diff --git a/extra/completion.bash b/extra/completion.bash index d854af2..c9ddca5 100644 --- a/extra/completion.bash +++ b/extra/completion.bash @@ -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 diff --git a/extra/completion.ps1 b/extra/completion.ps1 index 9edb418..4db9b2d 100644 --- a/extra/completion.ps1 +++ b/extra/completion.ps1 @@ -2,7 +2,7 @@ function MUTNEntryCompleter { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) #$entryPath = (Resolve-Path '~/.local/share/libmutton').Path # UNIX testing $entryPath = (Resolve-Path '~/AppData/Local/libmutton/entries').Path - $entryNames = If (Test-Path $entryPath) {(Get-ChildItem -Path $entryPath -Recurse).FullName.Substring($entryPath.Length) -replace '\\', '/' -replace ' ', '` '} + $entryNames = If (Test-Path $entryPath) {(Get-ChildItem -Path $entryPath -Recurse -File).FullName.Substring($entryPath.Length) -replace '\\', '/' -replace ' ', '` '} $entryNames | Where-Object { $_ -like "$wordToComplete*" } } diff --git a/extra/completion.zsh b/extra/completion.zsh index 6d16b34..c2c87b8 100644 --- a/extra/completion.zsh +++ b/extra/completion.zsh @@ -1,16 +1,17 @@ #compdef mutn -mutn_path="$HOME/.local/share/libmutton" -full_paths=("$mutn_path"/**/*) -trimmed_paths=() -for scan_path in "${full_paths[@]}"; do - trimmed_paths+=("${scan_path#$mutn_path}") +mutnPath="$HOME/.local/share/libmutton" +fullPaths=("$mutnPath"/**/*) +trimmedPaths=() +for scanPath in "${fullPaths[@]}"; do + # exclude directories + [ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}") done -[[ -z $trimmed_paths ]] && trimmed_paths=(help) +[[ -z $trimmedPaths ]] && trimmedPaths=(help) case ${words[-2]} in mutn ) - compadd $trimmed_paths + compadd $trimmedPaths ;; /* ) compadd {copy,edit,gen,add,shear}