Last active
March 19, 2019 10:14
-
-
Save for2ando/63fd417885d98634539d747641180d1e to your computer and use it in GitHub Desktop.
Slightly extended cygstart command clone for cygwin (and expected for msys2).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage="$0 [Options] [NumberOfSkippingPathConvert] Command [Args] | |
Description: | |
call spacified command with spacified args which is replaced path-delimiter | |
character / to \. | |
Options: | |
-c with cmd.exe (Command is executed with 'cmd.exe /k') | |
-x (not implemented yet) | |
-s synchronize execution (wait a termination of Command) | |
-n dry run mode | |
-v verbose mode | |
-h print this usage | |
Arguments: | |
Command | |
A name of command to be executed. This name is searched on search-path by | |
envvar PATH. | |
Args | |
Arguments for the Command. In default, the arguments are tryed to be | |
converted to Windows-style (¥¥-delimited and has a drive name) pathes. | |
NumberOfSkippingPathConvert | |
format as exgexp: [0-9]+ | |
If this argument N is specified, then the path convertion for the Args | |
to Windows-style is switched off only on first N Args. | |
" | |
dryrun=false | |
verbose=false | |
withcmd=false | |
withxterm=false | |
synchronize=false | |
while true | |
do | |
case "$1" in | |
-n) dryrun=true;; | |
-v) verbose=true;; | |
-c) withcmd=true;; | |
-x) withxterm=true;; | |
-s) synchronize=true;; | |
-h) echo "$usage"; exit 0;; | |
-*) echo "$0: $1: unknown option.¥n$usage"; exit 1;; | |
*) break;; | |
esac | |
shift | |
done | |
case "$1" in [0-9]|[0-9][0-9]) skip=$1; shift;; *) skip=0;; esac | |
cmd="$1" | |
shift | |
i=0 | |
for arg in "$@" | |
do | |
if [ $i -lt $skip ]; then | |
args[$((i++))]="$arg" | |
else | |
args[$((i++))]=`cygpath -w "$arg"` | |
fi | |
done | |
call="cygstart" | |
cmdsh="" | |
cmdpath=`which "$cmd"` | |
trailer="" | |
$synchronize && call="" | |
$withcmd && { | |
cmdsh="`which cmd` /k" | |
cmdpath=`cygpath -w "$cmd"` | |
#trailer="& pause" | |
trailer="" | |
} | |
$withxterm && { | |
cmdsh="`which cmd` /k" | |
cmdpath=`cygpath -w "$cmd"` | |
#trailer="& pause" | |
trailer="" | |
} | |
$dryrun || $verbose && echo $call $cmdsh "$cmdpath" "${args[@]}" $trailer | |
$dryrun || $call $cmdsh "$cmdpath" "${args[@]}" $trailer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment