Add --no-shebang option

This commit is contained in:
zawwz 2021-01-06 14:49:20 +01:00
parent 5944fa7cc6
commit 44d71155cc
3 changed files with 7 additions and 3 deletions

View file

@ -9,6 +9,7 @@ extern bool opt_minimize;
extern bool g_cd;
extern bool g_include;
extern bool g_resolve;
extern bool g_shebang;
void get_opts();

View file

@ -194,14 +194,14 @@ int main(int argc, char* argv[])
if(destfile == "-")
destfile = "/dev/stdout";
// output
std::ofstream(destfile) << sh->generate();
std::ofstream(destfile) << sh->generate(g_shebang, 0);
// don't chmod on /dev/
if(destfile.substr(0,5) != "/dev/")
ztd::exec("chmod", "+x", destfile);
ztd::exec("chmod", "+x", destfile);
}
else // to console
{
std::cout << sh->generate();
std::cout << sh->generate(g_shebang, 0);
}
}
catch(ztd::format_error& e)

View file

@ -8,6 +8,7 @@ bool opt_minimize=false;
bool g_cd=false;
bool g_include=true;
bool g_resolve=true;
bool g_shebang=true;
ztd::option_set gen_options()
{
@ -21,6 +22,7 @@ ztd::option_set gen_options()
ztd::option('o', "output", true , "Output result script to file", "file"),
ztd::option('c', "stdout", false, "Output result script to stdout"),
ztd::option('e', "exec", false, "Directly execute script"),
ztd::option("no-shebang", false, "Don't output shebang"),
ztd::option("\r [Processing]"),
ztd::option('C', "no-cd", false, "Don't cd when doing %include and %resolve"),
ztd::option('m', "minimize", false, "Minimize code without changing functionality"),
@ -49,6 +51,7 @@ void get_opts()
g_cd=!options['C'].activated;
g_include=!options["no-include"].activated;
g_resolve=!options["no-resolve"].activated;
g_shebang=!options["no-shebang"].activated;
if(options["exclude-var"])
re_var_exclude=var_exclude_regex(options["exclude-var"], !options["no-exclude-reserved"]);
else