From 45b5ac8b510400bcccbf893dee2229757533d7a7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 23 May 2017 13:21:15 +1200 Subject: Fix up completions for td(1df) Hung on null completion --- bash/bash_completion.d/td.bash | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'bash/bash_completion.d') diff --git a/bash/bash_completion.d/td.bash b/bash/bash_completion.d/td.bash index eb29992b..db232dd6 100644 --- a/bash/bash_completion.d/td.bash +++ b/bash/bash_completion.d/td.bash @@ -4,16 +4,23 @@ _td() { dir=${TODO_DIR:-"$HOME"/Todo} local fn while IFS= read -rd '' fn ; do + [[ -n $fn ]] || continue COMPREPLY[${#COMPREPLY[@]}]=$fn done < <( shopt -s extglob nullglob shopt -u dotglob - local -a fns + declare -a fns fns=("$dir"/"${COMP_WORDS[COMP_CWORD]}"*) fns=("${fns[@]#"$dir"/}") - ((${#fns[@]})) || exit 1 - printf '%s\0' "${fns[@]##"$dir"/}" + + # Print quoted entries, null-delimited, if there was at least one; + # otherwise, just print a null character to stop this hanging in Bash + # 4.4 + if ((${#fns[@]})) ; then + printf '%q\0' "${fns[@]}" + else + printf '\0' + fi ) - return } complete -F _td td -- cgit v1.2.3