mirror of
https://github.com/TheLocehiliosan/yadm
synced 2025-06-13 13:03:58 +00:00
Fix handling of filenames with space in bash completion (#341)
By calling __gitcompappend with the same suffix as the completion for git does (i.e. " ") we can remove the call to sort -u as it is no longer needed (bash seems to remove duplicates) and then spaces are handled correctly. Also make the completion available in testhost.
This commit is contained in:
parent
bee1558a4e
commit
2ac90b004c
1
Makefile
1
Makefile
@ -123,6 +123,7 @@ testhost: require-docker .testyadm
|
|||||||
--hostname testhost \
|
--hostname testhost \
|
||||||
--rm -it \
|
--rm -it \
|
||||||
-v "$(CURDIR)/.testyadm:/bin/yadm:ro" \
|
-v "$(CURDIR)/.testyadm:/bin/yadm:ro" \
|
||||||
|
-v "$(CURDIR)/completion/bash/yadm:/usr/share/bash-completion/completions/yadm:ro" \
|
||||||
$(IMAGE) \
|
$(IMAGE) \
|
||||||
bash -l
|
bash -l
|
||||||
|
|
||||||
|
@ -12,16 +12,15 @@ if declare -F _git > /dev/null || declare -F __git_wrap__git_main > /dev/null; t
|
|||||||
|
|
||||||
local current=${COMP_WORDS[COMP_CWORD]}
|
local current=${COMP_WORDS[COMP_CWORD]}
|
||||||
local penultimate
|
local penultimate
|
||||||
if [ "$((COMP_CWORD-1))" -ge "0" ]; then
|
if ((COMP_CWORD >= 1)); then
|
||||||
penultimate=${COMP_WORDS[COMP_CWORD - 1]}
|
penultimate=${COMP_WORDS[COMP_CWORD - 1]}
|
||||||
fi
|
fi
|
||||||
local antepenultimate
|
local antepenultimate
|
||||||
if [ "$((COMP_CWORD-2))" -ge "0" ]; then
|
if ((COMP_CWORD >= 2)); then
|
||||||
antepenultimate=${COMP_WORDS[COMP_CWORD - 2]}
|
antepenultimate=${COMP_WORDS[COMP_CWORD - 2]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -x GIT_DIR
|
local -x GIT_DIR
|
||||||
# shellcheck disable=SC2034
|
|
||||||
GIT_DIR="$(yadm introspect repo 2>/dev/null)"
|
GIT_DIR="$(yadm introspect repo 2>/dev/null)"
|
||||||
|
|
||||||
case "$penultimate" in
|
case "$penultimate" in
|
||||||
@ -75,9 +74,7 @@ if declare -F _git > /dev/null || declare -F __git_wrap__git_main > /dev/null; t
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ "$current" =~ ^- ]]; then
|
if [[ "$current" =~ ^- ]]; then
|
||||||
local matching
|
__gitcompappend "${yadm_switches[*]}" "" "$current" " "
|
||||||
matching=$(compgen -W "${yadm_switches[*]}" -- "$current")
|
|
||||||
__gitcompappend "$matching"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Find the index of where the sub-command argument should go.
|
# Find the index of where the sub-command argument should go.
|
||||||
@ -93,19 +90,11 @@ if declare -F _git > /dev/null || declare -F __git_wrap__git_main > /dev/null; t
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [[ "$COMP_CWORD" = "$command_idx" ]]; then
|
if [[ "$COMP_CWORD" = "$command_idx" ]]; then
|
||||||
local matching
|
__gitcompappend "$(yadm introspect commands 2>/dev/null)" "" "$current" " "
|
||||||
matching=$(compgen -W "$(yadm introspect commands 2>/dev/null)" -- "$current")
|
|
||||||
__gitcompappend "$matching"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove duplicates found in COMPREPLY (a native bash way could be better)
|
|
||||||
if [ -n "${COMPREPLY[*]}" ]; then
|
|
||||||
COMPREPLY=($(echo "${COMPREPLY[@]}" | sort -u))
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -o bashdefault -o default -F _yadm yadm 2>/dev/null \
|
complete -o bashdefault -o default -o nospace -F _yadm yadm 2>/dev/null ||
|
||||||
|| complete -o default -F _yadm yadm
|
complete -o default -o nospace -F _yadm yadm
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user