热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

gtShell-为你常用的目录建立标签并快速跳转

使用场景:如果你有很多工作目录,需要每天在这些目录中跳来跳去。那么你就应该试试goShell.一个使用简单、功能恰到好处的terminal下的小工具。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  - Saves the current directory as "bookmark_name"'  echo '-d  - Deletes the bookmark'  echo '-l - Lists all available bookmarks'  echo '-h(-help,--help) - Lists usage'  echo ' - 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 

安装:

  1. git clone git@github.com:huangbowen521/gtShell.git 或者直接拷贝 gt.sh文件内容。

  2. add gt.sh file path to your ~/.bash_profile or ~/.bashrc file

  3. reload your profile or restart your terminal

用例:

  • gt -a - 保存当前目录的标签为 给定的bookmark_name

  • gt -d - 删除给定的标签

  • gt -l - 列除所有标签

  • gt -h - 帮助信息

  • gt - 跳转到指定的标签目录

例子:

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  - Saves the current directory as "bookmark_name" -d  - Deletes the bookmark -l - Lists all available bookmarks -h(-help,--help) - Lists usage  - Jump to the bookmark 
1
2
3
current_user:~/sourcecode/study$ gt go goAgent goShell current_user:~/sourcecode/study$ gt goShell 

推荐阅读
author-avatar
铁血BelieveMe
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有