標籤:des android os ar for 檔案 sp div c
平時有很多項目的目錄,需要頻繁的在這些目錄中切換,效率很低。 之前總是在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