Skip to content

Commit

Permalink
feature: leading pattern for subpath completion with ^ or :
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe committed Apr 16, 2019
1 parent a1812f7 commit 5109e76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions __diraction-dispatch
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ then # Subcomand completion
return 1
fi
;;
:*) # Leading Pattern
local subpath=${subcommand#:}
local nslash=$(echo $subpath | grep -o / |tr -d '\n' | wc -c)
local dirpattern=''; for n ({0..$nslash}); do dirpattern="$dirpattern*/"; done
local cmd="cd $dirdir && ls -d -- $dirpattern 2>>/dev/null | sed -E 's@^@:@g' | grep -E \"^:$subpath\" "
local matches="$(eval $cmd 2>/dev/null)"
local paths; if [[ -n "$matches" ]]; then paths=("${(f)matches}"); else paths=(); fi
if [[ ${#paths} -gt 0 ]]; then
compadd -x "Matching Subdirs" -U ${paths[@]}
# _values dont works : having a special meaning
return 0
else
_message "No matching subdir"
return 1
fi
;;
*) # Basic argument
_describe -t commands "Dispatcher subcommand" _DIRACTION_HELP_SUBCOMMAND

Expand Down
13 changes: 12 additions & 1 deletion diractions.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,18 @@ function _diraction-dispatch() {
fi
else
echo "$cmd subdir does not exist" >&2;
_d
cd "$dir"
fi ;;
^*|:*) local sdir="$dir/${cmd#?}"
if [[ -d "$sdir" ]]; then
if [[ -z "$@" ]]; then
cd "$sdir"
else
cdir=$cdir _diraction-dispatch "$sdir" $@
fi
else
echo "$cmd subdir does not exist" >&2;
cd "$dir"
fi ;;

# §maybe : o, open? (wrapping with glob?)
Expand Down

0 comments on commit 5109e76

Please sign in to comment.