From 95c3c2daf1e63f02a37db0e003f01da788acfb7d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 30 Aug 2016 14:43:33 +1200 Subject: Handle empty filename completions better Bash 4.4 hangs in an awkward way (probably outputting the literal null char in some unexpected context) without this; I'm not sure if this is a bug or whether it's just been tolerated behaviour until now. --- bash/bash_completion.d/sd.bash | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'bash/bash_completion.d/sd.bash') diff --git a/bash/bash_completion.d/sd.bash b/bash/bash_completion.d/sd.bash index f8017591..0c59f544 100644 --- a/bash/bash_completion.d/sd.bash +++ b/bash/bash_completion.d/sd.bash @@ -9,6 +9,7 @@ _sd() { # Build list of matching sibiling directories while IFS= read -rd '' dirname ; do + [[ -n $dirname ]] || continue COMPREPLY[${#COMPREPLY[@]}]=$dirname done < <( @@ -29,11 +30,14 @@ _sd() { sibs[${#sibs[@]}]=$dirname done - # Bail if no results to prevent empty output - ((${#sibs[@]})) || exit 1 - - # Print results, null-delimited - printf '%q\0' "${sibs[@]}" + # Print quoted sibs, null-delimited, if there was at least one; + # otherwise, just print a null character to stop this hanging in Bash + # 4.4 + if ((${#sibs[@]})) ; then + printf '%q\0' "${sibs[@]}" + else + printf '\0' + fi ) } complete -F _sd sd -- cgit v1.2.3