Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be macro-style support for determining whether we're compiling to batch or bash scripts #58

Open
coriolinus opened this issue Nov 16, 2016 · 1 comment

Comments

@coriolinus
Copy link

Right now, there's no good way to execute built-in commands which vary between systems. You're stuck with stuff like this:

//! Not platform independent!
//! If on Windows, change this to "move"
call("mv", source, dest);

It would be much more powerful if we could use extremely simple macro-style syntax to implement platform-dependent behavior. The above would, under this proposal, look something like this:

#IF_BASH {
   move = "mv";
}
#IF_BATCH {
   move = "move";
}
call(move, source, dest);
@operatorequals
Copy link

I know it is a bit late but: gcc is your friend.
You can very well use the gcc preprocessor to achieve not only #defines but #includes too.
I made this script for the exact purpose:

#!/bin/sh
FILE="$1"
if [ ! -f "$FILE" ]; then
        echo "File '$FILE' not found"
        exit 1;
fi

quiet=""
#quiet="2>/dev/null"

tmpfile=$(mktemp '/tmp/XXXX-btsh.c')
cp "$FILE" "$tmpfile"
gcc  -E "$tmpfile" $quiet | egrep -v '^#'

rm "$tmpfile"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants