Mar*_*ltz 7 command-line shell-script rvm macos
如果答案很明显,我很抱歉,但我还没有找到答案(可能是因为我搜索的术语不正确)。
我在运行 Snow Leopard 的 Mac 上,我想知道当我输入/cd 到该目录时是否可以自动运行 shell 命令(或脚本)。
一个更好地说明我的问题的例子:我使用RVM来管理 Ruby 的版本。它对它的项目.rvmrc文件采用了类似的策略。这些文件在输入它们所在的目录时运行,以便为该特定项目使用正确版本的 Ruby。
我想做类似的事情,以便在输入包含目录的文件时显示 todo.txt 文件的内容。
将以下内容添加到您的~/.bash_profile:
function cd {
# actually change the directory with all args passed to the function
builtin cd "$@"
# if there's a regular file named "todo.txt"...
if [ -f "todo.txt" ] ; then
# display its contents
cat todo.txt
fi
}
Run Code Online (Sandbox Code Playgroud)
可能你已经有一个类似的功能cd——只要扩展那个功能来打印它的内容(todo.txt如果它存在)。
| 归档时间: |
|
| 查看次数: |
3479 次 |
| 最近记录: |