-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpcc-completion
More file actions
73 lines (65 loc) · 1.81 KB
/
phpcc-completion
File metadata and controls
73 lines (65 loc) · 1.81 KB
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
72
73
#!/bin/bash
#
# This file is part of the PHP Code Compiler project
#
# Copyright (c) Yannoff (https://github.com/yannoff)
#
# @project PHP Code Compiler (yannoff/phpcc)
# @homepage https://github.com/yannoff/phpcc
# @license https://github.com/yannoff/phpcc/blob/main/LICENSE
#
# For the full copyright and license information, please view
# the LICENSE file that was distributed with this source code.
#
#
# Remove - or -- prefix from an option name beginning
#
# args:
# $1: the raw option name (eg: "-op" or "--long-o")
#
__trim(){ local w=$1; if [ "${w:0:2}" = "--" ]; then echo ${w:2}; elif [ "${w:0:1}" = "-" ]; then echo ${w:1}; else echo ${w}; fi }
#
# PHP Code Compiler bash completion command
#
# args:
# $1: the command word
# $2: the current word
# $3: the previous word
#
__comp_phpcc_command(){
local prev=$3 cur=$2 options=()
options+=( banner )
options+=( debug )
options+=( dir )
options+=( file )
options+=( help )
options+=( main )
options+=( meta )
options+=( no-minify )
options+=( output )
options+=( quiet )
options+=( shebang-less )
case "${prev}" in
# previous typed option expects a file path
--banner|--file|--main|--output)
compgen -d -f ${cur}
;;
# previous typed option expects a directory path
--dir)
compgen -d ${cur}
;;
# previous typed option is not elligible to completion
--meta)
;;
*)
case "$cur" in
-*|"")
# If comp word is empty or starts with a minus sign,
# then use the long options list for completion
compgen -W "${options[*]}" -P -- $(__trim ${cur})
;;
esac
;;
esac
}
complete -C __comp_phpcc_command phpcc