DIRS="$HOME/.gtDirs" iftest ! -e $DIRS then touch$DIRS fi
gt () { case$1in -d) temp=`mktemp -t .gtDirs-XXXXXX` sed "/^$2=/"d $DIRS > $temp mv$temp$DIRS rm -f $temp ;; -a) validate_bookmark_name "$@" if [ -z "$result" ]; then CURDIR=$PWD echo"$2=$CURDIR" >> $DIRS fi ;; -l) cat$DIRS ;; -h) print_usage ;; *) if [ -z $1 ]; then print_usage elif [[ ! -z `awk -F '=''/^'"$1"'=/ {print $2 }'$DIRS` ]]; then cd `awk -F '=''/^'"$1"'=/ {print $2 }'$DIRS` else echo'error: bookmark name not found'
fi
esac }
#validate names function validate_bookmark_name { result="" if [ -z $2 ]; then result='error: bookmark name required!' echo$result elif [ -z `echo$2 | sed 's/[^A-Za-z0-9_]//g' ` ]; then result='error: bookmark name is invalid!' echo$result fi
}
function print_usage { echo'Usage:' echo'-a <bookmark_name> - Saves the current directory as "bookmark_name"' echo'-d <bookmark_name> - Deletes the bookmark' echo'-l - Lists all available bookmarks' echo'-h(-help,--help) - Lists usage' echo'<bookmark_name> - Jump to the bookmark' }
function _l { awk -F '='' {print $1} '$DIRS }
function _comp { local curw COMPREPLY=() curw=${COMP_WORDS[COMP_CWORD]} COMPREPLY=($(compgen -W '`_l`' -- $curw)) return 0 }
# ZSH completion command function _compzsh { reply=($(_l)) }
if [ $ZSH_VERSION ]; then compctl -K _compzsh gt else shopt -s progcomp complete -F _comp gt fi
add gt.sh file path to your ~/.bash_profile or ~/.bashrc file
reload your profile or restart your terminal
用例:
gt -a <bookmark_name> - 保存当前目录的标签为 给定的bookmark_name
gt -d <bookmark_name> - 删除给定的标签
gt -l - 列除所有标签
gt -h - 帮助信息
gt <bookmark_name> - 跳转到指定的标签目录
例子:
1 2 3 4 5 6 7 8 9
current_user:~$ cd sourcecode/study/ current_user:~/sourcecode/study$ gt -a study current_user:~/sourcecode/study$ cd ~ current_user:~$ gt study current_user:~/sourcecode/study$ gt -l goAgent=/Users/twer/sourcecode/goagent/goagent-goagent-9c1edd3/local octopress=/Users/twer/sourcecode/octopress goShell=/Users/twer/sourcecode/shell/goShell study=/Users/twer/sourcecode/study
1 2 3 4 5
current_user:~/sourcecode/study$ gt -d study current_user:~/sourcecode/study$ gt -l goAgent=/Users/twer/sourcecode/goagent/goagent-goagent-9c1edd3/local octopress=/Users/twer/sourcecode/octopress goShell=/Users/twer/sourcecode/shell/goShell
1 2 3 4 5 6 7
current_user:~/sourcecode/study$ gt -h Usage: -a <bookmark_name> - Saves the current directory as "bookmark_name" -d <bookmark_name> - Deletes the bookmark -l - Lists all available bookmarks -h(-help,--help) - Lists usage <bookmark_name> - Jump to the bookmark