-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__diraction-dispatch
41 lines (35 loc) Β· 1.2 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
#compdef _diraction-dispatch
# completion for the dispatcher command
# words: 1:function 2:directory 3:pattern
# Β§TODO: also switch based on current!
# so that can improved completion of subcommand needing args
case $words[3] in
/*) # Pattern :D
local diract=$words[2]
local dirdir=`eval echo $diract`
local pattern="${words[3]#/}"
local cmd="$cd $dirdir && ls -d $pattern* 2>/dev/null | sed -E 's:^:/:g' | xargs echo"
# maybe extract fund
for dir in $(eval $cmd)
do
compadd $dir
done && return 0
;;
*) # Basic argument
local -a subcommands
subcommands=(
'ls:List files in the specified folder (alias l)'
'exec:Exec (through eval) the specified command (alias e -,` )'
'interactive:Go in interactive mode, to perform several commands (alias i,prompt,shell)'
'/:Go in some of the subfolder if provided (alias c cd)'
'edit:Edit the given subfile (alias ed)'
'brower:Launch browser on the directory (alias b)'
'tree:Launch tree command (alias t)'
)
#TODO: maybe make this a gloabl variable to add user defined function?
# or extend the array here?
if (( CURRENT == 3)); then
_describe -t commands "Dispatcher subcommand" subcommands
return
fi
esac