mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-03 15:47:23 -04:00
Do not auto-complete directories in shell completions (only entries)
This commit is contained in:
+12
-11
@@ -1,24 +1,25 @@
|
|||||||
# mutn(1) completion
|
# mutn(1) completion
|
||||||
|
|
||||||
_path_gen() {
|
_path_gen() {
|
||||||
local mutn_path="$HOME/.local/share/libmutton"
|
local mutnPath="$HOME/.local/share/libmutton"
|
||||||
local glob_status=$(shopt -p globstar)
|
local globStatus=$(shopt -p globstar)
|
||||||
[ -z "${glob_status##*u*}" ] && shopt -s globstar # if recursive globbing is disabled, enable it
|
[ -z "${globStatus##*u*}" ] && shopt -s globstar # if recursive globbing is disabled, enable it
|
||||||
local full_paths=("$mutn_path"/**/*)
|
local fullPaths=("$mutnPath"/**/*)
|
||||||
$glob_status # set recursive globbing to user default
|
$globStatus # set recursive globbing to user default
|
||||||
for scan_path in "${full_paths[@]}"; do
|
for scanPath in "${fullPaths[@]}"; do
|
||||||
trimmed_paths+=("${scan_path#$mutn_path}")
|
# exclude directories
|
||||||
|
[ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}")
|
||||||
done
|
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 cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
local prev=${COMP_WORDS[COMP_CWORD-1]}
|
local prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||||
|
|
||||||
case $prev in
|
case $prev in
|
||||||
mutn )
|
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" )
|
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "copy edit gen add shear" -- "$cur" )
|
||||||
@@ -38,4 +39,4 @@ _mutn_completions() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
} &&
|
} &&
|
||||||
_path_gen && complete -F _mutn_completions mutn
|
_path_gen && complete -F _mutnCompletions mutn
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ function MUTNEntryCompleter {
|
|||||||
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
|
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
|
||||||
#$entryPath = (Resolve-Path '~/.local/share/libmutton').Path # UNIX testing
|
#$entryPath = (Resolve-Path '~/.local/share/libmutton').Path # UNIX testing
|
||||||
$entryPath = (Resolve-Path '~/AppData/Local/libmutton/entries').Path
|
$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*" }
|
$entryNames | Where-Object { $_ -like "$wordToComplete*" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
#compdef mutn
|
#compdef mutn
|
||||||
|
|
||||||
mutn_path="$HOME/.local/share/libmutton"
|
mutnPath="$HOME/.local/share/libmutton"
|
||||||
full_paths=("$mutn_path"/**/*)
|
fullPaths=("$mutnPath"/**/*)
|
||||||
trimmed_paths=()
|
trimmedPaths=()
|
||||||
for scan_path in "${full_paths[@]}"; do
|
for scanPath in "${fullPaths[@]}"; do
|
||||||
trimmed_paths+=("${scan_path#$mutn_path}")
|
# exclude directories
|
||||||
|
[ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}")
|
||||||
done
|
done
|
||||||
[[ -z $trimmed_paths ]] && trimmed_paths=(help)
|
[[ -z $trimmedPaths ]] && trimmedPaths=(help)
|
||||||
|
|
||||||
case ${words[-2]} in
|
case ${words[-2]} in
|
||||||
mutn )
|
mutn )
|
||||||
compadd $trimmed_paths
|
compadd $trimmedPaths
|
||||||
;;
|
;;
|
||||||
/* )
|
/* )
|
||||||
compadd {copy,edit,gen,add,shear}
|
compadd {copy,edit,gen,add,shear}
|
||||||
|
|||||||
Reference in New Issue
Block a user