Skip to content

Instantly share code, notes, and snippets.

@GongT

GongT/code.sh

Created Nov 5, 2019
Embed
What would you like to do?
start VSCode from cygwin (/usr/local/bin/code)
#/usr/bin/env bash
ARGS=("$@")
WPATH=()
PPATH=()
OIFS="$IFS"
IFS=":"
X=( $PATH )
for P in "${X[@]}" ; do
if [[ "$P" =~ "/cygdrive/" ]] ; then
WPATH+=("$P")
else
PPATH+=("$P")
fi
done
IFS="$OIFS"
unset OIFS
for I in "${WPATH[@]}" ; do
if [[ -e "$I/code" ]]; then
CODE="$I/code"
break;
fi
done
if [[ -z "$CODE" ]]; then
echo "Cannot find code.exe From:" >&2
for I in "${WPATH[@]}" ; do
echo "$I" >&2
done
exit 1
fi
for I in "${ARGS[@]}"; do
if [[ "${I[0]}" == '-' ]]; then
PARGS+=("$I")
else
PARGS+=("$(cygpath -c OEM -m -l -a "$I")")
fi
done
"${CODE}" "${PARGS[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment