Do not auto-complete directories in shell completions (only entries)

This commit is contained in:
2024-03-18 14:39:55 -04:00
parent 26a5898e15
commit e4de8f930b
3 changed files with 21 additions and 19 deletions
+12 -11
View File
@@ -1,24 +1,25 @@
# mutn(1) completion
_path_gen() {
local mutn_path="$HOME/.local/share/libmutton"
local glob_status=$(shopt -p globstar)
[ -z "${glob_status##*u*}" ] && shopt -s globstar # if recursive globbing is disabled, enable it
local full_paths=("$mutn_path"/**/*)
$glob_status # set recursive globbing to user default
for scan_path in "${full_paths[@]}"; do
trimmed_paths+=("${scan_path#$mutn_path}")
local mutnPath="$HOME/.local/share/libmutton"
local globStatus=$(shopt -p globstar)
[ -z "${globStatus##*u*}" ] && shopt -s globstar # if recursive globbing is disabled, enable it
local fullPaths=("$mutnPath"/**/*)
$globStatus # set recursive globbing to user default
for scanPath in "${fullPaths[@]}"; do
# exclude directories
[ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}")
done
if [ "${trimmed_paths[0]}" == '/**/*' ]; then trimmed_paths[0]=help; fi
if [ "${trimmedPaths[0]}" == '' ]; then trimmedPaths[0]=help; fi
} &&
_mutn_completions() {
_mutnCompletions() {
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
case $prev in
mutn )
while read -r; do ITEM=${REPLY// /\\ }; COMPREPLY+=( "$ITEM" ); done < <( compgen -W "$(printf "'%s' " "${trimmed_paths[@]}")" -- "$cur" )
while read -r; do ITEM=${REPLY// /\\ }; COMPREPLY+=( "$ITEM" ); done < <( compgen -W "$(printf "'%s' " "${trimmedPaths[@]}")" -- "$cur" )
;;
/* )
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "copy edit gen add shear" -- "$cur" )
@@ -38,4 +39,4 @@ _mutn_completions() {
esac
} &&
_path_gen && complete -F _mutn_completions mutn
_path_gen && complete -F _mutnCompletions mutn