diff --git a/index.js b/index.js index 79bb14e..e0c3e99 100644 --- a/index.js +++ b/index.js @@ -140,15 +140,15 @@ function writeShim_ (from, to, prog, args, variables, cb) { var sh = "#!/bin/sh\n" - if (shLongProg) { - sh = sh - + "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n" - + "\n" - + "case `uname` in\n" - + " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n" - + "esac\n" - + "\n" + sh = sh + + "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n" + + "\n" + + "case `uname` in\n" + + " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n" + + "esac\n" + + "\n" + if (shLongProg) { sh = sh + "if [ -x "+shLongProg+" ]; then\n" + " " + variables + shLongProg + " " + args + " " + shTarget + " \"$@\"\n" @@ -159,7 +159,8 @@ function writeShim_ (from, to, prog, args, variables, cb) { + "fi\n" + "exit $ret\n" } else { - sh = shProg + " " + args + " " + shTarget + " \"$@\"\n" + sh = sh + + shProg + " " + args + " " + shTarget + " \"$@\"\n" + "exit $?\n" } diff --git a/test/basic.js b/test/basic.js index ae1e0c5..f28575e 100755 --- a/test/basic.js +++ b/test/basic.js @@ -13,7 +13,14 @@ test('no shebang', function (t) { if (er) throw er t.equal(fs.readFileSync(to, 'utf8'), - "\"$basedir/from.exe\" \"$@\"\nexit $?\n") + "#!/bin/sh"+ + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ + "\n"+ + "\ncase `uname` in"+ + "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+ + "\nesac"+ + "\n"+ + "\n\"$basedir/from.exe\" \"$@\"\nexit $?\n") t.equal(fs.readFileSync(to + '.cmd', 'utf8'), "@\"%~dp0\\from.exe\" %*\r\n") t.end()