快速切換資料夾的DOS指令:go-tool

如同我在上一篇《clink:擴充cmd.exe成為Bash readline命令行的強大編輯功能》篇末提到的無法正確執行autojump,因而找到另一個也能在Windows DOS視窗(命令提示字元)裡快速切換目錄的工具 go-toola command-line tool for quick directory switching。go-tool是以建立關鍵字(它稱做shortcut)的方式來操作,建好代表某個資料夾的shortcut後,日後就能以此關鍵字切換到特定目錄。

安裝go-tool

go-tool和autojump一樣都是使用Python開發,但不能安裝標準的Python系統,否則在使用檔案總管開啟資料夾時會出現‘ImportError: No module named win32api‘錯誤,因為標準的Python系統不含Win32Api模組;我安裝的是含有Win32Api模組的ActivePython 2.7.6,將Python安裝目錄設定到PATH環境變數後,再使用下列步驟完成安裝:

  1. 由官方網站下載go-tool最新版
  2. 將下載的zip檔解壓縮,再切換到該目錄。
  3. 開啟DOS視窗,執行python setup.py install
  4. 再執行python -m go以建立整合用的批次檔,當出現建立go.bat的提示時輸入 1 再按〔Enter〕。

操作go-tool

go -h就能顯示出使用說明,也可以到網站的Getting Started網頁查看。

c:\Users\Jerry\AppData\Local\clink>go -h

    Quick directory changing.

    Usage:
        go <shortcut>[/sub/dir/path]    # change directories
                                        # same as "go -c ..."
        go -c|-o|-a|-d|-s ...           # cd, open, add, delete, set
        go --list [<pattern>]           # list matching shortcuts

    Options:
        -h, --help                      print this help and exit
        -V, --version                   print verion info and exit

        -c, --cd <path>                 cd to shortcut path in shell
        -s, --set <shortcut> <dir>      set a shortcut to <dir>
        -a, --add-current <shortcut>    add shortcut to current directory
        -d, --delete <shortcut>         delete the named shortcut
        -o, --open <path>               open the given shortcut path in
                                        explorer (Windows only)
        -l, --list [<pattern>]          list current shortcuts

    Generally you have a set of directories that you commonly visit.
    Typing these paths in full can be a pain. This script allows one to
    define a set of directory shortcuts to be able to quickly change to
    them. For example, I could define 'ko' to represent
    "D:\trentm\main\Apps\Komodo-devel", then
        C:\> go ko
        D:\trentm\main\Apps\Komodo-devel>
    and
        C:\> go ko/test
        D:\trentm\main\Apps\Komodo-devel\test>

    As well, you can always use some standard shortcuts, such as '~'
    (home) and '...' (up two dirs).

    See <http://code.google.com/p/go-tool/> for more information.

添加shortcut與快速切換目錄

先切換到經常使用的資料夾後,輸入go -a shortcut命令就能將資料夾加入shortcut清單裡:

c:
cd \Users\Jerry\AppData\Local
go -a apdata

go -l就能列出現有的shortcut清單,用go shortcut就能立即切換目錄到shortcut代表的目錄。

go apdata

rem 切換到上二層目錄
go ...

go -o shortcut則會將shortcut代表的資料夾在檔案總管裡顯示。

結語

以功能的簡易性來說,autojump的智慧切換目錄是比較理想的,但在找到autojump能正常運行之前,go-tool也能簡化一些切換目錄的操作。

##

您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *