blob: 72dcfb4ae23758e7e84bf8ffb706eae9b5ac7f7f [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.
Guillaume Nodetd19550f2016-03-21 16:59:10 +000041 .Gogo.format = false
Guillaume Nodet97431032016-03-21 16:53:06 +000042
43 ## disable printing the formatted result of a command into pipelines
44 #.Format.Pipe = false
45
46 # set prompt
47 prompt = 'g! '
Guillaume Nodetecbddee2016-03-21 16:57:22 +000048 \#rprompt = { (new java.text.SimpleDateFormat \'$'\u001B\\[90m'\'HH:mm:ss) format (new Date) }
Guillaume Nodete8e41c52016-03-21 16:55:25 +000049 # could also be written
Guillaume Nodetd19550f2016-03-21 16:59:10 +000050 # \#rprompt = { ${(qq)$(date +$'\u001B\[90m%T')} }
Guillaume Nodet97431032016-03-21 16:53:06 +000051
52
53 __option_not_present = {
54 res = true
Guillaume Nodetd19550f2016-03-21 16:59:10 +000055 opts = $argv
Guillaume Nodet97431032016-03-21 16:53:06 +000056 each $opts {
57 arg = $it
58 each ($.commandLine words) {
Guillaume Nodetd19550f2016-03-21 16:59:10 +000059 if { ($it toString) equals ($arg toString) } {
Guillaume Nodet97431032016-03-21 16:53:06 +000060 res = false
61 }
62 }
63 }
64 $res
65 }
66
67 __load_class = {
68 (($.reader class) classLoader) loadClass $1
69 }
70
Guillaume Nodet97431032016-03-21 16:53:06 +000071 __set_unset_arguments = {
72 is_setopt = (($.commandLine words) get 0) equals "setopt"
Guillaume Nodetd19550f2016-03-21 16:59:10 +000073 enums = ((__load_class 'org.jline.reader.LineReader$Option') enumConstants)
Guillaume Nodet97431032016-03-21 16:53:06 +000074 candidates = new ArrayList
Guillaume Nodetd19550f2016-03-21 16:59:10 +000075 each $enums {
76 name = ${(GL)it/_/-}
Guillaume Nodet97431032016-03-21 16:53:06 +000077 is_set = ($.reader isSet $it)
78 neg = %(( if(is_setopt, is_set, not(is_set)) ))
79 if { $neg } {
80 name = "no-${name}"
81 }
82 if { not { (($.commandLine words) subList 1 ($.commandLine wordIndex)) contains $name } } {
Guillaume Nodetd19550f2016-03-21 16:59:10 +000083 $candidates add (new org.jline.reader.Candidate $name $name (if { $neg } { "unset" } { "set" }) null null null true)
Guillaume Nodet97431032016-03-21 16:53:06 +000084 }
85 }
86 $candidates
87 }
88
89 setopt pad-prompts
90 setopt group
91
92 complete -c gogo:complete -e
93 complete -c gogo:complete -d "Edit command specific completions"
94 complete -c gogo:complete -s c -l command --description "Command to add completion to" -n '__option_not_present -c --command' -a '$.commands'
95 complete -c gogo:complete -s s -l short-option --description "Posix-style option to complete" -n '__option_not_present -s --short-option'
96 complete -c gogo:complete -s l -l long-option --description "GNU-style option to complete" -n '__option_not_present -l --long-option'
97 complete -c gogo:complete -s a -l arguments --description "A list of possible arguments" -n '__option_not_present -a --argument'
98 complete -c gogo:complete -s d -l description --description "Description of this completions" -n '__option_not_present -d --description'
99 complete -c gogo:complete -s h -l help --description "Display help and exit" -n '__option_not_present -h --help'
100 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'
101 complete -c gogo:complete -s e -l erase --description "Remove completion" -n '__option_not_present -e --erase'
102
103 complete -c gogo:history -e
104 complete -c gogo:history -d "Show and manipulate command history"
105 complete -c gogo:history -l clear --description "Clear history" -n '__option_not_present --clear'
106 complete -c gogo:history -l save --description "Save history" -n '__option_not_present --save'
107
108 complete -c gogo:setopt -e
109 complete -c gogo:setopt -d "Set or view set shell options"
110 complete -c gogo:setopt -a '__set_unset_arguments'
111
112 complete -c gogo:unsetopt -e
113 complete -c gogo:unsetopt -d "Unset or view unset shell options"
114 complete -c gogo:unsetopt -a '__set_unset_arguments'
115
116 complete -c gogo:cat -e
117 complete -c gogo:cat -d "Concatenate and print files"
118 complete -c gogo:cat -s n "Number the output lines, starting at 1"
119 complete -c gogo:cat -a '__files'
120
121 complete -c gogo:pwd -e
122 complete -c gogo:pwd -d "Get current directory"
123
124 complete -c gogo:ls -e
125 complete -c gogo:ls -d "List files"
126
127 complete -c gogo:cd -e
128 complete -c gogo:cd -d "Change current directory"
129 complete -c gogo:cd -a '__directories'
130
131 complete -c gogo:sleep -e
132 complete -c gogo:sleep -d "Pause execution for the specified amount of time"
133
134 complete -c gogo:echo -e
135 complete -c gogo:echo -d "Write arguments to the standard output"
136 complete -c gogo:echo -s n -d "No trailing new line"
137
138 complete -c gogo:grep -e
139 complete -c gogo:grep -d "File pattern searcher"
140 # TODO
141
142 complete -c gogo:sort -e
143 complete -c gogo:sort -d "Sort lines of text files"
144 # TODO
145
146 complete -c gogo:gosh -e
147 complete -c gogo:gosh -d "Execute script with arguments in a new session"
148 # TODO
149
150 complete -c gogo:sh -e
151 complete -c gogo:sh -d "Execute script with arguments in a new session"
152 # TODO
153
154 complete -c gogo:source -e
155 complete -c gogo:source -d "Execute script with arguments"
156 # TODO
157
158 # TODO: format getopt new set tac type addcommand removeCommand eval
159
160 complete -c gogo:each -e
161 complete -c gogo:each -d "Loop and execute script on the specified elements"
162
163 complete -c gogo:if -e
164 complete -c gogo:if -d "Conditionaly execute a script"
165
166 complete -c gogo:not -e
167 complete -c gogo:not -d "Negates the result of a script"
168
169 complete -c gogo:throw -e
170 complete -c gogo:throw -d "Throws an exception"
171
172 complete -c gogo:try -e
173 complete -c gogo:try -d "Try executing a script and catch any exception"
174
175 complete -c gogo:until -e
176 complete -c gogo:until -d "Loop and execute script until a condition is satisfied"
177
178 complete -c gogo:while -e
179 complete -c gogo:while -d "Loop and execute script while a condition is satisfied"
180
181 complete -c gogo:less -e
182 complete -c gogo:less -d "File pager"
183 complete -c gogo:less -s e -l quit-at-eof --description "Exit on second EOF"
184 complete -c gogo:less -s E -l QUIT-AT-EOF --description "Exit on EOF"
185 complete -c gogo:less -s q -l quiet -l silent --description "Silent mode"
186 complete -c gogo:less -s Q -l QUIET -l SILENT --description "Completely silent"
187 complete -c gogo:less -s S -l chop-long-lines --description "Do not fold long lines"
188 complete -c gogo:less -s i -l ignore-case --description "Search ignores lowercase case"
189 complete -c gogo:less -s I -l IGNORE-CASE --description "Search ignores all case"
190 complete -c gogo:less -s x -l tabs --description "Set tab stops"
191 complete -c gogo:less -s N -l LINE-NUMBERS --description "Display line number for each line"
192 complete -c gogo:less -a '__files'
193
194 complete -c gogo:nano -e
195 complete -c gogo:nano -d "File editor"
196 complete -c gogo:nano -a '__files'
197
198 complete -c gogo:keymap -e
199 complete -c gogo:keymap -d "Manipulate keymaps"
200 complete -c gogo:keymap -s N --description "Create a new keymap" -n '__option_not_present -N -d -D -l -r -s -A'
201 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'
202 complete -c gogo:keymap -s D --description "Delete named keymaps" -n '__option_not_present -N -d -D -l -r -s -A'
203 complete -c gogo:keymap -s l --description "List existing keymap names" -n '__option_not_present -N -d -D -l -r -s -A'
204 complete -c gogo:keymap -s r --description "Unbind specified in-strings" -n '__option_not_present -N -d -D -l -r -s -A'
205 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'
206 complete -c gogo:keymap -s A --description "Create alias to keymap" -n '__option_not_present -N -d -D -l -r -s -A'
207 complete -c gogo:keymap -s e --description "Select emacs keymap and bind it to main" -n '__option_not_present -e -a -v -M'
208 complete -c gogo:keymap -s v --description "Select viins keymap and bind it to main" -n '__option_not_present -e -a -v -M'
209 complete -c gogo:keymap -s a --description "Select vicmd keymap" -n '__option_not_present -e -a -v -M'
210 complete -c gogo:keymap -s M --description "Specify keymap to select" -n '__option_not_present -e -a -v -M' -a '(keymap -l | tac) split " "'
211 complete -c gogo:keymap -s R --description "Interpret in-strings as ranges"
212 complete -c gogo:keymap -s p --description "List bindings which have given key sequence as a a prefix"
213 complete -c gogo:keymap -s L --description "Output in form of keymap commands"
214
215 complete -c gogo:widget -e
216 complete -c gogo:widget -d "Manipulate widgets"
217 complete -c gogo:widget -s N --description "Create a new widget" -n '__option_not_present -N -A -D -U -l'
218 complete -c gogo:widget -s A --description "Create alias to widget" -n '__option_not_present -N -A -D -U -l'
219 complete -c gogo:widget -s D --description "Delete widgets" -n '__option_not_present -N -A -D -U -l'
220 complete -c gogo:widget -s U --description "Push characters to the stack" -n '__option_not_present -N -A -D -U -l'
221 complete -c gogo:widget -s l --description "List user-defined widgets" -n '__option_not_present -N -A -D -U -l'
222 complete -c gogo:widget -s a --description "With -l, list all widgets" -n '__option_not_present -l'
223
224 complete -c gogo:telnetd -e
225 complete -c gogo:telnetd -d "Telnet daemon"
226 complete -c gogo:telnetd -s i -l ip --description "Listening IP interface" -n '__option_not_present -i --ip'
227 complete -c gogo:telnetd -s p -l port --description "Listening IP port" -n '__option_not_present -p --port'
228 complete -c gogo:telnetd -a '[start stop status]'
229
230 complete -c gogo:sshd -e
231 complete -c gogo:sshd -d "SSH daemon"
232 complete -c gogo:sshd -s i -l ip --description "Listening IP interface" -n '__option_not_present -i --ip'
233 complete -c gogo:sshd -s p -l port --description "Listening IP port" -n '__option_not_present -p --port'
234 complete -c gogo:sshd -a '[start stop status]'
235
236 complete -c gogo:tmux -e
237 complete -c gogo:tmux -d "Terminal multiplexer"
238
Guillaume Nodet3f1fca52016-03-21 16:56:04 +0000239 complete -c gogo:bg -e
240 complete -c gogo:bg -d "Put job in background"
241
242 complete -c gogo:fg -e
243 complete -c gogo:fg -d "Put job in foreground"
244
245 complete -c gogo:jobs -e
246 complete -c gogo:jobs -d "List jobs"
247
Guillaume Nodetd19550f2016-03-21 16:59:10 +0000248 complete -c gogo:clear -e
249 complete -c gogo:clear -d "Clear screen"
250
251 complete -c gogo:head -e
252 complete -c gogo:head -d "Displays first lines of file"
253 complete -c gogo:head -s n -l lines --description "Print line counts"
254 complete -c gogo:head -s c -l bytes --description "Print byte counts"
255 complete -c gogo:head -a '__files'
256
257 complete -c gogo:tail -e
258 complete -c gogo:tail -d "Displays last lines of file"
259 complete -c gogo:tail -s q -l quiet --description "Suppress headers when printing multiple sources"
260 complete -c gogo:tail -s f -l follow --description "Do not stop at end of file"
261 complete -c gogo:tail -s F -l FOLLOW --description "Follow and check for file renaming or rotation"
262 complete -c gogo:tail -s n -l lines --description "Number of lines to print"
263 complete -c gogo:tail -s c -l bytes --description "Number of bytes to print"
264 complete -c gogo:tail -a '__files'
265
266 complete -c gogo:date -e
267 complete -c gogo:date -d "Display date and time"
268 complete -c gogo:date -s u --description "Use UTC"
269 complete -c gogo:date -s r --description "Print the date represented by 'seconds' since January 1, 1970"
270 complete -c gogo:date -s v --description "Adjust date"
271 complete -c gogo:date -s f --description "Use 'input_fmt' to parse 'new_date'"
272
273 complete -c gogo:wc -e
274 complete -c gogo:wc -d "Word, line, character, and byte count"
275 complete -c gogo:wc -s n -l lines --description "Print line count"
276 complete -c gogo:wc -s c -l bytes --description "Print byte count"
277 complete -c gogo:wc -s m -l chars --description "Print character count"
278 complete -c gogo:wc -s w -l words --description "Print word count"
279 complete -c gogo:wc -a '__files'
280
Guillaume Nodet97431032016-03-21 16:53:06 +0000281 # print welcome message
282 cat ($0 resolve motd)
283} {
284 echo "$0: ERROR: $exception"
285}
286
287# end