From e521cec24eb88b70cb15b5244e86a5d76032de99 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Dec 2018 02:13:23 +1300 Subject: Use simpler method of no case completion check --- bash/bash_completion.d/path.bash | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'bash/bash_completion.d/path.bash') diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash index 8b72a062..da867880 100644 --- a/bash/bash_completion.d/path.bash +++ b/bash/bash_completion.d/path.bash @@ -26,17 +26,12 @@ _path() { # Set options to glob correctly shopt -s dotglob nullglob - # Make globbing case-insensitive if appropriate; is there a cleaner way - # to find this value? - while read -r _ option value ; do - case $option in - (completion-ignore-case) - case $value in - (on) - shopt -s nocaseglob - break - ;; - esac + # Make globbing case-insensitive if appropriate + while read -r _ setting ; do + case $setting in + ('completion-ignore-case on') + shopt -s nocaseglob + break ;; esac done < <(bind -v) -- cgit v1.2.3 From 626593c3712531c251c69be2e561a34da98cdcdf Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Dec 2018 02:19:46 +1300 Subject: Remove null-result guard from completion gens I don't believe these are needed anymore, or possibly ever were. --- bash/bash_completion.d/path.bash | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'bash/bash_completion.d/path.bash') diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash index da867880..fcb57949 100644 --- a/bash/bash_completion.d/path.bash +++ b/bash/bash_completion.d/path.bash @@ -41,14 +41,8 @@ _path() { dirnames=("${COMP_WORDS[COMP_CWORD]}"*/) dirnames=("${dirnames[@]%/}") - # 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 ((${#dirnames[@]})) ; then - printf '%q\0' "${dirnames[@]}" - else - printf '\0' - fi + # Print quoted entries, null-delimited + printf '%q\0' "${dirnames[@]}" ) ;; -- cgit v1.2.3 From 0681de59778f82c9006de70ed9a9ee6644fd4a18 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Dec 2018 02:29:42 +1300 Subject: Adjust loop short circuits and pattern matches --- bash/bash_completion.d/path.bash | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'bash/bash_completion.d/path.bash') diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash index fcb57949..9aab8488 100644 --- a/bash/bash_completion.d/path.bash +++ b/bash/bash_completion.d/path.bash @@ -52,8 +52,11 @@ _path() { IFS=: read -rd '' -a promptarr < <(printf '%s\0' "$PATH") local part for part in "${promptarr[@]}" ; do - [[ $part == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue - COMPREPLY[${#COMPREPLY[@]}]=$(printf '%q' "$part") + case $part in + "${COMP_WORDS[COMP_CWORD]}"*) + COMPREPLY[${#COMPREPLY[@]}]=$(printf '%q' "$part") + ;; + esac done ;; -- cgit v1.2.3 From 18d31e8c13cf8ae97a16bfcf949dbae5391a47f2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Dec 2018 02:33:33 +1300 Subject: Break up a couple of long lines --- bash/bash_completion.d/path.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bash/bash_completion.d/path.bash') diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash index 9aab8488..ce494bd4 100644 --- a/bash/bash_completion.d/path.bash +++ b/bash/bash_completion.d/path.bash @@ -49,7 +49,8 @@ _path() { # Complete with directories from PATH remove) local -a promptarr - IFS=: read -rd '' -a promptarr < <(printf '%s\0' "$PATH") + IFS=: read -rd '' -a promptarr < \ + <(printf '%s\0' "$PATH") local part for part in "${promptarr[@]}" ; do case $part in -- cgit v1.2.3 From d6ed64f18cfccf1e6ffb5e5609f758beaec21def Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Dec 2018 02:34:04 +1300 Subject: Use simpler keyword complete for `path` subcommand --- bash/bash_completion.d/path.bash | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'bash/bash_completion.d/path.bash') diff --git a/bash/bash_completion.d/path.bash b/bash/bash_completion.d/path.bash index ce494bd4..7143b448 100644 --- a/bash/bash_completion.d/path.bash +++ b/bash/bash_completion.d/path.bash @@ -6,10 +6,18 @@ _path() { # Complete operation as first word local cmd - for cmd in list insert append remove shift pop check help ; do - [[ $cmd == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue + while read -r cmd ; do COMPREPLY[${#COMPREPLY[@]}]=$cmd - done + done < <(compgen -W ' + append + check + help + insert + list + pop + remove + shift + ' -- "${COMP_WORDS[COMP_CWORD]}") # Complete with either directories or $PATH entries as all other words else -- cgit v1.2.3