You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shell.completion.script 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //
  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. // This script is run each time a shell is created.
  20. // You can define here closures or variables that will be available
  21. // in each session.
  22. //
  23. __option_not_present = {
  24. res = true
  25. opts = $argv
  26. each $opts {
  27. arg = $it
  28. each ($.commandLine words) {
  29. if { ($it toString) equals ($arg toString) } {
  30. res = false
  31. }
  32. }
  33. }
  34. $res
  35. }
  36. __set_unset_arguments = {
  37. is_setopt = (($.commandLine words) get 0) equals "setopt"
  38. enums = ((__load_class 'org.jline.reader.LineReader$Option') enumConstants)
  39. candidates = new ArrayList
  40. each $enums {
  41. name = ${(GL)it/_/-}
  42. is_set = ($.reader isSet $it)
  43. neg = %(( if(is_setopt, is_set, not(is_set)) ))
  44. if { $neg } {
  45. name = "no-${name}"
  46. }
  47. if { not { (($.commandLine words) subList 1 ($.commandLine wordIndex)) contains $name } } {
  48. $candidates add (new org.jline.reader.Candidate $name $name (if { $neg } { "unset" } { "set" }) null null null true)
  49. }
  50. }
  51. $candidates
  52. }
  53. jlineReader = $.reader
  54. if { %(jlineReader != null) } {
  55. complete -c shell:complete -e
  56. complete -c shell:complete -d "Edit command specific completions"
  57. complete -c shell:complete -s c -l command --description "Command to add completion to" -n '__option_not_present -c --command' -a '$.commands'
  58. complete -c shell:complete -s s -l short-option --description "Posix-style option to complete" -n '__option_not_present -s --short-option'
  59. complete -c shell:complete -s l -l long-option --description "GNU-style option to complete" -n '__option_not_present -l --long-option'
  60. complete -c shell:complete -s a -l arguments --description "A list of possible arguments" -n '__option_not_present -a --argument'
  61. complete -c shell:complete -s d -l description --description "Description of this completions" -n '__option_not_present -d --description'
  62. complete -c shell:complete -s h -l help --description "Display help and exit" -n '__option_not_present -h --help'
  63. complete -c shell: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'
  64. complete -c shell:complete -s e -l erase --description "Remove completion" -n '__option_not_present -e --erase'
  65. complete -c shell:history -e
  66. complete -c shell:history -d "Show and manipulate command history"
  67. complete -c shell:history -l clear --description "Clear history" -n '__option_not_present --clear'
  68. complete -c shell:history -l save --description "Save history" -n '__option_not_present --save'
  69. complete -c shell:setopt -e
  70. complete -c shell:setopt -d "Set or view set shell options"
  71. complete -c shell:setopt -a '__set_unset_arguments'
  72. complete -c shell:unsetopt -e
  73. complete -c shell:unsetopt -d "Unset or view unset shell options"
  74. complete -c shell:unsetopt -a '__set_unset_arguments'
  75. complete -c shell:cat -e
  76. complete -c shell:cat -d "Concatenate and print files"
  77. complete -c shell:cat -s n "Number the output lines, starting at 1"
  78. complete -c shell:cat -a '__files'
  79. complete -c shell:pwd -e
  80. complete -c shell:pwd -d "Get current directory"
  81. complete -c shell:ls -e
  82. complete -c shell:ls -d "List files"
  83. complete -c shell:cd -e
  84. complete -c shell:cd -d "Change current directory"
  85. complete -c shell:cd -a 'wi = ($.commandLine wordIndex); if { %(wi==1) } { __directories } { [ ] }'
  86. complete -c shell:sleep -e
  87. complete -c shell:sleep -d "Pause execution for the specified amount of time"
  88. complete -c shell:echo -e
  89. complete -c shell:echo -d "Write arguments to the standard output"
  90. complete -c shell:echo -s n -d "No trailing new line"
  91. complete -c shell:grep -e
  92. complete -c shell:grep -d "File pattern searcher"
  93. # TODO
  94. complete -c shell:sort -e
  95. complete -c shell:sort -d "Sort lines of text files"
  96. # TODO
  97. complete -c shell:gosh -e
  98. complete -c shell:gosh -d "Execute script with arguments in a new session"
  99. # TODO
  100. complete -c shell:sh -e
  101. complete -c shell:sh -d "Execute script with arguments in a new session"
  102. # TODO
  103. complete -c shell:source -e
  104. complete -c shell:source -d "Execute script with arguments"
  105. # TODO
  106. # TODO: format getopt new set tac type addcommand removeCommand eval
  107. complete -c shell:break -e
  108. complete -c shell:break -d "Break from a loop"
  109. complete -c shell:continue -e
  110. complete -c shell:continue -d "Continue to next iteration in a loop"
  111. complete -c shell:each -e
  112. complete -c shell:each -d "Loop and execute script on the specified elements"
  113. complete -c shell:if -e
  114. complete -c shell:if -d "Conditionaly execute a script"
  115. complete -c shell:new -e
  116. complete -c shell:new -d "Creates new instance of the given java class"
  117. complete -c shell:not -e
  118. complete -c shell:not -d "Negates the result of a script"
  119. complete -c shell:throw -e
  120. complete -c shell:throw -d "Throws an exception"
  121. complete -c shell:try -e
  122. complete -c shell:try -d "Try executing a script and catch any exception"
  123. complete -c shell:until -e
  124. complete -c shell:until -d "Loop and execute script until a condition is satisfied"
  125. complete -c shell:while -e
  126. complete -c shell:while -d "Loop and execute script while a condition is satisfied"
  127. complete -c shell:less -e
  128. complete -c shell:less -d "File pager"
  129. complete -c shell:less -s e -l quit-at-eof --description "Exit on second EOF"
  130. complete -c shell:less -s E -l QUIT-AT-EOF --description "Exit on EOF"
  131. complete -c shell:less -s q -l quiet -l silent --description "Silent mode"
  132. complete -c shell:less -s Q -l QUIET -l SILENT --description "Completely silent"
  133. complete -c shell:less -s S -l chop-long-lines --description "Do not fold long lines"
  134. complete -c shell:less -s i -l ignore-case --description "Search ignores lowercase case"
  135. complete -c shell:less -s I -l IGNORE-CASE --description "Search ignores all case"
  136. complete -c shell:less -s x -l tabs --description "Set tab stops"
  137. complete -c shell:less -s N -l LINE-NUMBERS --description "Display line number for each line"
  138. complete -c shell:less -a '__files'
  139. complete -c shell:nano -e
  140. complete -c shell:nano -d "File editor"
  141. complete -c shell:nano -a '__files'
  142. complete -c shell:keymap -e
  143. complete -c shell:keymap -d "Manipulate keymaps"
  144. complete -c shell:keymap -s N --description "Create a new keymap" -n '__option_not_present -N -d -D -l -r -s -A'
  145. complete -c shell:keymap -s d --description "Delete existing keymaps and reset to default state" -n '__option_not_present -N -d -D -l -r -s -A'
  146. complete -c shell:keymap -s D --description "Delete named keymaps" -n '__option_not_present -N -d -D -l -r -s -A'
  147. complete -c shell:keymap -s l --description "List existing keymap names" -n '__option_not_present -N -d -D -l -r -s -A'
  148. complete -c shell:keymap -s r --description "Unbind specified in-strings" -n '__option_not_present -N -d -D -l -r -s -A'
  149. complete -c shell:keymap -s s --description "Bind each in-string to each out-string" -n '__option_not_present -N -d -D -l -r -s -A'
  150. complete -c shell:keymap -s A --description "Create alias to keymap" -n '__option_not_present -N -d -D -l -r -s -A'
  151. complete -c shell:keymap -s e --description "Select emacs keymap and bind it to main" -n '__option_not_present -e -a -v -M'
  152. complete -c shell:keymap -s v --description "Select viins keymap and bind it to main" -n '__option_not_present -e -a -v -M'
  153. complete -c shell:keymap -s a --description "Select vicmd keymap" -n '__option_not_present -e -a -v -M'
  154. complete -c shell:keymap -s M --description "Specify keymap to select" -n '__option_not_present -e -a -v -M' -a '(keymap -l | tac) split " "'
  155. complete -c shell:keymap -s R --description "Interpret in-strings as ranges"
  156. complete -c shell:keymap -s p --description "List bindings which have given key sequence as a a prefix"
  157. complete -c shell:keymap -s L --description "Output in form of keymap commands"
  158. complete -c shell:widget -e
  159. complete -c shell:widget -d "Manipulate widgets"
  160. complete -c shell:widget -s N --description "Create a new widget" -n '__option_not_present -N -A -D -U -l'
  161. complete -c shell:widget -s A --description "Create alias to widget" -n '__option_not_present -N -A -D -U -l'
  162. complete -c shell:widget -s D --description "Delete widgets" -n '__option_not_present -N -A -D -U -l'
  163. complete -c shell:widget -s U --description "Push characters to the stack" -n '__option_not_present -N -A -D -U -l'
  164. complete -c shell:widget -s l --description "List user-defined widgets" -n '__option_not_present -N -A -D -U -l'
  165. complete -c shell:widget -s a --description "With -l, list all widgets" -n '__option_not_present -l'
  166. complete -c shell:bg -e
  167. complete -c shell:bg -d "Put job in background"
  168. complete -c shell:fg -e
  169. complete -c shell:fg -d "Put job in foreground"
  170. complete -c shell:jobs -e
  171. complete -c shell:jobs -d "List jobs"
  172. complete -c shell:clear -e
  173. complete -c shell:clear -d "Clear screen"
  174. complete -c shell:head -e
  175. complete -c shell:head -d "Displays first lines of file"
  176. complete -c shell:head -s n -l lines --description "Print line counts"
  177. complete -c shell:head -s c -l bytes --description "Print byte counts"
  178. complete -c shell:head -a '__files'
  179. complete -c shell:tail -e
  180. complete -c shell:tail -d "Displays last lines of file"
  181. complete -c shell:tail -s q -l quiet --description "Suppress headers when printing multiple sources"
  182. complete -c shell:tail -s f -l follow --description "Do not stop at end of file"
  183. complete -c shell:tail -s F -l FOLLOW --description "Follow and check for file renaming or rotation"
  184. complete -c shell:tail -s n -l lines --description "Number of lines to print"
  185. complete -c shell:tail -s c -l bytes --description "Number of bytes to print"
  186. complete -c shell:tail -a '__files'
  187. complete -c shell:date -e
  188. complete -c shell:date -d "Display date and time"
  189. complete -c shell:date -s u --description "Use UTC"
  190. complete -c shell:date -s r --description "Print the date represented by 'seconds' since January 1, 1970"
  191. complete -c shell:date -s v --description "Adjust date"
  192. complete -c shell:date -s f --description "Use 'input_fmt' to parse 'new_date'"
  193. complete -c shell:wc -e
  194. complete -c shell:wc -d "Word, line, character, and byte count"
  195. complete -c shell:wc -s n -l lines --description "Print line count"
  196. complete -c shell:wc -s c -l bytes --description "Print byte count"
  197. complete -c shell:wc -s m -l chars --description "Print character count"
  198. complete -c shell:wc -s w -l words --description "Print word count"
  199. complete -c shell:wc -a '__files'
  200. __get_scr_components = {
  201. list = [ ]
  202. scrref = ($.context getServiceReference org.osgi.service.component.runtime.ServiceComponentRuntime)
  203. scr = ($.context getService $scrref)
  204. each ($scr getComponentDescriptionDTOs ($.context bundles)) {
  205. $list add ((($it getClass) getField "name") get $it)
  206. }
  207. $.context ungetService $scrref
  208. $list
  209. }
  210. complete -c scr:config -e
  211. complete -c scr:config -d "Show the current SCR configuration"
  212. complete -c scr:disable -e
  213. complete -c scr:disable -d "Disable an enabled component"
  214. complete -c scr:disable -a '__get_scr_components'
  215. complete -c scr:enable -e
  216. complete -c scr:enable -d "Enable an disabled component"
  217. complete -c scr:enable -a '__get_scr_components'
  218. complete -c scr:info -e
  219. complete -c scr:info -d "Dump information of a component or component configuration"
  220. complete -c scr:info -a '__get_scr_components'
  221. complete -c scr:list -e
  222. complete -c scr:list -d "List component configurations of a specific bundle"
  223. }