Skip to content

Instantly share code, notes, and snippets.

@mslinn
Last active January 9, 2022 17:51
Show Gist options
  • Save mslinn/57ed4879be2e574cc8b78425ac3ce3bb to your computer and use it in GitHub Desktop.
Save mslinn/57ed4879be2e574cc8b78425ac3ce3bb to your computer and use it in GitHub Desktop.
WSL launch atom
#!/bin/bash
function help {
echo "Edit WSL files or directories in atom, on Windows.
Usage:
$( basename $0 ) [ FILE_OR_DIRECTORY | -l PHRASE ] ...
FILE_OR_DIRECTORY can either be absolute or relative to the current directory.
If no arguments are specified, the current directory is assumed.
If the -l option is provided, the current git repository is searched for PHRASE,
and the files that the token are found in are edited.
The cursor is placed on the first line of each file that contains PHRASE.
Examples:
$ atom # Edit current directory
$ atom . # Edit current directory
$ atom blah.html # Edit ./blah.html
$ atom blah.html ick.html # Edit ./blah.html and ./ick.html
$ atom ~ # Edit home directory
$ atom ~ . # Edit home and current directories
$ atom -l blah # Edit all files in the current git repo that contain the word blah
$ atom -l blah -l ick # Edit all files in the current git repo that contain the word blah or ick
"
exit 1
}
unset ARGS
unset FOUND_ONE
if [ "$1" ]; then
while getopts "hl:\?" OPT; do
case "$OPT" in
h | \?) help ;;
l) FILES="$( git grep -n "$OPTARG" )"
if [ "$FILES" ]; then
FOUND_ONE=true
for FL in "$FILES"; do
# See https://stackoverflow.com/a/28225752/553865
IFS=: read -r F L JUNK <<< "$FL"
#echo "F=$F"
#echo "L=$L"
#echo "JUNK=$JUNK"
ARGS="$ARGS $( wslpath -m "$F" ):$L"
done
fi
;;
esac
done
shift $(($OPTIND-1))
unset X
for X in $*; do
ARGS="$ARGS $( wslpath -m "$X" )"
done
else
FOUND_ONE=true
ARGS="$( pwd )"
fi
if [ "$FOUND_ONE" ]; then
#echo "pwd=$( pwd )"
#echo "ARGS=$ARGS"
"$( wslpath "$(wslvar USERPROFILE)" )/AppData/Local/atom/atom.exe" $ARGS & > /dev/null
else
echo "No matching files found."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment