| #!/bin/bash | |
| goto () { | |
| if [ ! -d "$HOME/.shortcuts" ] | |
| then | |
| mkdir -p "$HOME/.shortcuts" | |
| fi | |
| if [[ "$1" == "--list" ]] | |
| then | |
| for f in $HOME/.shortcuts/* | |
| do | |
| echo "$(basename "$f") -> $(tr -d '\n' < "$f")" | |
| done | |
| return 1 | |
| elif [[ "$1" == "--define" ]] | |
| then | |
| if [[ "$2" == "" ]] | |
| then | |
| echo "usage: goto --define [shortcut name] [target directory]" | |
| return 1 | |
| else | |
| rm -f "$HOME/.shortcuts/$2" | |
| echo -n "$3" > "$HOME/.shortcuts/$2" | |
| return 0 | |
| fi | |
| elif [[ "$1" == "--rm" ]] | |
| then | |
| rm -f "$HOME/.shortcuts/$2" | |
| return 0 | |
| else | |
| if [ -s "$HOME/.shortcuts/$1" ] | |
| then | |
| GTDIR=$(cat "$HOME/.shortcuts/$1") | |
| cd "$GTDIR" || return 1 | |
| else | |
| echo "goto: unknown shortcut '$1'" | |
| return 1 | |
| fi | |
| fi | |
| return 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment