blob: 068f5d15c5cd9b0227ef14d0dbe6c75bc687d64c [file] [log] [blame]
Guillaume Nodet97431032016-03-21 16:53:06 +00001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19# default gosh_profile
20# only read if etc/gosh_profile doesn't exist relative to the System property
21# gosh.home or failing that the current directory.
22
23# catch all exceptions from this script to avoid it aborting startup
24try {
25
26 # ensure gogo commands are found first
Guillaume Nodete8e41c52016-03-21 16:55:25 +000027 SCOPE = 'gogo:*'
Guillaume Nodet97431032016-03-21 16:53:06 +000028
29 # add methods on BundleContext object as commands
30 addcommand context ${.context}
31
32 # add methods on System object as commands
33 #addcommand system (((${.context} getClass) getClassLoader) loadClass java.lang.System)
34
35 # alias to print full stack trace
36 e = { $exception printStackTrace }
37
38 ## disable console auto-formatting of each result
39 # you will then need to explicitly use the 'format' command
40 # to print the result of commands that don't write to stdout.
41 #.Gogo.format = false
42
43 ## disable printing the formatted result of a command into pipelines
44 #.Format.Pipe = false
45
46 # set prompt
47 prompt = 'g! '
Guillaume Nodete8e41c52016-03-21 16:55:25 +000048 \#rprompt = { (new java.text.SimpleDateFormat \'\u001B\[90m\'HH:mm:ss) format (new Date) }
49 # could also be written
50 # rprompt = { date +\u001B\\\[90m\%T }
Guillaume Nodet97431032016-03-21 16:53:06 +000051
52
53 __option_not_present = {
54 res = true
55 opts = ([ $args ] get 0)
56 each $opts {
57 arg = $it
58 each ($.commandLine words) {
59 if { ($it toString) contentEquals ($arg toString) } {
60 res = false
61 }
62 }
63 }
64 $res
65 }
66
67 __load_class = {
68 (($.reader class) classLoader) loadClass $1
69 }
70
71 __as_list = {
72 (__load_class java.util.Arrays) asList $1
73 }
74
75 __set_unset_arguments = {
76 is_setopt = (($.commandLine words) get 0) equals "setopt"
77 enums = ((__load_class 'org.jline.ConsoleReader$Option') enumConstants)
78 candidates = new ArrayList
79 each (__as_list $enums) {
80 name = ((($it name) toLowerCase) replace '_' '-')
81 is_set = ($.reader isSet $it)
82 neg = %(( if(is_setopt, is_set, not(is_set)) ))
83 if { $neg } {
84 name = "no-${name}"
85 }
86 if { not { (($.commandLine words) subList 1 ($.commandLine wordIndex)) contains $name } } {
87 $candidates add (new org.jline.Candidate $name $name (if { $neg } { "unset" } { "set" }) null null null true)
88 }
89 }
90 $candidates
91 }
92
93 setopt pad-prompts
94 setopt group
95
96 complete -c gogo:complete -e
97 complete -c gogo:complete -d "Edit command specific completions"
98 complete -c gogo:complete -s c -l command --description "Command to add completion to" -n '__option_not_present -c --command' -a '$.commands'
99 complete -c gogo:complete -s s -l short-option --description "Posix-style option to complete" -n '__option_not_present -s --short-option'
100 complete -c gogo:complete -s l -l long-option --description "GNU-style option to complete" -n '__option_not_present -l --long-option'
101 complete -c gogo:complete -s a -l arguments --description "A list of possible arguments" -n '__option_not_present -a --argument'
102 complete -c gogo:complete -s d -l description --description "Description of this completions" -n '__option_not_present -d --description'
103 complete -c gogo:complete -s h -l help --description "Display help and exit" -n '__option_not_present -h --help'
104 complete -c gogo:complete -s n -l condition --description "The completion should only be used if the specified command has a zero exit status" -n '__option_not_present -n --condition'
105 complete -c gogo:complete -s e -l erase --description "Remove completion" -n '__option_not_present -e --erase'
106
107 complete -c gogo:history -e
108 complete -c gogo:history -d "Show and manipulate command history"
109 complete -c gogo:history -l clear --description "Clear history" -n '__option_not_present --clear'
110 complete -c gogo:history -l save --description "Save history" -n '__option_not_present --save'
111
112 complete -c gogo:setopt -e
113 complete -c gogo:setopt -d "Set or view set shell options"
114 complete -c gogo:setopt -a '__set_unset_arguments'
115
116 complete -c gogo:unsetopt -e
117 complete -c gogo:unsetopt -d "Unset or view unset shell options"
118 complete -c gogo:unsetopt -a '__set_unset_arguments'
119
120 complete -c gogo:cat -e
121 complete -c gogo:cat -d "Concatenate and print files"
122 complete -c gogo:cat -s n "Number the output lines, starting at 1"
123 complete -c gogo:cat -a '__files'
124
125 complete -c gogo:pwd -e
126 complete -c gogo:pwd -d "Get current directory"
127
128 complete -c gogo:ls -e
129 complete -c gogo:ls -d "List files"
130
131 complete -c gogo:cd -e
132 complete -c gogo:cd -d "Change current directory"
133 complete -c gogo:cd -a '__directories'
134
135 complete -c gogo:sleep -e
136 complete -c gogo:sleep -d "Pause execution for the specified amount of time"
137
138 complete -c gogo:echo -e
139 complete -c gogo:echo -d "Write arguments to the standard output"
140 complete -c gogo:echo -s n -d "No trailing new line"
141
142 complete -c gogo:grep -e
143 complete -c gogo:grep -d "File pattern searcher"
144 # TODO
145
146 complete -c gogo:sort -e
147 complete -c gogo:sort -d "Sort lines of text files"
148 # TODO
149
150 complete -c gogo:gosh -e
151 complete -c gogo:gosh -d "Execute script with arguments in a new session"
152 # TODO
153
154 complete -c gogo:sh -e
155 complete -c gogo:sh -d "Execute script with arguments in a new session"
156 # TODO
157
158 complete -c gogo:source -e
159 complete -c gogo:source -d "Execute script with arguments"
160 # TODO
161
162 # TODO: format getopt new set tac type addcommand removeCommand eval
163
164 complete -c gogo:each -e
165 complete -c gogo:each -d "Loop and execute script on the specified elements"
166
167 complete -c gogo:if -e
168 complete -c gogo:if -d "Conditionaly execute a script"
169
170 complete -c gogo:not -e
171 complete -c gogo:not -d "Negates the result of a script"
172
173 complete -c gogo:throw -e
174 complete -c gogo:throw -d "Throws an exception"
175
176 complete -c gogo:try -e
177 complete -c gogo:try -d "Try executing a script and catch any exception"
178
179 complete -c gogo:until -e
180 complete -c gogo:until -d "Loop and execute script until a condition is satisfied"
181
182 complete -c gogo:while -e
183 complete -c gogo:while -d "Loop and execute script while a condition is satisfied"
184
185 complete -c gogo:less -e
186 complete -c gogo:less -d "File pager"
187 complete -c gogo:less -s e -l quit-at-eof --description "Exit on second EOF"
188 complete -c gogo:less -s E -l QUIT-AT-EOF --description "Exit on EOF"
189 complete -c gogo:less -s q -l quiet -l silent --description "Silent mode"
190 complete -c gogo:less -s Q -l QUIET -l SILENT --description "Completely silent"
191 complete -c gogo:less -s S -l chop-long-lines --description "Do not fold long lines"
192 complete -c gogo:less -s i -l ignore-case --description "Search ignores lowercase case"
193 complete -c gogo:less -s I -l IGNORE-CASE --description "Search ignores all case"
194 complete -c gogo:less -s x -l tabs --description "Set tab stops"
195 complete -c gogo:less -s N -l LINE-NUMBERS --description "Display line number for each line"
196 complete -c gogo:less -a '__files'
197
198 complete -c gogo:nano -e
199 complete -c gogo:nano -d "File editor"
200 complete -c gogo:nano -a '__files'
201
202 complete -c gogo:keymap -e
203 complete -c gogo:keymap -d "Manipulate keymaps"
204 complete -c gogo:keymap -s N --description "Create a new keymap" -n '__option_not_present -N -d -D -l -r -s -A'
205 complete -c gogo:keymap -s d --description "Delete existing keymaps and reset to default state" -n '__option_not_present -N -d -D -l -r -s -A'
206 complete -c gogo:keymap -s D --description "Delete named keymaps" -n '__option_not_present -N -d -D -l -r -s -A'
207 complete -c gogo:keymap -s l --description "List existing keymap names" -n '__option_not_present -N -d -D -l -r -s -A'
208 complete -c gogo:keymap -s r --description "Unbind specified in-strings" -n '__option_not_present -N -d -D -l -r -s -A'
209 complete -c gogo:keymap -s s --description "Bind each in-string to each out-string" -n '__option_not_present -N -d -D -l -r -s -A'
210 complete -c gogo:keymap -s A --description "Create alias to keymap" -n '__option_not_present -N -d -D -l -r -s -A'
211 complete -c gogo:keymap -s e --description "Select emacs keymap and bind it to main" -n '__option_not_present -e -a -v -M'
212 complete -c gogo:keymap -s v --description "Select viins keymap and bind it to main" -n '__option_not_present -e -a -v -M'
213 complete -c gogo:keymap -s a --description "Select vicmd keymap" -n '__option_not_present -e -a -v -M'
214 complete -c gogo:keymap -s M --description "Specify keymap to select" -n '__option_not_present -e -a -v -M' -a '(keymap -l | tac) split " "'
215 complete -c gogo:keymap -s R --description "Interpret in-strings as ranges"
216 complete -c gogo:keymap -s p --description "List bindings which have given key sequence as a a prefix"
217 complete -c gogo:keymap -s L --description "Output in form of keymap commands"
218
219 complete -c gogo:widget -e
220 complete -c gogo:widget -d "Manipulate widgets"
221 complete -c gogo:widget -s N --description "Create a new widget" -n '__option_not_present -N -A -D -U -l'
222 complete -c gogo:widget -s A --description "Create alias to widget" -n '__option_not_present -N -A -D -U -l'
223 complete -c gogo:widget -s D --description "Delete widgets" -n '__option_not_present -N -A -D -U -l'
224 complete -c gogo:widget -s U --description "Push characters to the stack" -n '__option_not_present -N -A -D -U -l'
225 complete -c gogo:widget -s l --description "List user-defined widgets" -n '__option_not_present -N -A -D -U -l'
226 complete -c gogo:widget -s a --description "With -l, list all widgets" -n '__option_not_present -l'
227
228 complete -c gogo:telnetd -e
229 complete -c gogo:telnetd -d "Telnet daemon"
230 complete -c gogo:telnetd -s i -l ip --description "Listening IP interface" -n '__option_not_present -i --ip'
231 complete -c gogo:telnetd -s p -l port --description "Listening IP port" -n '__option_not_present -p --port'
232 complete -c gogo:telnetd -a '[start stop status]'
233
234 complete -c gogo:sshd -e
235 complete -c gogo:sshd -d "SSH daemon"
236 complete -c gogo:sshd -s i -l ip --description "Listening IP interface" -n '__option_not_present -i --ip'
237 complete -c gogo:sshd -s p -l port --description "Listening IP port" -n '__option_not_present -p --port'
238 complete -c gogo:sshd -a '[start stop status]'
239
240 complete -c gogo:tmux -e
241 complete -c gogo:tmux -d "Terminal multiplexer"
242
243 # print welcome message
244 cat ($0 resolve motd)
245} {
246 echo "$0: ERROR: $exception"
247}
248
249# end