Skip to content

Instantly share code, notes, and snippets.

@cfg
Last active December 14, 2015 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfg/5117423 to your computer and use it in GitHub Desktop.
Save cfg/5117423 to your computer and use it in GitHub Desktop.
Add a "Open mintty here" item to Windows Explorer context menus. Basically `chere` with the addition of the Background key.
#!/bin/bash
KEY="mintty"
PROMPT="Open mintty h&ere"
if [ -z "$KEY" ] || [ -z "$PROMPT" ] ; then
echo "Key and Prompt cannot be empty"
exit 1
fi
declare -a KEYS=(
"/HKCR/Directory/Shell/$KEY"
"/HKCR/Background/Shell/$KEY"
"/HKCR/Drive/shell/$KEY"
"/HKLM/SOFTWARE/Classes/Directory/Shell/$KEY"
"/HKLM/SOFTWARE/Classes/Directory/Background/Shell/$KEY"
)
function list_keys () {
for ITEM in "${KEYS[@]}" ; do
echo -n "$ITEM: "
regtool check $ITEM > /dev/null 2>&1
ERR="$?"
if [[ "$ERR" -ne "0" ]] ; then
echo "(not found)"
continue
fi
regtool get $ITEM
regtool list $ITEM/
echo -n "$ITEM/command: "
regtool get $ITEM/command/
echo ""
done
}
function add_keys () {
for ITEM in "${KEYS[@]}" ; do
echo "== Add $ITEM =="
set -x
regtool -w add $ITEM
regtool -w -s set $ITEM/ "$PROMPT"
regtool -w add $ITEM/command
if [[ "$ITEM" =~ .*/Background/Shell/.* ]] ; then
regtool -w -e set $ITEM/command/ "C:\cygwin\bin\mintty.exe -e /bin/xhere /bin/bash.exe \"%V\""
else
regtool -w -e set $ITEM/command/ "C:\cygwin\bin\mintty.exe -e /bin/xhere /bin/bash.exe \"%L\""
fi
set +x
echo ""
done
}
function remove_keys () {
for ITEM in "${KEYS[@]}" ; do
echo "== Remove $ITEM =="
regtool check $ITEM/command > /dev/null 2>&1
ERR="$?"
if [[ "$ERR" -ne "0" ]] ; then
echo "$ITEM/command does not exist, aborting for safety."
echo ""
continue
fi
set -x
regtool -w remove $ITEM/command
regtool -w remove $ITEM
set +x
echo ""
done
}
case $1 in
"--uninstall" | "-u")
remove_keys
;;
"" | "--install" | "-i")
add_keys
;;
"--list" | "-l")
list_keys
;;
* | "-h" | "--help")
echo "Usage: $0 [-u --uninstall] [-i --install] [-l --list]"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment