gtShell 为你常用的目录建立标签并快速跳转
gtShell - 为你常用的目录建立标签并快速跳转
使用场景: 如果你有很多工作目录,需要每天在这些目录中跳来跳去。那么你就应该试试goShell. 一个使用简单、功能恰到好处的terminal下的小工具。 gtShell支持将常用的一些目录保存为bookmark,提供快速跳转功能。这样你就不需要在使用cd后面跟随一长串的目录名称。 它也支持自动完成,你只需要输入开头的几个字母,然后按tab键就可以自动匹配。 目前源码被我host在 github 上。
下面是主要文件gt.sh的源码。
gt.sh gt.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#! /bin/bash DIRS = "$HOME/.gtDirs" if test ! -e $DIRS then touch $DIRS fi gt () { case $1 in -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
安装:
git clone git@github.com:huangbowen521/gtShell.git 或者直接拷贝 gt.sh文件内容。
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
1 2 3
current_user:~/sourcecode/study $ gt go<Tab> goAgent goShell current_user:~/sourcecode/study $ gt goShell
作者: 黄博文 @无敌北瓜
出处: http://www.cnblogs.com/huang0925
黄博文的地盘
本文版权归本人和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
分类: 编程开发
作者: Leo_wl
出处: http://www.cnblogs.com/Leo_wl/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
版权信息查看更多关于gtShell 为你常用的目录建立标签并快速跳转的详细内容...