-
-
Save ewieberappc/0bd8a3936d4403ab17a5 to your computer and use it in GitHub Desktop.
Add shortcuts/names to paths for quick navigation.
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
GoTo allows you to set a nickname/shortcut to a path so that you can easily navigate to it later. | |
USAGE: | |
$ goto [options] - CDs to your previous location | |
$ goto <name> [options] - CDs to the location saved in the goto shortcut <name>. Prompts to set the shortcut if it is not already set | |
OPTIONS: | |
-o, --open - CDs to the location saved in the goto shortcut <name> and opens the location in finder. Prompts to set the shortcut if it is not already set | |
-oo, --open-only - Opens the location saved in the goto shortcut <name> in finder. Prompts to set the shortcut if it is not already set | |
-s <name>, --set <name> <path> - Set the shortcut <name> to location <path>. Uses current location if no path specified | |
-u <name>, --unset <name> - Removes (unsets) the shortcut <name> | |
-ua, --unset-all - Removes (unsets) all goto shortcuts | |
-l, --list - Print a list of all goto shortcuts | |
-e, --export - Exports all shortcuts for importing later (overwrites previous export) | |
-i, --import - Imports all shortcuts that were exported | |
-h, --help - Opens the help URL (this page) | |
INSTALLATION: | |
1. Download the executable file to a folder (recommended '~/bin') | |
2. Add the path to the folder to your PATH in your .bash_profile (export PATH=$PATH:~/bin) | |
3. Add an alias to your .bash_profile to run the command in the current shell: ( goto(){ . .goto $@; } ) | |
4. Restart your terminal or run '. ~/.bash_profile' | |
SAMPLE SETUP COMMAND: | |
setupgoto () { goto -s work ~/Documents/Appcelerator_Studio_Workspace; goto -s sdk ~/Library/Application\ Support/Titanium/mobilesdk; goto -s cli ~/.appcelerator/install; }; setupgoto; | |
NOTES: | |
Run the 'Sample Setup Command' to load a few shortcuts into 'GoTo'. | |
You can set up your terminal window to automatically run 'goto -i' when it starts. This will load any GoTo shorcuts that you have exported into each terminal window you open. |
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
open=0; case "$1" in "") cd - 1>/dev/null;; -h|--help) HELP='https://gist.github.com/ewieberappc/0bd8a3936d4403ab17a5'; echo -ne '\t'$'\e[37m''Opening help URL: '"$HELP"'\n'$'\e[0m'; open "$HELP"; exit;; -l|--list) for i in ${!Goto*}; do echo -ne '\t'$'\e[37m'; str=$(echo "$i" | sed 's/Goto//g'); echo "$str"' : '"${!i}"$'\e[0m'; done;; -e|--export) rm ~/.gotoExport 2>/dev/null; for i in ${!Goto*}; do str=$(echo "$i" | sed 's/Goto//g'); echo "$str"' : '"${!i}" >>~/.gotoExport; done; echo -e '\t'$'\e[37m''Shortcuts exported'$'\e[0m';; -i|--import) if [[ ! -e ~/.gotoExport ]]; then echo -e '\t'$'\e[37m''Nothing to import'$'\e[0m'; exit; fi; while read line; do name='Goto'${line%% :*}; loc=${line##*: }; export $name="$loc"; echo -e '\t'$'\e[37m'$line$'\e[0m'; done < ~/.gotoExport;; -u|--unset) if [[ "$2" == "" ]]; then exit; fi; echo -ne '\t'$'\e[37m''Unset : '; tmp='Goto'$2; unset ${tmp}; echo -e $'\e[37m'$2$'\e[0m';; -ua|--unset-all) echo -ne '\t'$'\e[37m''Unset : '; for i in ${!Goto*}; do unset "$i"; str=$(echo "$i" | sed 's/Goto//g'); echo -n $'\e[37m'"$str"', '$'\e[0m'; done; echo;; -s|--set) if [[ "$2" == "" ]]; then exit; fi; tmp='Goto'$2; if [[ "$3" != "" ]]; then export ${tmp}="$3"; else export ${tmp}=$(pwd); fi; echo -e '\t'$'\e[37m'$2' : '${!tmp}$'\e[0m';; -o|--open) ${FUNCNAME[0]} "$2" -o; exit;; -oo|--open-only) ${FUNCNAME[0]} "$2" -oo; exit;; *) tmp='Goto'$1; if [[ "${!tmp}" == "" ]]; then echo -e '\t'$'\e[37m'$1' : Not set'$'\e[0m'; read -p $'\e[32m''?'$'\e[0m'' Set '$1' to current location? (y/N) ' -r; if [[ $REPLY =~ ^[Yy]$ ]]; then ${FUNCNAME[0]} -s "$1"; fi; fi; if [[ "${!tmp}" != "" ]]; then case "$2" in -o|--open) open=1;; -oo|--open-only) open=2;; -s|--set) ${FUNCNAME[0]} -s "$1"; exit;; -u|--unset) ${FUNCNAME[0]} -u "$1"; exit;; esac; if [[ "$open" != 2 ]]; then cd "${!tmp}"; fi; fi; esac; if [[ "$open" == 1 ]]; then open .; elif [[ "$open" == 2 ]]; then open "${!tmp}"; fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment