使用场景: 如果你有很多工作目录,需要每天在这些目录中跳来跳去。那么你就应该试试goShell. 一个使用简单、功能恰到好处的terminal下的小工具。 gtShell支持将常用的一些目录保存为bookmark,提供快速跳转功能。这样你就不需要在使用cd后面跟随一长串的目录名称。 它也支持自动完成,你只需要输入开头的几个字母,然后按tab键就可以自动匹配。 目前源码被我host在github上。

下面是主要文件gt.sh的源码。

gt.shgt.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

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

  1. 【HTML 教程系列第 11 篇】HTML 中常用的文本格式化标签

    这是[HTML 教程系列第 11 篇],如果觉得有用的话,欢迎关注专栏. 在网页中,有时需要为文字设置粗体.斜体.下划线或上下标等效果,这时就需要用到 HTML 中的文本格式化标签(也叫文本标签),常 ...

  2. 第三百七十七节,Django+Xadmin打造上线标准的在线教育平台—apps目录建立,以及数据表生成...

    第三百七十七节,Django+Xadmin打造上线标准的在线教育平台-apps目录建立,以及数据表生成 apps目录建立 我们创建一个apps目录,将所有的app放到apps目录里去,这样方便管理,也 ...

  3. 常用的SSH注解标签

    常用的SSH注解标签 1.Spring的注解 关于配Bean用的         @Component         @Controller @Service @Repository        ...

  4. h5列表 php,常用的HTML5列表标签

    这次给大家带来常用的HTML5列表标签,使用用HTML5列表标签的注意事项有哪些,下面就是实战案例,一起来看一下. 一.列表标签作用 作用:给一堆数据添加列表语义,也就是告诉搜索引擎告诉浏览器这一堆数 ...

  5. HTML学习二_HTML常用的行级标签,常用实体字符及表单标签

    HTML常用的行级标签(行内元素)不独占一行### 有语义的行内元素 #### HTML链接 a标签 ```angular2html<a href="链接地址">链接文 ...

  6. html5语义化编程,HTML5常用的语义化标签

    本文将为您描述HTML5常用的语义化标签,具体实现方法:快速查询 article | aside | nav | section | header | footer 架构预览 nav定义导航链接的部分 ...

  7. Hexo为文章设置目录与标签的方法

    1. 创建目录页   在网站根目录下执行以下代码. hexo new page categories    Hexo\source 目录中会生成一个 categories 文件夹,文件夹内有一个 in ...

  8. Hexo(sakura)建立标签云hexo-tag-cloud

    Hexo博客Next主题建立标签云hexo-tag-cloud及效果展示

  9. dede模板里常用到的一些标签—dedecms模板开发

    dede模板里常用到的一些标签 1.头尾调用标签: {dede:include filename="head.htm"/} {dede:include filename=" ...

  10. Mybatis常用的动态SQL标签讲解

    先让我们看看mybatis常用动态SQL的标签有哪一些 如果mybatis和SSM整合环境不会搭建请看这篇 https://blog.csdn.net/weixin_44012722/article/ ...

最新文章

  1. ArcEngine的ToolbarControl解析
  2. Saltstack笔记
  3. CLH锁 、MCS锁
  4. Linux学习笔记:Linux分区
  5. Wildfly Swarm,朝着成熟和一小部分贡献
  6. Go语言之进阶篇响应报文测试方法
  7. DataGrid导出Excel
  8. MFC DLL向导(二)
  9. 商城管理系统(前台+后台+管理员+用户+html+jsp)
  10. 【美女送福利了win7主题】
  11. APP上架市场隐私政策被拒(关于未经用户同意收集用户信息)
  12. LoRaWAN节点和网关接入阿里LinkWAN
  13. windows下安装mathtype公式编辑器记录
  14. 零信任架构:下一代网络安全架构?
  15. 2023学年持IB成绩申请NTU入学流程指南
  16. 主机win10与虚拟机win7相互ping通方法
  17. 银行降转账额度 “余额宝”要当心了
  18. FPGA之DDR4驱动
  19. 双非计算机本科生如何混进互联网大厂?
  20. web 报表轻松实现数据异常预警功能

热门文章

  1. Windows服务器系统的端口要求
  2. Android 四大组件学习之Service三
  3. 讲讲亿级PV的负载均衡架构
  4. freeswitch debug
  5. linux 设备驱动之8250串口驱动分析
  6. [51nod]1284 2 3 5 7的倍数
  7. winpcap基本原理及常见应用_锁相放大器的基本原理(Part 1)
  8. oracle11g Rac Bond,Oracle11g搭建RAC步骤..doc
  9. 客服机器人代码_什么是第三方客服系统
  10. 挂载ntfs_解决Mac不能写入Windows格式(NTFS)磁盘问题