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

简介: 使用场景: 如果你有很多工作目录,需要每天在这些目录中跳来跳去。那么你就应该试试goShell. 一个使用简单、功能恰到好处的terminal下的小工具。 gtShell支持将常用的一些目录保存为bookmark,提供快速跳转功能。

使用场景: 如果你有很多工作目录,需要每天在这些目录中跳来跳去。那么你就应该试试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

安装:

  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> - 保存当前目录的标签为 给定的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
相关文章
|
4月前
markdown增加目录索引,实现点击目录跳转到对应的内容目录标题
markdown增加目录索引,实现点击目录跳转到对应的内容目录标题
78 0
|
4月前
怎么添加文章目录,然后点击目录跳转到对应的内容目录标题+怎么打开MarkDown编辑
怎么添加文章目录,然后点击目录跳转到对应的内容目录标题+怎么打开MarkDown编辑
30 0
|
10月前
|
SQL Java 应用服务中间件
【实战记录分析】目录导航
【实战记录分析】目录导航
41 0
|
JavaScript 前端开发
脚本可放置与外部文件中
脚本可放置与外部文件中
42 1
|
小程序 开发者
小程序__02--navigationBarTitleText配置子页面标题,依旧显示默认标题,子页面配置不显示
navigationBarTitleText配置子页面标题,依旧显示默认标题,子页面配置不显示
|
XML Java 数据格式
SMB使用递归方式下载、删除远程服务器文件(包含带有子文件夹等)
SMB(Server Message Block)通信协议是微软(Microsoft)和英特尔(Intel)在1987年制定的协议,主要是作为Microsoft网络的通讯协议。SMB 是在会话层(session layer)和表示层(presentation layer)以及小部分应用层(application layer)的协议。
381 0
|
JavaScript
【Layui】在使用open方法弹出子页面时,路径地址不对,报错,解决方案
【Layui】在使用open方法弹出子页面时,路径地址不对,报错,解决方案
292 0
【Layui】在使用open方法弹出子页面时,路径地址不对,报错,解决方案
有点玄学,虽然不知道为什么第一个工程配置文件的资源放到某个位置,建立第一个工程时也是同样放到那个位置,就配置文件内容不断报错了
有点玄学,虽然不知道为什么第一个工程配置文件的资源放到某个位置,建立第一个工程时也是同样放到那个位置,就配置文件内容不断报错了
368 0
有点玄学,虽然不知道为什么第一个工程配置文件的资源放到某个位置,建立第一个工程时也是同样放到那个位置,就配置文件内容不断报错了
|
搜索推荐 SEO
怎么给网站建立一级目录
学习了一级目录是什么?一级目录有什么好处?之后,开始学习怎么给网站建立一级目录,学会这些,做一个简单的网站是没有问题的。 怎么给网站建立一级目录 在FTP后台,鼠标点击右键—&gt;新建文件夹。然后鼠标右键点击这个文件夹,重新命名,输入bbs,或blog即可。 然后,我需要上传一个“一级目录的首页”到bbs或9dian文件夹里。
254 0
|
前端开发 JavaScript
html页面统一设置静态资源地址的解决方案--base标签
一,资源路径 在html页面中,路径有两种 相对路径: <link rel="stylesheet" href="css/owl.carousel.min.css"> 绝对路径: <link rel="stylesheet" type="text/css" href="http://www.eotodo.com/jquery/font-awesome.4.6.0.css"> 二,配置统一资源地址 我们在页面中引用资源一般也是通过这两种方式来引入的。
5034 0