west-completion.bash 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. # Bash auto-completion for west subcommands and flags. To initialize, run
  2. #
  3. # source west-completion.bash
  4. #
  5. # To make it persistent, add it to e.g. your .bashrc.
  6. __west_previous_extglob_setting=$(shopt -p extglob)
  7. shopt -s extglob
  8. # The following function is based on code from:
  9. #
  10. # bash_completion - programmable completion functions for bash 3.2+
  11. #
  12. # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
  13. # © 2009-2010, Bash Completion Maintainers
  14. # <bash-completion-devel@lists.alioth.debian.org>
  15. #
  16. # This program is free software; you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation; either version 2, or (at your option)
  19. # any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU General Public License
  27. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  28. #
  29. # The latest version of this software can be obtained here:
  30. #
  31. # http://bash-completion.alioth.debian.org/
  32. #
  33. # RELEASE: 2.x
  34. # This function can be used to access a tokenized list of words
  35. # on the command line:
  36. #
  37. # __git_reassemble_comp_words_by_ref '=:'
  38. # if test "${words_[cword_-1]}" = -w
  39. # then
  40. # ...
  41. # fi
  42. #
  43. # The argument should be a collection of characters from the list of
  44. # word completion separators (COMP_WORDBREAKS) to treat as ordinary
  45. # characters.
  46. #
  47. # This is roughly equivalent to going back in time and setting
  48. # COMP_WORDBREAKS to exclude those characters. The intent is to
  49. # make option types like --date=<type> and <rev>:<path> easy to
  50. # recognize by treating each shell word as a single token.
  51. #
  52. # It is best not to set COMP_WORDBREAKS directly because the value is
  53. # shared with other completion scripts. By the time the completion
  54. # function gets called, COMP_WORDS has already been populated so local
  55. # changes to COMP_WORDBREAKS have no effect.
  56. #
  57. # Output: words_, cword_, cur_.
  58. __west_reassemble_comp_words_by_ref()
  59. {
  60. local exclude i j first
  61. # Which word separators to exclude?
  62. exclude="${1//[^$COMP_WORDBREAKS]}"
  63. cword_=$COMP_CWORD
  64. if [ -z "$exclude" ]; then
  65. words_=("${COMP_WORDS[@]}")
  66. return
  67. fi
  68. # List of word completion separators has shrunk;
  69. # re-assemble words to complete.
  70. for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
  71. # Append each nonempty word consisting of just
  72. # word separator characters to the current word.
  73. first=t
  74. while
  75. [ $i -gt 0 ] &&
  76. [ -n "${COMP_WORDS[$i]}" ] &&
  77. # word consists of excluded word separators
  78. [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
  79. do
  80. # Attach to the previous token,
  81. # unless the previous token is the command name.
  82. if [ $j -ge 2 ] && [ -n "$first" ]; then
  83. ((j--))
  84. fi
  85. first=
  86. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  87. if [ $i = $COMP_CWORD ]; then
  88. cword_=$j
  89. fi
  90. if (($i < ${#COMP_WORDS[@]} - 1)); then
  91. ((i++))
  92. else
  93. # Done.
  94. return
  95. fi
  96. done
  97. words_[$j]=${words_[j]}${COMP_WORDS[i]}
  98. if [ $i = $COMP_CWORD ]; then
  99. cword_=$j
  100. fi
  101. done
  102. }
  103. if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
  104. _get_comp_words_by_ref ()
  105. {
  106. local exclude cur_ words_ cword_
  107. if [ "$1" = "-n" ]; then
  108. exclude=$2
  109. shift 2
  110. fi
  111. __west_reassemble_comp_words_by_ref "$exclude"
  112. cur_=${words_[cword_]}
  113. while [ $# -gt 0 ]; do
  114. case "$1" in
  115. cur)
  116. cur=$cur_
  117. ;;
  118. prev)
  119. prev=${words_[$cword_-1]}
  120. ;;
  121. words)
  122. words=("${words_[@]}")
  123. ;;
  124. cword)
  125. cword=$cword_
  126. ;;
  127. esac
  128. shift
  129. done
  130. }
  131. fi
  132. if ! type _tilde >/dev/null 2>&1; then
  133. # Perform tilde (~) completion
  134. # @return True (0) if completion needs further processing,
  135. # False (> 0) if tilde is followed by a valid username, completions
  136. # are put in COMPREPLY and no further processing is necessary.
  137. _tilde()
  138. {
  139. local result=0
  140. if [[ $1 == \~* && $1 != */* ]]; then
  141. # Try generate ~username completions
  142. COMPREPLY=( $( compgen -P '~' -u -- "${1#\~}" ) )
  143. result=${#COMPREPLY[@]}
  144. # 2>/dev/null for direct invocation, e.g. in the _tilde unit test
  145. [[ $result -gt 0 ]] && compopt -o filenames 2>/dev/null
  146. fi
  147. return $result
  148. }
  149. fi
  150. if ! type _quote_readline_by_ref >/dev/null 2>&1; then
  151. # This function quotes the argument in a way so that readline dequoting
  152. # results in the original argument. This is necessary for at least
  153. # `compgen' which requires its arguments quoted/escaped:
  154. #
  155. # $ ls "a'b/"
  156. # c
  157. # $ compgen -f "a'b/" # Wrong, doesn't return output
  158. # $ compgen -f "a\'b/" # Good
  159. # a\'b/c
  160. #
  161. # See also:
  162. # - http://lists.gnu.org/archive/html/bug-bash/2009-03/msg00155.html
  163. # - http://www.mail-archive.com/bash-completion-devel@lists.alioth.\
  164. # debian.org/msg01944.html
  165. # @param $1 Argument to quote
  166. # @param $2 Name of variable to return result to
  167. _quote_readline_by_ref()
  168. {
  169. if [ -z "$1" ]; then
  170. # avoid quoting if empty
  171. printf -v $2 %s "$1"
  172. elif [[ $1 == \'* ]]; then
  173. # Leave out first character
  174. printf -v $2 %s "${1:1}"
  175. elif [[ $1 == \~* ]]; then
  176. # avoid escaping first ~
  177. printf -v $2 \~%q "${1:1}"
  178. else
  179. printf -v $2 %q "$1"
  180. fi
  181. # Replace double escaping ( \\ ) by single ( \ )
  182. # This happens always when argument is already escaped at cmdline,
  183. # and passed to this function as e.g.: file\ with\ spaces
  184. [[ ${!2} == *\\* ]] && printf -v $2 %s "${1//\\\\/\\}"
  185. # If result becomes quoted like this: $'string', re-evaluate in order to
  186. # drop the additional quoting. See also: http://www.mail-archive.com/
  187. # bash-completion-devel@lists.alioth.debian.org/msg01942.html
  188. [[ ${!2} == \$* ]] && eval $2=${!2}
  189. } # _quote_readline_by_ref()
  190. fi
  191. # This function turns on "-o filenames" behavior dynamically. It is present
  192. # for bash < 4 reasons. See http://bugs.debian.org/272660#64 for info about
  193. # the bash < 4 compgen hack.
  194. _compopt_o_filenames()
  195. {
  196. # We test for compopt availability first because directly invoking it on
  197. # bash < 4 at this point may cause terminal echo to be turned off for some
  198. # reason, see https://bugzilla.redhat.com/653669 for more info.
  199. type compopt &>/dev/null && compopt -o filenames 2>/dev/null || \
  200. compgen -f /non-existing-dir/ >/dev/null
  201. }
  202. if ! type _filedir >/dev/null 2>&1; then
  203. # This function performs file and directory completion. It's better than
  204. # simply using 'compgen -f', because it honours spaces in filenames.
  205. # @param $1 If `-d', complete only on directories. Otherwise filter/pick only
  206. # completions with `.$1' and the uppercase version of it as file
  207. # extension.
  208. #
  209. _filedir()
  210. {
  211. local IFS=$'\n'
  212. _tilde "$cur" || return
  213. local -a toks
  214. local x tmp
  215. x=$( compgen -d -- "$cur" ) &&
  216. while read -r tmp; do
  217. toks+=( "$tmp" )
  218. done <<< "$x"
  219. if [[ "$1" != -d ]]; then
  220. local quoted
  221. _quote_readline_by_ref "$cur" quoted
  222. # Munge xspec to contain uppercase version too
  223. # http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
  224. local xspec=${1:+"!*.@($1|${1^^})"}
  225. x=$( compgen -f -X "$xspec" -- $quoted ) &&
  226. while read -r tmp; do
  227. toks+=( "$tmp" )
  228. done <<< "$x"
  229. # Try without filter if it failed to produce anything and configured to
  230. [[ -n ${COMP_FILEDIR_FALLBACK:-} && -n "$1" && ${#toks[@]} -lt 1 ]] && \
  231. x=$( compgen -f -- $quoted ) &&
  232. while read -r tmp; do
  233. toks+=( "$tmp" )
  234. done <<< "$x"
  235. fi
  236. if [[ ${#toks[@]} -ne 0 ]]; then
  237. # 2>/dev/null for direct invocation, e.g. in the _filedir unit test
  238. _compopt_o_filenames
  239. COMPREPLY+=( "${toks[@]}" )
  240. fi
  241. } # _filedir()
  242. fi
  243. # Misc helpers taken from Docker:
  244. # https://github.com/docker/docker-ce/blob/master/components/cli/contrib/completion/bash/docker
  245. # __west_pos_first_nonflag finds the position of the first word that is neither
  246. # option nor an option's argument. If there are options that require arguments,
  247. # you should pass a glob describing those options, e.g. "--option1|-o|--option2"
  248. # Use this function to restrict completions to exact positions after the argument list.
  249. __west_pos_first_nonflag()
  250. {
  251. local argument_flags=$1
  252. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  253. while [ "$counter" -le "$cword" ]; do
  254. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  255. (( counter++ ))
  256. # eat "=" in case of --option=arg syntax
  257. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  258. else
  259. case "${words[$counter]}" in
  260. -*)
  261. ;;
  262. *)
  263. break
  264. ;;
  265. esac
  266. fi
  267. # Bash splits words at "=", retaining "=" as a word, examples:
  268. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  269. while [ "${words[$counter + 1]}" = "=" ] ; do
  270. counter=$(( counter + 2))
  271. done
  272. (( counter++ ))
  273. done
  274. echo $counter
  275. }
  276. # __west_map_key_of_current_option returns `key` if we are currently completing the
  277. # value of a map option (`key=value`) which matches the extglob given as an argument.
  278. # This function is needed for key-specific completions.
  279. __west_map_key_of_current_option()
  280. {
  281. local glob="$1"
  282. local key glob_pos
  283. if [ "$cur" = "=" ] ; then # key= case
  284. key="$prev"
  285. glob_pos=$((cword - 2))
  286. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  287. key=${cur%=*}
  288. glob_pos=$((cword - 1))
  289. elif [ "$prev" = "=" ] ; then
  290. key=${words[$cword - 2]} # key=value case
  291. glob_pos=$((cword - 3))
  292. else
  293. return
  294. fi
  295. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  296. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  297. }
  298. # __west_value_of_option returns the value of the first option matching `option_glob`.
  299. # Valid values for `option_glob` are option names like `--log-level` and globs like
  300. # `--log-level|-l`
  301. # Only positions between the command and the current word are considered.
  302. __west_value_of_option()
  303. {
  304. local option_extglob=$(__west_to_extglob "$1")
  305. local counter=$((command_pos + 1))
  306. while [ "$counter" -lt "$cword" ]; do
  307. case ${words[$counter]} in
  308. $option_extglob )
  309. echo "${words[$counter + 1]}"
  310. break
  311. ;;
  312. esac
  313. (( counter++ ))
  314. done
  315. }
  316. # __west_to_alternatives transforms a multiline list of strings into a single line
  317. # string with the words separated by `|`.
  318. # This is used to prepare arguments to __west_pos_first_nonflag().
  319. __west_to_alternatives()
  320. {
  321. local parts=( $1 )
  322. local IFS='|'
  323. echo "${parts[*]}"
  324. }
  325. # __west_to_extglob transforms a multiline list of options into an extglob pattern
  326. # suitable for use in case statements.
  327. __west_to_extglob()
  328. {
  329. local extglob=$( __west_to_alternatives "$1" )
  330. echo "@($extglob)"
  331. }
  332. __set_comp_dirs()
  333. {
  334. _filedir -d
  335. }
  336. __set_comp_files()
  337. {
  338. _filedir
  339. }
  340. # Sets completions for $cur, from the possibilities in $1..n
  341. __set_comp()
  342. {
  343. # "${*:1}" gives a single argument with arguments $1..n
  344. COMPREPLY=($(compgen -W "${*:1}" -- "$cur"))
  345. }
  346. __west_x()
  347. {
  348. west 2>/dev/null "$@"
  349. }
  350. __set_comp_west_projs()
  351. {
  352. __set_comp "$(__west_x list --format={name} "$@")"
  353. }
  354. __set_comp_west_boards()
  355. {
  356. __set_comp "$(__west_x boards --format={name} "$@")"
  357. }
  358. __comp_west_west()
  359. {
  360. case "$prev" in
  361. --zephyr-base|-z)
  362. __set_comp_dirs
  363. return
  364. ;;
  365. # We don't know how to autocomplete any others
  366. $(__west_to_extglob "$global_args_opts") )
  367. return
  368. ;;
  369. esac
  370. case "$cur" in
  371. -*)
  372. __set_comp $global_bool_opts $global_args_opts
  373. ;;
  374. *)
  375. local counter=$( __west_pos_first_nonflag "$(__west_to_extglob "$global_args_opts")" )
  376. if [ "$cword" -eq "$counter" ]; then
  377. __set_comp ${cmds[*]}
  378. fi
  379. ;;
  380. esac
  381. }
  382. __comp_west_init()
  383. {
  384. local init_args_opts="
  385. --manifest -m
  386. --manifest-rev --mr
  387. --local -l
  388. "
  389. case "$prev" in
  390. --local|-l)
  391. __set_comp_dirs
  392. return
  393. ;;
  394. esac
  395. case "$cur" in
  396. -*)
  397. __set_comp $init_args_opts
  398. ;;
  399. esac
  400. }
  401. __comp_west_update()
  402. {
  403. local update_bool_opts="
  404. --keep-descendants -k
  405. --rebase -r
  406. "
  407. case "$cur" in
  408. -*)
  409. __set_comp $update_bool_opts
  410. ;;
  411. *)
  412. __set_comp_west_projs
  413. ;;
  414. esac
  415. }
  416. __comp_west_list()
  417. {
  418. local list_args_opts="
  419. --format -f
  420. "
  421. case "$prev" in
  422. # We don't know how to autocomplete those
  423. $(__west_to_extglob "$list_args_opts") )
  424. return
  425. ;;
  426. esac
  427. case "$cur" in
  428. -*)
  429. __set_comp $list_args_opts
  430. ;;
  431. *)
  432. __set_comp_west_projs
  433. ;;
  434. esac
  435. }
  436. __comp_west_manifest()
  437. {
  438. local manifest_bool_opts="
  439. --freeze
  440. "
  441. local manifest_args_opts="
  442. --out -o
  443. "
  444. case "$prev" in
  445. --out|-o)
  446. __set_comp_files
  447. return
  448. ;;
  449. esac
  450. case "$cur" in
  451. -*)
  452. __set_comp $manifest_bool_opts $manifest_args_opts
  453. ;;
  454. esac
  455. }
  456. __comp_west_diff()
  457. {
  458. case "$cur" in
  459. *)
  460. __set_comp_west_projs
  461. ;;
  462. esac
  463. }
  464. __comp_west_status()
  465. {
  466. case "$cur" in
  467. *)
  468. __set_comp_west_projs
  469. ;;
  470. esac
  471. }
  472. __comp_west_forall()
  473. {
  474. local forall_args_opts="
  475. -c
  476. "
  477. case "$prev" in
  478. # We don't know how to autocomplete those
  479. $(__west_to_extglob "$forall_args_opts") )
  480. return
  481. ;;
  482. esac
  483. case "$cur" in
  484. -*)
  485. __set_comp $forall_args_opts
  486. ;;
  487. *)
  488. __set_comp_west_projs
  489. ;;
  490. esac
  491. }
  492. __comp_west_config()
  493. {
  494. local config_bool_opts="
  495. --global
  496. --local
  497. --system
  498. "
  499. case "$cur" in
  500. -*)
  501. __set_comp $config_bool_opts
  502. ;;
  503. esac
  504. }
  505. __comp_west_help()
  506. {
  507. case "$cur" in
  508. *)
  509. local counter=$( __west_pos_first_nonflag "$(__west_to_extglob "$global_args_opts")" )
  510. if [ "$cword" -eq "$counter" ]; then
  511. __set_comp ${cmds[*]}
  512. fi
  513. ;;
  514. esac
  515. }
  516. # Zephyr extension commands
  517. __comp_west_completion()
  518. {
  519. case "$cur" in
  520. *)
  521. local counter=$( __west_pos_first_nonflag "$(__west_to_extglob "$global_args_opts")" )
  522. if [ "$cword" -eq "$counter" ]; then
  523. __set_comp "bash"
  524. fi
  525. ;;
  526. esac
  527. }
  528. __comp_west_boards()
  529. {
  530. local boards_args_opts="
  531. --format -f --name -n
  532. --arch-root --board-root
  533. "
  534. case "$prev" in
  535. --format|-f|--name|-n)
  536. # We don't know how to autocomplete these.
  537. return
  538. ;;
  539. --arch-root)
  540. __set_comp_dirs
  541. return
  542. ;;
  543. --board-root)
  544. __set_comp_dirs
  545. return
  546. ;;
  547. esac
  548. case "$cur" in
  549. -*)
  550. __set_comp $boards_args_opts
  551. ;;
  552. esac
  553. }
  554. __comp_west_build()
  555. {
  556. local build_bool_opts="
  557. --cmake -c
  558. --cmake-only
  559. -n --just-print --dry-run --recon
  560. --force -f
  561. "
  562. local build_args_opts="
  563. --board -b
  564. --build-dir -d
  565. --target -t
  566. --pristine -p
  567. --build-opt -o
  568. "
  569. case "$prev" in
  570. --board|-b)
  571. __set_comp_west_boards
  572. return
  573. ;;
  574. --build-dir|-d)
  575. __set_comp_dirs
  576. return
  577. ;;
  578. --pristine|-p)
  579. __set_comp "auto always never"
  580. return
  581. ;;
  582. # We don't know how to autocomplete those
  583. $(__west_to_extglob "$build_args_opts") )
  584. return
  585. ;;
  586. esac
  587. case "$cur" in
  588. -*)
  589. __set_comp $build_bool_opts $build_args_opts
  590. ;;
  591. *)
  592. __set_comp_dirs
  593. ;;
  594. esac
  595. }
  596. __comp_west_sign()
  597. {
  598. local sign_bool_opts="
  599. --force -f
  600. --bin --no-bin
  601. --hex --no-hex
  602. "
  603. local sign_args_opts="
  604. --build-dir -d
  605. --tool -t
  606. --tool-path -p
  607. -B --sbin
  608. -H --shex
  609. "
  610. case "$prev" in
  611. --build-dir|-d|--tool-path|-p)
  612. __set_comp_dirs
  613. return
  614. ;;
  615. --tool|-t)
  616. __set_comp "imgtool"
  617. return
  618. ;;
  619. -B|--sbin|-H|--shex)
  620. __set_comp_files
  621. return
  622. ;;
  623. esac
  624. case "$cur" in
  625. -*)
  626. __set_comp $sign_bool_opts $sign_args_opts
  627. ;;
  628. esac
  629. }
  630. __comp_west_runner_cmd()
  631. {
  632. # Common arguments for runners
  633. local runner_bool_opts="
  634. --context -H
  635. --skip-rebuild
  636. "
  637. local runner_args_opts="
  638. --build-dir -d
  639. --cmake-cache -c
  640. --runner -r
  641. --board-dir
  642. --elf-file
  643. --hex-file
  644. --bin-file
  645. --gdb
  646. --openocd
  647. --openocd-search
  648. "
  649. case "$prev" in
  650. --build-dir|-d|--cmake-cache|-c|--board-dir|--gdb|--openocd|--openocd-search)
  651. __set_comp_dirs
  652. return
  653. ;;
  654. --elf-file|--hex-file|--bin-file)
  655. __set_comp_files
  656. return
  657. ;;
  658. esac
  659. case "$cur" in
  660. -*)
  661. __set_comp $runner_bool_opts $runner_args_opts
  662. ;;
  663. esac
  664. }
  665. __comp_west_flash()
  666. {
  667. __comp_west_runner_cmd
  668. }
  669. __comp_west_debug()
  670. {
  671. __comp_west_runner_cmd
  672. }
  673. __comp_west_debugserver()
  674. {
  675. __comp_west_runner_cmd
  676. }
  677. __comp_west_attach()
  678. {
  679. __comp_west_runner_cmd
  680. }
  681. __comp_west()
  682. {
  683. local previous_extglob_setting=$(shopt -p extglob)
  684. shopt -s extglob
  685. # Reset to default, to make sure compgen works properly
  686. local IFS=$' \t\n'
  687. local builtin_cmds=(
  688. init
  689. update
  690. list
  691. manifest
  692. diff
  693. status
  694. forall
  695. config
  696. help
  697. )
  698. local zephyr_ext_cmds=(
  699. completion
  700. boards
  701. build
  702. sign
  703. flash
  704. debug
  705. debugserver
  706. attach
  707. zephyr-export
  708. )
  709. local cmds=(${builtin_cmds[*]} ${zephyr_ext_cmds[*]})
  710. # Global options for all commands
  711. local global_bool_opts="
  712. --help -h
  713. --verbose -v
  714. --version -V
  715. "
  716. local global_args_opts="
  717. --zephyr-base -z
  718. "
  719. COMPREPLY=()
  720. local cur words cword prev
  721. _get_comp_words_by_ref -n : cur words cword prev
  722. local command='west' command_pos=0
  723. local counter=1
  724. while [ "$counter" -lt "$cword" ]; do
  725. case "${words[$counter]}" in
  726. west)
  727. return 0
  728. ;;
  729. $(__west_to_extglob "$global_args_opts") )
  730. (( counter++ ))
  731. ;;
  732. -*)
  733. ;;
  734. =)
  735. (( counter++ ))
  736. ;;
  737. *)
  738. command="${words[$counter]}"
  739. command_pos=$counter
  740. break
  741. ;;
  742. esac
  743. (( counter++ ))
  744. done
  745. # Construct the function name to be called
  746. local completions_func=__comp_west_${command//-/_}
  747. #echo "comp_func: ${completions_func}"
  748. declare -F $completions_func >/dev/null && $completions_func
  749. # Restore the user's extglob setting
  750. eval "$previous_extglob_setting"
  751. return 0
  752. }
  753. eval "$__west_previous_extglob_setting"
  754. unset __west_previous_extglob_setting
  755. complete -F __comp_west west