zoukankan      html  css  js  c++  java
  • 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生成引擎有问题,文中的引用部分生成的完全不对,让我找找问题先。。。 __

  • 相关阅读:
    C# 获取Enum 描述
    VC++ Vector取数据,慎用memcpy
    VC++ Char * 保存成bmp和JPEG
    VC++ 应用程序调用MFC DLL里的窗体
    yolov3.cfg参数说明及调参经验
    WIN10+YOLOv4,windows上完美执行YOLOv4目标检测
    Nvdia GPU
    C++ 编程习惯(提高速度)
    VC++发布Dll如何区分Debug和Release
    _CRT_SECURE_NO_WARNINGS错误提示,解决办法
  • 原文地址:https://www.cnblogs.com/yaoshan/p/3924381.html
Copyright © 2011-2022 走看看