unix - 当 cd 进入目录时显示自定义消息

标签 unix rvm rvmrc

我正在寻找一种在 cd 进入目录时显示自定义消息的方法。例如

$ cd some_folder
Warning: Don't edit these files!
some_folder $

从一篇旧文章中,我发现了将其添加到我的 .bashrc 文件的建议:

reminder_cd() {
  builtin cd "$@" && { [ ! -f .cd-reminder ] || cat .cd-reminder 1>&2; }
}

alias cd=reminder_cd

使用此脚本,如果我的文件夹中有一个文件 .reminder_cd,则当我 cd 进入该文件时,会显示该文件的内容。

这可行,但它似乎杀死了当您 cd 进入目录时执行操作的其他脚本。具体来说,当您 cd 进入目录时,它会阻止 Ruby RVM 使用 .rvmrc 切换 ruby​​ 版本的能力。

有没有办法修改上面的函数(或使用完全不同的技术),以便它不会清除输入文件夹时使用的任何现有脚本?

最佳答案

RVM 具有适用于大多数命令的 Hook ,您可以创建一个:

hook="$rvm_path/hooks/after_cd_reminder"
echo "[ ! -f .cd-reminder ] || cat .cd-reminder 1>&2" > "$hook"
chmod +x "$hook"

关于unix - 当 cd 进入目录时显示自定义消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14691798/

相关文章:

linux - 使用 sed 替换不规则数量的斜杠 (/)

linux - 使用键排序不起作用

ruby - 如何将 RVM 指向我的 Homebrew Ruby 目录?

installation - 如何使用rvm在OS_X 10.9上安装ruby 2.1.0? ( : osx/10. 9/x86_64/ruby 没有可用的二进制 ruby )

ruby - 使用 ansible playbook 更改 rvm ruby​​ 版本

ruby-on-rails - 带有 Bundler 的 rvm gemsets

rvm - 更新 rvm 破坏了我的整个环境,因为我运行的是 "get head"而不是 "get stable"

Python终端输出宽度

linux - 为什么这个 SED 命令不起作用?

ruby-on-rails - RVM 安装 bash 脚本什么都不做