【问题标题】:How to change the terminal prompt to just current directory? [closed]如何将终端提示更改为当前目录? [关闭]
【发布时间】:2014-01-21 16:23:11
【问题描述】:

我使用的是 Macbook Pro,我想将其更改为当前目录和终端中的美元符号提示。我已经查看了 these resources 来尝试解决这个问题。

我尝试修改 ~/.bashrc 文件并保存它,但它似乎不起作用。

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PS1="\W$ ”

最后一行是我添加的用于更改提示的内容。

【问题讨论】:

    标签: macos path terminal


    【解决方案1】:

    这应该在 .bash_profile 中完成,而不是在 .bashrc 中。

    nano ~/.bash_profile
    

    添加一行包含以下内容:

    export PS1="\W\$ "
    

    .bashrc 仅在启动子 shell 时执行。 bash 登录 shell 使用以下初始化脚本:

    .bash_profile
    .bash_login
    .profile
    

    【讨论】:

      【解决方案2】:

      您需要转义美元符号。像这样:

      $ PS1="\W\$ "
      ~$ cd tmp
      /Users/philip/tmp
      tmp$
      

      一旦您更改了 .bashrc,您要么需要注销/重新登录,要么需要 . ~/.bashrc 重新获取它。

      我会谦虚地建议不要这样做。拥有完整路径非常有用,因为“tmp”目录可以在任何地方。考虑使用执行相对路径的“\w”(即使用 ~ 表示 HOME)

      【讨论】:

      • 我正在考虑使用完整路径。无论如何,我使用了. ~/.bashrc,但是当我每次打开终端窗口时都必须使用它时。是我做错了什么,还是没有解决方法?
      猜你喜欢
      • 2013-08-29
      • 2015-01-28
      • 1970-01-01
      • 2014-07-26
      • 2019-09-04
      • 2012-10-25
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      相关资源
      最近更新 更多