sda*_*das 4 command-line shell git
我有两个目录:src和projects. 我想阻止自己跑步,git ...除非我特别在里面src或projects. 这可能吗?
很难阻止二进制文件运行,但对于典型情况,存在一种简单的保护方法:
shell 函数可能如下所示:
git () {
local cwd="$(pwd -P)"
if ! [ "/path/to/src" = "$cwd" -o "/path/to/projects" = "$cwd" ]; then
echo "The current working directory is: '${cwd}'"
echo "git must not be run from here; from src and projects only."
echo "Aborting."
else
command git "$@"
fi
}
Run Code Online (Sandbox Code Playgroud)