Skip to content

Commit e282450

Browse files
committed
Add basic bash completion script
1 parent 129f910 commit e282450

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
#
4+
# This file is part of the PHP Code Compiler project
5+
#
6+
# Copyright (c) Yannoff (https://github.com/yannoff)
7+
#
8+
# @project PHP Code Compiler (yannoff/phpcc)
9+
# @homepage https://github.com/yannoff/phpcc
10+
# @license https://github.com/yannoff/phpcc/blob/main/LICENSE
11+
#
12+
# For the full copyright and license information, please view
13+
# the LICENSE file that was distributed with this source code.
14+
#
15+
16+
#
17+
# Remove - or -- prefix from an option name beginning
18+
#
19+
# args:
20+
# $1: the raw option name (eg: "-op" or "--long-o")
21+
#
22+
__trim(){ local w=$1; if [ "${w:0:2}" = "--" ]; then echo ${w:2}; elif [ "${w:0:1}" = "-" ]; then echo ${w:1}; else echo ${w}; fi }
23+
24+
#
25+
# PHP Code Compiler bash completion command
26+
#
27+
# args:
28+
# $1: the command word
29+
# $2: the current word
30+
# $3: the previous word
31+
#
32+
__comp_phpcc_command(){
33+
local prev=$3 cur=$2 options=()
34+
35+
options+=( banner )
36+
options+=( debug )
37+
options+=( dir )
38+
options+=( file )
39+
options+=( help )
40+
options+=( main )
41+
options+=( meta )
42+
options+=( no-minify )
43+
options+=( output )
44+
options+=( quiet )
45+
options+=( shebang-less )
46+
47+
case "${prev}" in
48+
--banner|--dir|--file|--main|--output)
49+
# if previous typed option expects a file or directory path,
50+
# let the reply empty so that readline's default
51+
# completion is attempted
52+
;;
53+
54+
*)
55+
case "$cur" in
56+
-*|"")
57+
compgen -W "${options[*]}" -P -- $(__trim ${cur})
58+
;;
59+
60+
*)
61+
;;
62+
esac
63+
;;
64+
esac
65+
}
66+
complete -o default -C __comp_phpcc_command phpcc

0 commit comments

Comments
 (0)