-
Notifications
You must be signed in to change notification settings - Fork 1
/
__diraction-dispatch
71 lines (60 loc) · 2.31 KB
/
__diraction-dispatch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#compdef _diraction-dispatch
# completion for the dispatcher command
# words: 1:function 2:directory 3:pattern
local diract=$words[2]
local dirdir=`eval echo $diract`
local subcommand=$words[3]
# Update Pwd to make subcompleter to consider we are in the target directory
PWD=$dirdir
if (( CURRENT == 3));
then # Subcomand completion
case $subcommand in
/*) # Pattern :D
local pattern="${subcommand#/}"
local cmd="cd $dirdir && ls -d $pattern*/ 2>/dev/null | sed -E 's:^:/:g' | xargs echo"
compadd -S '' -x "Matching Subdirs:" $(eval $cmd) || _message "No subdir matching"
# Ânote: _directories can't work since / is the leading char
# Â- maybe change behavior if no match
# improve completion valuessss!!!!
return 0
;;
*) # Basic argument
compadd -x "Whitelisted commands" $DIRACTION_DISPATCH_WHITELIST
# maybe extend subcommands with these value??
# or extend the array here?
_describe -t commands "Dispatcher subcommand" _DIRACTION_HELP_SUBCOMMAND
return
esac
else # argument completion
shift words; shift words # shifting words args
((CURRENT = CURRENT -2))
case $subcommand in
e|"exec"|[-,_]) # magic native completion
shift words; ((CURRENT--))
if ((CURRENT == 1 )); then
_command_names
elif functions "_${words[1]}" > /dev/null; then
"_${words[1]}"
else
_path_files -W $PWD ; _options_set
fi ; return 0
;;
i|interactive|prompt|shell|help)
_message "Just hit enter, and enter the interactive mode :)" && return 0;;
/)
_directories -W "$PWD"
;;
*)
local compfun="_${subcommand}"
if functions "$compfun" > /dev/null; then
# §tofix: git error: zsh:12: command not found: ___diraction-dispatch_main
# if so do it up
$compfun && return 0
# beware to file completion:
# https://github.com/robbyrussell/oh-my-zsh/issues/2394
else
_message "No Specific completion available for $subcommand"
fi
;;
esac
fi