You can't make a directory executable as a script, but you can create a wrapper that calls the scripts in the directory.
You can do this either with a function (in your profile script or a file in your FPATH
) or with a wrapper script.
A simple function might look like:
git() {
local subPath='/path/to/your/git'
local sub="${1}" ; shift
if [[ -x "${subPath}/${1}" ]]; then
"${subPath}/${sub}" "${@}"
return $?
else
printf '%s\n' "git: Unknown sub-command '${sub}'." >&2
return 1
fi
}
(This is the same way that the sub
project you linked works, just simplified.)
Of course, if you actually want to create a sub-command for git
specifically (and that wasn't just an example), you'll need to make sure that the built-in git
commands still work. In that case you could do like this:
git() {
local subPath='/path/to/your/git'
local sub="${1}"
if [[ -x "${subPath}/${sub}" ]]; then
shift
"${subPath}/${sub}" "${@}"
return $?
else
command git "${@}"
return 1
fi
}
But it might be worth pointing out in that case that git
supports adding arbitrary aliases via git config
:
git config --global alias.who '!/path/to/your/git/who'