My personal dotfiles
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.

_android 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. #compdef android
  2. # ------------------------------------------------------------------------------
  3. # Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are met:
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # * Neither the name of the zsh-users nor the
  14. # names of its contributors may be used to endorse or promote products
  15. # derived from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
  21. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # ------------------------------------------------------------------------------
  28. # Description
  29. # -----------
  30. #
  31. # Completion script for the android command (Revision 12)
  32. # (http://developer.android.com/guide/developing/tools/android.html).
  33. #
  34. # ------------------------------------------------------------------------------
  35. # Authors
  36. # -------
  37. #
  38. # * Julien Nicoulaud <julien.nicoulaud@gmail.com>
  39. #
  40. # ------------------------------------------------------------------------------
  41. _android() {
  42. typeset -A opt_args
  43. local context state line curcontext="$curcontext"
  44. local ret=1
  45. _arguments -C -A "-*" \
  46. '(- : *)'{-h,--help}'[get help on a specific command]:command:_android_cmds' \
  47. '(-s --silent -v --verbose)'{-v,--verbose}'[verbose mode: errors, warnings and informational messages are printed]' \
  48. '(-v --verbose -s --silent)'{-s,--silent}'[silent mode: only errors are printed out]' \
  49. '1: :_android_cmds' \
  50. '*::arg:->args' \
  51. && ret=0
  52. case "$state" in
  53. (args)
  54. curcontext="${curcontext%:*:*}:android-cmd-$words[1]:"
  55. case $words[1] in
  56. (list)
  57. _arguments -C \
  58. '1: :_android_list_entities' \
  59. '*::list-arg:->list-args' \
  60. && ret=0
  61. case "$state" in
  62. (list-args)
  63. case $words[1] in
  64. (avd|target)
  65. _arguments \
  66. '(-0 --null)'{-0,--null}'[terminate lines with \0 instead of \n (e.g. for xargs -0)]' \
  67. '(-c --compact)'{-c,--compact}'[compact output (suitable for scripts)]' \
  68. && ret=0
  69. ;;
  70. (sdk)
  71. _arguments \
  72. '(-o --obsolete)'{-o,--obsolete}'[install obsolete packages]' \
  73. '--proxy-host[HTTP/HTTPS proxy host (overrides settings if defined)]:proxy host:_hosts' \
  74. '--proxy-port[HTTP/HTTPS proxy port (overrides settings if defined)]:proxy port number' \
  75. '(-s --no-https)'{-s,--no-https}'[use HTTP instead of HTTPS (the default) for downloads]' \
  76. '(-u --no-ui)'{-u,--no-ui}'[display list result on console (no GUI)]' \
  77. && ret=0
  78. ;;
  79. esac
  80. ;;
  81. esac
  82. ;;
  83. (create)
  84. _arguments -C \
  85. '1: :_android_create_entities' \
  86. '*::create-arg:->create-args' \
  87. && ret=0
  88. case "$state" in
  89. (create-args)
  90. case $words[1] in
  91. (avd)
  92. _arguments \
  93. '(-c --sdcard)'{-c,--sdcard}'[path to a shared SD card image, or size of a new sdcard for the new AVD]:SD card image or size:_files -g "*.img"' \
  94. '(-n --name)'{-n,--name}'[name of the new AVD]:name' \
  95. '(-a --snapshot)'{-a,--snapshot}'[place a snapshots file in the AVD, to enable persistence]' \
  96. '(-p --path)'{-p,--path}'[directory where the new AVD will be created]: :_files -/' \
  97. '(-f --force)'{-f,--force}'[forces creation (overwrites an existing AVD)]' \
  98. '(-s --skin)'{-s,--skin}'[skin for the new AVD]:skin' \
  99. '(-t --target)'{-t,--target}'[target ID of the new AVD]: :_android_targets' \
  100. && ret=0
  101. ;;
  102. (project)
  103. _arguments \
  104. '(-n --name)'{-n,--name}'[project name]:project name' \
  105. '(-p --path)'{-p,--path}'[the new project'\''s directory]: :_files -/' \
  106. '(-k --package)'{-k,--package}'[Android package name for the application]:package name' \
  107. '(-a --activity)'{-a,--activity}'[name of the default Activity that is created]:activity name' \
  108. '(-t --target)'{-t,--target}'[target ID of the new project]: :_android_targets' \
  109. && ret=0
  110. ;;
  111. (test-project)
  112. _arguments \
  113. '(-n --name)'{-n,--name}'[project name]:project name' \
  114. '(-p --path)'{-p,--path}'[the new project'\''s directory]: :_files -/' \
  115. '(-m --main)'{-m,--main}'[path to directory of the app under test, relative to the test project directory]:path' \
  116. && ret=0
  117. ;;
  118. (lib-project)
  119. _arguments \
  120. '(-n --name)'{-n,--name}'[project name]:project name' \
  121. '(-p --path)'{-p,--path}'[the new project'\''s directory]: :_files -/' \
  122. '(-k --package)'{-k,--package}'[Android package name for the application]:package name' \
  123. '(-t --target)'{-t,--target}'[target ID of the new project]: :_android_targets' \
  124. && ret=0
  125. ;;
  126. esac
  127. ;;
  128. esac
  129. ;;
  130. (update)
  131. _arguments -C \
  132. '1: :_android_update_entities' \
  133. '*::update-arg:->update-args' \
  134. && ret=0
  135. case "$state" in
  136. (update-args)
  137. case $words[1] in
  138. (avd)
  139. _arguments \
  140. '(-n --name)'{-n,--name}'[name of the AVD to update]: :_android_avd_names' \
  141. && ret=0
  142. ;;
  143. (project)
  144. _arguments \
  145. '(-l --library)'{-l,--library}'[directory of an Android library to add, relative to this project'\''s directory]: :_files -/' \
  146. '(-p --path)'{-p,--path}'[the project'\''s directory]: :_files -/' \
  147. '(-n --name)'{-n,--name}'[project name]:name' \
  148. '(-t --target)'{-t,--target}'[target ID to set for the project]: :_android_targets' \
  149. '(-s --subprojects)'{-s,--subprojects}'[also updates any projects in sub-folders, such as test projects]' \
  150. && ret=0
  151. ;;
  152. (test-project)
  153. _arguments \
  154. '(-p --path)'{-p,--path}'[the project'\''s directory]: :_files -/' \
  155. '(-m --main)'{-m,--main}'[directory of the app under test, relative to the test project directory]:path' \
  156. && ret=0
  157. ;;
  158. (lib-project)
  159. _arguments \
  160. '(-p --path)'{-p,--path}'[the project'\''s directory]: :_files -/' \
  161. '(-t --target)'{-t,--target}'[target ID to set for the project]: :_android_targets' \
  162. && ret=0
  163. ;;
  164. (sdk)
  165. _arguments \
  166. '(-o --obsolete)'{-o,--obsolete}'[install obsolete packages]' \
  167. '--proxy-host[HTTP/HTTPS proxy host (overrides settings if defined)]:proxy host:_hosts' \
  168. '--proxy-port[HTTP/HTTPS proxy port (overrides settings if defined)]:proxy port number' \
  169. '(-s --no-https)'{-s,--no-https}'[use HTTP instead of HTTPS (the default) for downloads]' \
  170. '(-u --no-ui)'{-u,--no-ui}'[update from command-line (no GUI)]' \
  171. '(-f --force)'{-f,--force}'[force replacement of a package or its parts, even if something has been modified]' \
  172. '(-t --filter)'{-t,--filter}'[a filter that limits the update to the specified types of packages]: :_android_sdk_update_filters -s ,' \
  173. '(-n --dry-mode)'{-n,--dry-mode}'[simulate the update but does not download or install anything]' \
  174. && ret=0
  175. ;;
  176. esac
  177. ;;
  178. esac
  179. ;;
  180. (move)
  181. _arguments -C \
  182. '1: :_android_move_entities' \
  183. '*::move-arg:->move-args' \
  184. && ret=0
  185. case "$state" in
  186. (move-args)
  187. case $words[1] in
  188. (avd)
  189. _arguments \
  190. '(-n --name)'{-n,--name}'[name of the AVD to move or rename]: :_android_avd_names' \
  191. '(-p --path)'{-p,--path}'[path to the AVD'\''s new directory]: :_files -/' \
  192. '(-r --rename)'{-r,--rename}'[new name of the AVD]:name' \
  193. && ret=0
  194. ;;
  195. esac
  196. ;;
  197. esac
  198. ;;
  199. (delete)
  200. _arguments -C \
  201. '1: :_android_delete_entities' \
  202. '*::delete-arg:->delete-args' \
  203. && ret=0
  204. case "$state" in
  205. (delete-args)
  206. case $words[1] in
  207. (avd)
  208. _arguments \
  209. '(-n --name)'{-n,--name}'[name of the AVD to delete]: :_android_avd_names' \
  210. && ret=0
  211. ;;
  212. esac
  213. ;;
  214. esac
  215. ;;
  216. (display)
  217. _arguments \
  218. '1: :_android_display_entities' \
  219. && ret=0
  220. ;;
  221. esac
  222. ;;
  223. esac
  224. return ret
  225. }
  226. (( $+functions[_android_cmds] )) ||
  227. _android_cmds() {
  228. local commands; commands=(
  229. 'list:list existing targets or virtual devices'
  230. 'create:create new virtual devices or projects'
  231. 'update:update a virtual device, project, SDK or adb'
  232. 'move:move a virtual device'
  233. 'delete:delete a virtual device'
  234. 'avd:displays the AVD Manager window'
  235. 'sdk:displays the SDK Manager window'
  236. 'display:display manager windows'
  237. )
  238. _describe -t commands 'command' commands "$@"
  239. }
  240. (( $+functions[_android_list_entities] )) ||
  241. _android_list_entities() {
  242. local entities; entities=(
  243. 'avd:list existing Android Virtual Devices'
  244. 'target:list existing targets'
  245. 'sdk:list remote SDK repository'
  246. )
  247. _describe -t entities 'entity' entities "$@"
  248. }
  249. (( $+functions[_android_create_entities] )) ||
  250. _android_create_entities() {
  251. local entities; entities=(
  252. 'avd:create a new Android Virtual Device'
  253. 'project:create a new Android project'
  254. 'test-project:create a new Android project for a test package'
  255. 'lib-project:create a new Android library project'
  256. )
  257. _describe -t entities 'entity' entities "$@"
  258. }
  259. (( $+functions[_android_update_entities] )) ||
  260. _android_update_entities() {
  261. local entities; entities=(
  262. 'avd:update an Android Virtual Device to match the folders of a new SDK'
  263. 'project:update an Android project'
  264. 'test-project:update the Android project for a test package'
  265. 'lib-project:update an Android library project'
  266. 'adb:update adb to support the USB devices declared in the SDK add-ons'
  267. 'sdk:update the SDK by suggesting new platforms to install if available'
  268. )
  269. _describe -t entities 'entity' entities "$@"
  270. }
  271. (( $+functions[_android_move_entities] )) ||
  272. _android_move_entities() {
  273. local entities; entities=(
  274. 'avd:move or rename an Android Virtual Device'
  275. )
  276. _describe -t entities 'entity' commands "$@"
  277. }
  278. (( $+functions[_android_delete_entities] )) ||
  279. _android_delete_entities() {
  280. local entities; entities=(
  281. 'avd:delete an Android Virtual Device'
  282. )
  283. _describe -t entities 'entity' entities "$@"
  284. }
  285. (( $+functions[_android_display_entities] )) ||
  286. _android_display_entities() {
  287. local entities; entities=(
  288. 'sdk:display the SDK Manager window'
  289. 'avd:display the AVD Manager window'
  290. )
  291. _describe -t entities 'entity' entities "$@"
  292. }
  293. (( $+functions[_android_targets] )) ||
  294. _android_targets() {
  295. local targets; targets=(${(f)"$(_call_program targets $service list target --compact)"//:/\\:})
  296. _describe -t targets 'target' targets "$@"
  297. }
  298. (( $+functions[_android_avd_names] )) ||
  299. _android_avd_names() {
  300. local avd_names; avd_names=(${(f)"$(_call_program targets $service list avd --compact)"//:/\\:})
  301. _describe -t avd-names 'AVD name' avd_names "$@"
  302. }
  303. (( $+functions[_android_sdk_update_filters] )) ||
  304. _android_sdk_update_filters() {
  305. local filters; filters=(platform tool platform-tool doc sample extra)
  306. _values $@ 'filter' "${filters[@]}"
  307. }
  308. _android "$@"
  309. # Local Variables:
  310. # mode: Shell-Script
  311. # sh-indentation: 2
  312. # indent-tabs-mode: nil
  313. # sh-basic-offset: 2
  314. # End:
  315. # vim: ft=zsh sw=2 ts=2 et