首页 > 代码库 > 快速切换目录命令go

快速切换目录命令go

平时有很多项目的目录,需要频繁的在这些目录中切换,效率很低。 之前总是在shell里ctrl + r 或者 cd -,后来目录多了这招也不好使了 我是个懒人,什么事重复三遍就不能忍 然后就用Python造了个命令go,可以方便智能的随意切换目录 先上代码,再继续说

#.bashrc中加入go () {	cd $(python /Users/auxten/scripts/thepath.py "$1")}

/Users/auxten/scripts/thepath.py内容如下

#!/usr/bin/env python# -*- coding: utf8 -*-import sysimport ospath_dic = {    "flow":"/Users/auxten/Codes/Android/VPN/flow",    "byod":"/Users/auxten/Codes/Android/byod/git/byod",    "vine":"/Users/auxten/Codes/baidu/ops-src/ops-vine",    "gko":"/Users/auxten/Codes/gko_pool",    "cdn":"/Users/auxten/Codes/baidu/ops-src/dlPlatform/log_analytics/web/web_env/",    "proxy":"/Users/auxten/Dropbox/插件/spiderProxy/",    "vpn":"/Users/auxten/Codes/Android/VPN/flow",}search_path = [    "/Users/auxten/Codes/Android/byod/trunk/",    "/Users/auxten/Codes/baidu/ops-src/",    "/Users/auxten/Codes/",]path = "~"try:    path = path_dic[sys.argv[1]]except KeyError,IndexError:    for dir in search_path:        tmp_path = os.path.join(dir, sys.argv[1])        if os.path.isdir(tmp_path):            path = tmp_path            break            print path

  如果在path_dic里指定类似这种

"flow":"/Users/auxten/Codes/Android/VPN/flow",
go flow##就相当于cd /Users/auxten/Codes/Android/VPN/flow

如果在path_dic里没有指定就会在search_path中按顺序查找flow文件夹,找到后就cd进去

 

快速切换目录命令go