osx上使用'cd'命令跳轉到別名(alias)目錄

在mac上使用windows的共享目錄時,在terminal中時法使用cd的,會提示"xxx 不是目錄",通過一番的查找,發現了Mac Terminal 'cd' to folder alias,
通過本人驗證時能夠用的,具體步驟參考Make Terminal Follow Aliases Like Symlinks:web

This is a two-part process requiring a little familiarity with gcc and bash, but I’ll try to make it as simple as possible. Firstly, you need this file: getTrueName.c. This file was created by Thos Davis and is licensed under the GPLv2. Save it anywhere, then compile it with the following command:shell

gcc -o getTrueName -framework Carbon getTrueName.c
This will create the ‘getTrueName’ executable in the same directory as the source. You can add it to your PATH, or just copy it directly to /usr/bin so it’s easy to access.windows

Interestingly, when Terminal opens a new shell, .bashrc is not executed as you might expect. Instead, under the login shell, .bash_profile is executed. So, add the following to .bash_profile in your Home directory. You might need to create it first; it isn’t there by default.bash

function cd {
      if [ ${#1} == 0 ]; then
        builtin cd
      elif [ -d "${1}" ]; then
        builtin cd "${1}"
      elif [[ -f "${1}" || -L "${1}" ]]; then
        path=$(getTrueName "$1")
        builtin cd "$path"
      else
        builtin cd "${1}"
      fi
    }

Effectively, this looks for Finder aliases and resolves them before deferring to the builtin cd command. Append it to your .bash_profile, then either execute it or restart Terminal for the changes to take effect. Now you can cd to Finder aliases within Terminal and have them treated just like symlinks. Just like it should be.markdown

在修改完.bashrc後只有在新打開terminal時纔會有效,解決方法有:hexo

1 每次操做前執行source .bashrcui

2 一勞永逸的方法:將下面代碼加到.base_profile文件後面this

if [ "${BASH-no}" != "no" ]; then
  [ -r ~/.bashrc ] && . ~/.bashrc
fi

__ 注:我是使用hexo寫的本篇,應該是hexo的markdown生成引擎有問題,文中的引用部分生成的徹底不對,讓我找找問題先。。。 __.net

相關文章
相關標籤/搜索