aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/mysql.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-30 14:43:33 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-30 14:51:41 +1200
commit95c3c2daf1e63f02a37db0e003f01da788acfb7d (patch)
tree8d477a9d48f58b8100b34892478bdce619db4ee4 /bash/bash_completion.d/mysql.bash
parentNote broken mysql() (diff)
downloaddotfiles-95c3c2daf1e63f02a37db0e003f01da788acfb7d.tar.gz
dotfiles-95c3c2daf1e63f02a37db0e003f01da788acfb7d.zip
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.
Diffstat (limited to 'bash/bash_completion.d/mysql.bash')
-rw-r--r--bash/bash_completion.d/mysql.bash14
1 files changed, 9 insertions, 5 deletions
diff --git a/bash/bash_completion.d/mysql.bash b/bash/bash_completion.d/mysql.bash
index f64b6f32..9755f033 100644
--- a/bash/bash_completion.d/mysql.bash
+++ b/bash/bash_completion.d/mysql.bash
@@ -12,6 +12,7 @@ _mysql() {
# Return the names of the .cnf files sans prefix as completions
local db
while IFS= read -rd '' db ; do
+ [[ -n $db ]] || continue
COMPREPLY[${#COMPREPLY[@]}]=$db
done < <(
@@ -24,11 +25,14 @@ _mysql() {
cnfs=("${cnfs[@]#"$dirname"/}")
cnfs=("${cnfs[@]%.cnf}")
- # Bail if no files to prevent empty output
- ((${#cnfs[@]})) || exit 1
-
- # Print the conf names, null-delimited
- printf '%q\0' "${cnfs[@]}"
+ # 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 ((${#cnfs[@]})) ; then
+ printf '%q\0' "${cnfs[@]}"
+ else
+ printf '\0'
+ fi
)
}
complete -F _mysql -o default mysql