Escape space in YADM_HOOK_FULL_COMMAND (#187)

Backslashes are used to escape spaces, tabs, and backslashes. This
allows hooks to identify separate parameters (which are space
delimited).
This commit is contained in:
Tim Byrne 2020-01-23 08:11:19 -06:00
parent 3b820835ab
commit ccb75b97ea
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
1 changed files with 10 additions and 1 deletions

11
yadm
View File

@ -70,7 +70,16 @@ function main() {
require_git
# capture full command, for passing to hooks
FULL_COMMAND="$*"
# the parameters will be space delimited and
# spaces, tabs, and backslashes will be escaped
_tab=$'\t'
for param in "$@"; do
param="${param//\\/\\\\}"
param="${param//$_tab/\\$_tab}"
param="${param// /\\ }"
_fc+=( "$param" )
done
FULL_COMMAND="${_fc[*]}"
# create the YADM_DIR if it doesn't exist yet
[ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR"