osx上使用'cd'命令跳转到别名(alias)目录

在mac上使用windows的共享目录时,在terminal中时法使用cd的,会提示"xxx 不是目录",经过一番的查找,发现了Mac Terminal 'cd' to folder alias,
经过本人验证时可以用的,具体步骤参考Make Terminal Follow Aliases Like Symlinks:

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:

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.

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.

 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.

在修改完.bashrc后只有在新打开terminal时才会有效,解决方法有:

1 每次操作前执行source .bashrc

2 一劳永逸的方法:将下面代码加到.base_profile文件后面

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

__ 注:我是使用hexo写的本篇,应该是hexo的markdown生成引擎有问题,文中的引用部分生成的完全不对,让我找找问题先。。。 __

转载于:https://www.cnblogs.com/yaoshan/p/3924381.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值