Skip to content

Instantly share code, notes, and snippets.

@porglezomp porglezomp/00-README.md
Last active Jan 25, 2019

Embed
What would you like to do?
Goto scripts

Goto

These scripts goto and label let you handle jumping around to directories that you want to get to frequently, without having to figure out the path relative to where you are currently. To create a location, go to the directory you care about, then type label <name>. After you've done that, you're able to type goto <name> at any time to jump directly to that location.

Installation

To install on fish, copy the fish scripts into the locations listed at the top of them. To install on bash/sh/etc., copy the goto-label.sh into the end of your .profile, .bash_profile, or whatever else you have your config code in.

# Put in ~/.config/fish/completions/goto.fish
complete -c goto -x -a '(goto --_completion)'
# Put in ~/.config/fish/completions/label.fish
complete -c label -f
# Add these to your .profile, .bash_profile, etc.
function goto() {
mkdir -p ~/.config/goto
touch ~/.config/goto/labels
if [[ -z "$@" ]]; then
echo "Usage: goto <name>"
return 1
fi
found=$(grep "^$@\t" ~/.config/goto/labels | cut -f 2)
if [[ -z "$found" ]]; then
echo "Unknown label '$@'"
return 1
fi
cd "$found"
}
function label() {
mkdir -p ~/.config/goto
touch ~/.config/goto/labels
if [[ -z "$@" ]]; then
echo "Usage: label <name>"
return 1
fi
if grep "^$@\t" ~/.config/goto/labels > /dev/null; then
echo "Label '$@' is already defined"
return 1
fi
printf "$@\t$PWD\n" >> ~/.goto
}
# Put in ~/.config/fish/functions/goto.fish
function goto --description 'Jump directly to a directory'
mkdir -p ~/.config/goto/
touch ~/.config/goto/labels
if [ "$argv" = "--_completion" ]
cut -f 1 ~/.config/goto/labels
return 0
end
if [ -z "$argv" ]
echo "Usage: goto <name>"
return 1
end
set -l found (grep "^$argv\t" ~/.config/goto/labels | cut -f 2)
if [ -z "$found" ]
echo "Unknown label '$argv'"
return 1
end
cd "$found"
end
# Put in ~/.config/fish/functions/label.fish
function label --description ''
mkdir -p ~/.config/goto/
touch ~/.config/goto/labels
if [ -z "$argv" ]
echo "Usage: label <name>"
return 1
end
if grep "$argv\t" ~/.config/goto/labels > /dev/null
echo "The label '$argv' is already defined"
return 1
end
printf "$argv\t$PWD\n" >> ~/.config/goto/labels
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.