-
Notifications
You must be signed in to change notification settings - Fork 19
/
completion-jruby
74 lines (67 loc) · 2.29 KB
/
completion-jruby
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
74
#! bash
# bash completion for the `jruby` command.
#
# Copyright (c) 2009-2021 Daniel Luz <dev dot gsz at mernen dot com>.
# Distributed under the MIT license.
# https://mernen.com/projects/completion-ruby
#
# To use, source this file on bash:
# . completion-jruby
#
# This script works best when completion-ruby is also loaded.
__jruby() {
local cmd=$1
local cur=$2
local prev=$3
COMPREPLY=()
local options="
-G -J --jdb --environment --properties --sample --client --server --manager
--disable --enable
--headless --bytecode -X-O -X+O -X-C -X+C --fast --dev
--profile --profile.api --profile.flat --profile.graph --profile.html --profile.json --profile.out --profile.service"
local i
local script_given
local script_in_path
local switches_accepted=1
for ((i=1; i < $COMP_CWORD; ++i)); do
local arg=${COMP_WORDS[$i]}
case $arg in
-S)
script_in_path=1;;
-S*)
# Syntax supported by jruby, but not by ruby, oddly
script_given=1;;
--)
# End of switches
switches_accepted=
[[ $COMP_CWORD != $((i + 1)) ]] && script_given=1
break;;
-*)
;;
*)
# Non-switch arg, must be the script name
script_given=1
switches_accepted=;;
esac
done
if [[ $switches_accepted && $cur = -* ]]; then
COMPREPLY=($(compgen -W "$options" -- "$cur"))
elif [[ $script_in_path && ! $script_given ]]; then
local jruby_dir=$(dirname "$(which "$cmd")" 2>/dev/null)
if [[ -d $jruby_dir ]]; then
local jruby_cmds=($(find "$jruby_dir" -maxdepth 1 -type f -perm +111 2>/dev/null))
jruby_cmds=("${jruby_cmds[@]##*/}")
COMPREPLY=($(compgen -W "${jruby_cmds[*]}" -- "$cur"))
fi
elif [[ $prev = --enable || $prev = --disable ]]; then
COMPREPLY=($(compgen -W "gems did_you_mean rubyopt frozen-string-literal" -- "$cur"))
fi
# Include `ruby` completion results, if available
if [[ $(type -t __ruby) = function ]]; then
local cr=("${COMPREPLY[@]}")
__ruby "$@"
COMPREPLY+=("${cr[@]}")
fi
}
complete -F __jruby -o filenames -o bashdefault -o default jruby
# vim: ai ft=sh sw=4 sts=4 et