The goal is to make some set of commands available to the user after they clone/checkout repo.
the git hook file
#!/bin/sh
echo $PWD/dev-commands.sh
source $PWD/dev-commands.sh
the command I want to make available after the git hook names dev-commands.sh
#!/bin/sh
function greet() {
echo Hello
}
this does not seem to make the command available. if I run source dev-commands.sh in the directory manually it does make the greet
commands availble..
any tips?
CodePudding user response:
Sourced functions are available in the shell that sourced them, not its parent shells. That's why when you write a shell script, it can use its own functions without worrying about interfering with what its invoker's commands mean.
( doit() { echo hi; }; doit ); doit
for instance, will say hi
and then very probably complain -bash: doit: command not found
or an equivalent message because the parens were there to put doit
into a subshell, which has its own environment, just like git hooks.
Altering someone's shell namespace on the fly without their active cooperation can and will be accurately described as malware.
Include a setup command they can source if they want.