I have two directories: src and projects. I would like to prevent myself from running git ... unless I am specifically inside src or projects. Is this possible?
Is it possible to restrict certain commands from being run in a directory?
shell;command line;git
It is difficult to prevent the binary from being run but for the typical situations an easy protection method exists:You define a shell function that overwrites the name. This will obviously not work in another (also another user's) shell.You take the binary out of the $PATH and replace it by a wrapper script. This is safer but will obviously cause problems with software updates (the script gets overwritten).The shell function could look like this: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}