Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make #!/usr/bin/env [node|php] work in cygwin

  • Loading branch information...
commit e0e642d3dda7239bf11fa9ea6f413464d90deb2e 1 parent 8ea50d7
@weikinhuang authored
View
89 .dotenv/cygwin/.functions
@@ -148,95 +148,6 @@ if type winpty &> /dev/null; then
}'
export -f $BINARY
}
-
- function __cygphpwrap() {
- local PROGRAM
- # the name of the program
- if [[ -n $1 ]]; then
- PROGRAM=$(cygpath -u "$1")
- elif [[ -f $(cygpath -u "c:/Program Files (x86)/PHP/php.exe") ]]; then
- PROGRAM=$(cygpath -u "c:/Program Files (x86)/PHP/php.exe")
- elif [[ -f $(cygpath -u "c:/Program Files/PHP/php.exe") ]]; then
- PROGRAM=$(cygpath -u "c:/Program Files/PHP/php.exe")
- elif [[ -f $(cygpath -u "c:/PHP/php.exe") ]]; then
- PROGRAM=$(cygpath -u "c:/PHP/php.exe")
- else
- # php binary not found
- return 1
- fi
-
- # attempt to wrap php as well if found
- eval 'function php() {
- local arg args IS_REPL_SHELL
-
- # if there are any baked in arguments they are defined here
- args=( )
-
- IS_REPL_SHELL=""
- for arg in "$@"
- do
- # if argument is a file, then expand it to windows paths
- if [ -e "$arg" ]
- then
- # echo "arg $arg is a file"
- args=("${args[@]}" "$(cygpath -w "$arg")")
- else
- # echo "arg $arg is not a file"
- args=("${args[@]}" "$arg")
- if [ "$arg" == "-a" ]; then
- IS_REPL_SHELL=1
- fi
- fi
- done
-
- # test if we are in a pipe and pass stdin as last argument if we are piping in
- if [ ! -t 0 ]
- then
- "'$PROGRAM'" "${args[@]}" <<< "$(cat -)"
- else
- if [[ ${#args[@]} -eq 0 || -n $IS_REPL_SHELL ]]
- then
- # php script to simulate repl in cygwin, as php is compiled without readline
- winpty "'$PROGRAM'" -r '"'"'
- echo "Interactive mode enabled" . PHP_EOL . PHP_EOL;
- $fp = fopen("php://stdin", "r");
- $in = "";
- do {
- if(!$in) {
- echo "php> ";
- }
- $in = $in . trim(fgets($fp));
- if($in) {
- if(substr($in, -1) === chr(92)) {
- $in = substr($in, 0, -1);
- } else {
- ob_start();
- eval($in);
- $res = ob_get_clean();
- echo $res;
- if(ord(substr($res, -1)) !== 10) {
- // the real shell does not do this as well
- // echo PHP_EOL;
- }
- $in = "";
- }
- }
-
- } while($in !== "quit");'"'"'
- else
- "'$PROGRAM'" "${args[@]}"
- fi
- fi
-
- return $?
- }'
- export -f php
- }
- # try running it, if it fails leave it to the user
- if __cygphpwrap; then
- unset __cygphpwrap
- fi
-
else
function __cygcliwrap() {
echo "Package winpty required. Please visit https://github.com/rprichard/winpty and compile application."
View
39 .dotenv/cygwin/bin/node
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+# the name of the program
+PROGRAM=$(cygpath -u "c:/Program Files/nodejs/node.exe")
+
+if [[ ! -f "$PROGRAM" ]]; then
+ exit 1;
+fi
+
+# if there are any baked in arguments they are defined here
+args=( )
+
+for arg in "$@"
+do
+ # if argument is a file, then expand it to windows paths
+ if [ -e "$arg" ]
+ then
+ # echo "arg $arg is a file"
+ args=("${args[@]}" "$(cygpath -w "$arg")")
+ else
+ # echo "arg $arg is not a file"
+ args=("${args[@]}" "$arg")
+ fi
+done
+
+# test if we are in a pipe and pass stdin as last argument if we are piping in
+if [ ! -t 0 ]
+then
+ "${PROGRAM}" "${args[@]}" <<< "$(cat -)"
+else
+ if [ ${#args[@]} -eq 0 ]
+ then
+ winpty "${PROGRAM}" "${args[@]}"
+ else
+ "${PROGRAM}" "${args[@]}"
+ fi
+fi
+
+exit $?
View
75 .dotenv/cygwin/bin/php
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+# the name of the program
+if [[ -f "$(cygpath -u "c:/Program Files/PHP/php.exe")" ]]; then
+ PROGRAM=$(cygpath -u "c:/Program Files/PHP/php.exe")
+elif [[ -f "$(cygpath -u "c:/Program Files (x86)/PHP/php.exe")" ]]; then
+ PROGRAM=$(cygpath -u "c:/Program Files (x86)/PHP/php.exe")
+elif [[ -f "$(cygpath -u "c:/PHP/php.exe")" ]]; then
+ PROGRAM=$(cygpath -u "c:/PHP/php.exe")
+else
+ # php binary not found
+ return 1
+fi
+
+# if there are any baked in arguments they are defined here
+args=( )
+
+IS_REPL_SHELL=""
+for arg in "$@"
+do
+ # if argument is a file, then expand it to windows paths
+ if [ -e "$arg" ]
+ then
+ # echo "arg $arg is a file"
+ args=("${args[@]}" "$(cygpath -w "$arg")")
+ else
+ # echo "arg $arg is not a file"
+ args=("${args[@]}" "$arg")
+ if [ "$arg" == "-a" ]; then
+ IS_REPL_SHELL=1
+ fi
+ fi
+done
+
+# test if we are in a pipe and pass stdin as last argument if we are piping in
+if [ ! -t 0 ]
+then
+ "${PROGRAM}" "${args[@]}" <<< "$(cat -)"
+else
+ if [[ ${#args[@]} -eq 0 || -n $IS_REPL_SHELL ]]
+ then
+
+ # php script to simulate repl in cygwin, as php is compiled without readline
+ winpty "${PROGRAM}" -r '
+echo "Interactive mode enabled" . PHP_EOL . PHP_EOL;
+$fp = fopen("php://stdin", "r");
+$in = "";
+do {
+ if(!$in) {
+ echo "php> ";
+ }
+ $in = $in . trim(fgets($fp));
+ if($in) {
+ if(substr($in, -1) === chr(92)) {
+ $in = substr($in, 0, -1);
+ } else {
+ ob_start();
+ eval($in);
+ $res = ob_get_clean();
+ echo $res;
+ if(ord(substr($res, -1)) !== 10) {
+ // the real shell does not do this as well
+ // echo PHP_EOL;
+ }
+ $in = "";
+ }
+ }
+
+} while($in !== "quit");'
+ else
+ "${PROGRAM}" "${args[@]}"
+ fi
+fi
+
+exit $?
View
2  .dotenv/other/cygwin-exewrappers.sh
@@ -61,7 +61,7 @@ function __createcygwinwrappers() {
__cygexewrap "c:/${X86_PGM_PATH}/Windows NT/Accessories/wordpad.exe" wordpad
# cli based applications
- __cygcliwrap "c:/Program Files/nodejs/node.exe" node
+ # __cygcliwrap "c:/Program Files/nodejs/node.exe" node # we don't do this because we want # ! /usr/bin/env node to work
__cygcliwrap "c:/${X86_PGM_PATH}/phantomjs/phantomjs.exe" phantomjs
__cygcliwrap "c:/Windows/System32/cmd.exe" wcmd
__cygcliwrap "c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" wpowershell
Please sign in to comment.
Something went wrong with that request. Please try again.