git bash completion


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #
  2. # bash completion support for core Git.
  3. #
  4. # Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
  5. # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  6. # Distributed under the GNU General Public License, version 2.0.
  7. #
  8. # The contained completion routines provide support for completing:
  9. #
  10. # *) local and remote branch names
  11. # *) local and remote tag names
  12. # *) .git/remotes file names
  13. # *) git 'subcommands'
  14. # *) tree paths within 'ref:path/to/file' expressions
  15. # *) common --long-options
  16. #
  17. # To use these routines:
  18. #
  19. # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  20. # 2) Added the following line to your .bashrc:
  21. # source ~/.git-completion.sh
  22. #
  23. # 3) You may want to make sure the git executable is available
  24. # in your PATH before this script is sourced, as some caching
  25. # is performed while the script loads. If git isn't found
  26. # at source time then all lookups will be done on demand,
  27. # which may be slightly slower.
  28. #
  29. # 4) Consider changing your PS1 to also show the current branch:
  30. # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
  31. #
  32. # The argument to __git_ps1 will be displayed only if you
  33. # are currently in a git repository. The %s token will be
  34. # the name of the current branch.
  35. #
  36. # To submit patches:
  37. #
  38. # *) Read Documentation/SubmittingPatches
  39. # *) Send all patches to the current maintainer:
  40. #
  41. # "Shawn O. Pearce" <[email protected]>
  42. #
  43. # *) Always CC the Git mailing list:
  44. #
  45. #
  46.  
  47. __gitdir ()
  48. {
  49. if [ -z "$1" ]; then
  50. if [ -n "$__git_dir" ]; then
  51. echo "$__git_dir"
  52. elif [ -d .git ]; then
  53. echo .git
  54. else
  55. git rev-parse --git-dir 2>/dev/null
  56. fi
  57. elif [ -d "$1/.git" ]; then
  58. echo "$1/.git"
  59. else
  60. echo "$1"
  61. fi
  62. }
  63.  
  64. __git_ps1 ()
  65. {
  66. local b="$(git symbolic-ref HEAD 2>/dev/null)"
  67. if [ -n "$b" ]; then
  68. if [ -n "$1" ]; then
  69. printf "$1" "${b##refs/heads/}"
  70. else
  71. printf " (%s)" "${b##refs/heads/}"
  72. fi
  73. fi
  74. }
  75.  
  76. __gitcomp ()
  77. {
  78. local all c s=$'\n' IFS=' '$'\t'$'\n'
  79. local cur="${COMP_WORDS[COMP_CWORD]}"
  80. if [ $# -gt 2 ]; then
  81. cur="$3"
  82. fi
  83. for c in $1; do
  84. case "$c$4" in
  85. --*=*) all="$all$c$4$s" ;;
  86. *.) all="$all$c$4$s" ;;
  87. *) all="$all$c$4 $s" ;;
  88. esac
  89. done
  90. IFS=$s
  91. COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
  92. return
  93. }
  94.  
  95. __git_heads ()
  96. {
  97. local cmd i is_hash=y dir="$(__gitdir "$1")"
  98. if [ -d "$dir" ]; then
  99. for i in $(git --git-dir="$dir" \
  100. for-each-ref --format='%(refname)' \
  101. refs/heads ); do
  102. echo "${i#refs/heads/}"
  103. done
  104. return
  105. fi
  106. for i in $(git-ls-remote "$1" 2>/dev/null); do
  107. case "$is_hash,$i" in
  108. y,*) is_hash=n ;;
  109. n,*^{}) is_hash=y ;;
  110. n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  111. n,*) is_hash=y; echo "$i" ;;
  112. esac
  113. done
  114. }
  115.  
  116. __git_tags ()
  117. {
  118. local cmd i is_hash=y dir="$(__gitdir "$1")"
  119. if [ -d "$dir" ]; then
  120. for i in $(git --git-dir="$dir" \
  121. for-each-ref --format='%(refname)' \
  122. refs/tags ); do
  123. echo "${i#refs/tags/}"
  124. done
  125. return
  126. fi
  127. for i in $(git-ls-remote "$1" 2>/dev/null); do
  128. case "$is_hash,$i" in
  129. y,*) is_hash=n ;;
  130. n,*^{}) is_hash=y ;;
  131. n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
  132. n,*) is_hash=y; echo "$i" ;;
  133. esac
  134. done
  135. }
  136.  
  137. __git_refs ()
  138. {
  139. local cmd i is_hash=y dir="$(__gitdir "$1")"
  140. if [ -d "$dir" ]; then
  141. if [ -e "$dir/HEAD" ]; then echo HEAD; fi
  142. for i in $(git --git-dir="$dir" \
  143. for-each-ref --format='%(refname)' \
  144. refs/tags refs/heads refs/remotes); do
  145. case "$i" in
  146. refs/tags/*) echo "${i#refs/tags/}" ;;
  147. refs/heads/*) echo "${i#refs/heads/}" ;;
  148. refs/remotes/*) echo "${i#refs/remotes/}" ;;
  149. *) echo "$i" ;;
  150. esac
  151. done
  152. return
  153. fi
  154. for i in $(git-ls-remote "$dir" 2>/dev/null); do
  155. case "$is_hash,$i" in
  156. y,*) is_hash=n ;;
  157. n,*^{}) is_hash=y ;;
  158. n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
  159. n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  160. n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
  161. n,*) is_hash=y; echo "$i" ;;
  162. esac
  163. done
  164. }
  165.  
  166. __git_refs2 ()
  167. {
  168. local i
  169. for i in $(__git_refs "$1"); do
  170. echo "$i:$i"
  171. done
  172. }
  173.  
  174. __git_refs_remotes ()
  175. {
  176. local cmd i is_hash=y
  177. for i in $(git-ls-remote "$1" 2>/dev/null); do
  178. case "$is_hash,$i" in
  179. n,refs/heads/*)
  180. is_hash=y
  181. echo "$i:refs/remotes/$1/${i#refs/heads/}"
  182. ;;
  183. y,*) is_hash=n ;;
  184. n,*^{}) is_hash=y ;;
  185. n,refs/tags/*) is_hash=y;;
  186. n,*) is_hash=y; ;;
  187. esac
  188. done
  189. }
  190.  
  191. __git_remotes ()
  192. {
  193. local i ngoff IFS=$'\n' d="$(__gitdir)"
  194. shopt -q nullglob || ngoff=1
  195. shopt -s nullglob
  196. for i in "$d/remotes"/*; do
  197. echo ${i#$d/remotes/}
  198. done
  199. [ "$ngoff" ] && shopt -u nullglob
  200. for i in $(git --git-dir="$d" config --list); do
  201. case "$i" in
  202. remote.*.url=*)
  203. i="${i#remote.}"
  204. echo "${i/.url=*/}"
  205. ;;
  206. esac
  207. done
  208. }
  209.  
  210. __git_merge_strategies ()
  211. {
  212. if [ -n "$__git_merge_strategylist" ]; then
  213. echo "$__git_merge_strategylist"
  214. return
  215. fi
  216. sed -n "/^all_strategies='/{
  217. s/^all_strategies='//
  218. s/'//
  219. p
  220. q
  221. }" "$(git --exec-path)/git-merge"
  222. }
  223. __git_merge_strategylist=
  224. __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
  225.  
  226. __git_complete_file ()
  227. {
  228. local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
  229. case "$cur" in
  230. ?*:*)
  231. ref="${cur%%:*}"
  232. cur="${cur#*:}"
  233. case "$cur" in
  234. ?*/*)
  235. pfx="${cur%/*}"
  236. cur="${cur##*/}"
  237. ls="$ref:$pfx"
  238. pfx="$pfx/"
  239. ;;
  240. *)
  241. ls="$ref"
  242. ;;
  243. esac
  244. COMPREPLY=($(compgen -P "$pfx" \
  245. -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
  246. | sed '/^100... blob /s,^.* ,,
  247. /^040000 tree /{
  248. s,^.* ,,
  249. s,$,/,
  250. }
  251. s/^.* //')" \
  252. -- "$cur"))
  253. ;;
  254. *)
  255. __gitcomp "$(__git_refs)"
  256. ;;
  257. esac
  258. }
  259.  
  260. __git_complete_revlist ()
  261. {
  262. local pfx cur="${COMP_WORDS[COMP_CWORD]}"
  263. case "$cur" in
  264. *...*)
  265. pfx="${cur%...*}..."
  266. cur="${cur#*...}"
  267. __gitcomp "$(__git_refs)" "$pfx" "$cur"
  268. ;;
  269. *..*)
  270. pfx="${cur%..*}.."
  271. cur="${cur#*..}"
  272. __gitcomp "$(__git_refs)" "$pfx" "$cur"
  273. ;;
  274. *.)
  275. __gitcomp "$cur."
  276. ;;
  277. *)
  278. __gitcomp "$(__git_refs)"
  279. ;;
  280. esac
  281. }
  282.  
  283. __git_commands ()
  284. {
  285. if [ -n "$__git_commandlist" ]; then
  286. echo "$__git_commandlist"
  287. return
  288. fi
  289. local i IFS=" "$'\n'
  290. for i in $(git help -a|egrep '^ ')
  291. do
  292. case $i in
  293. *--*) : helper pattern;;
  294. applymbox) : ask gittus;;
  295. applypatch) : ask gittus;;
  296. archimport) : import;;
  297. cat-file) : plumbing;;
  298. check-attr) : plumbing;;
  299. check-ref-format) : plumbing;;
  300. commit-tree) : plumbing;;
  301. cvsexportcommit) : export;;
  302. cvsimport) : import;;
  303. cvsserver) : daemon;;
  304. daemon) : daemon;;
  305. diff-files) : plumbing;;
  306. diff-index) : plumbing;;
  307. diff-tree) : plumbing;;
  308. fast-import) : import;;
  309. fsck-objects) : plumbing;;
  310. fetch-pack) : plumbing;;
  311. fmt-merge-msg) : plumbing;;
  312. for-each-ref) : plumbing;;
  313. hash-object) : plumbing;;
  314. http-*) : transport;;
  315. index-pack) : plumbing;;
  316. init-db) : deprecated;;
  317. local-fetch) : plumbing;;
  318. mailinfo) : plumbing;;
  319. mailsplit) : plumbing;;
  320. merge-*) : plumbing;;
  321. mktree) : plumbing;;
  322. mktag) : plumbing;;
  323. pack-objects) : plumbing;;
  324. pack-redundant) : plumbing;;
  325. pack-refs) : plumbing;;
  326. parse-remote) : plumbing;;
  327. patch-id) : plumbing;;
  328. peek-remote) : plumbing;;
  329. prune) : plumbing;;
  330. prune-packed) : plumbing;;
  331. quiltimport) : import;;
  332. read-tree) : plumbing;;
  333. receive-pack) : plumbing;;
  334. reflog) : plumbing;;
  335. repo-config) : deprecated;;
  336. rerere) : plumbing;;
  337. rev-list) : plumbing;;
  338. rev-parse) : plumbing;;
  339. runstatus) : plumbing;;
  340. sh-setup) : internal;;
  341. shell) : daemon;;
  342. send-pack) : plumbing;;
  343. show-index) : plumbing;;
  344. ssh-*) : transport;;
  345. stripspace) : plumbing;;
  346. svn) : import export;;
  347. symbolic-ref) : plumbing;;
  348. tar-tree) : deprecated;;
  349. unpack-file) : plumbing;;
  350. unpack-objects) : plumbing;;
  351. update-index) : plumbing;;
  352. update-ref) : plumbing;;
  353. update-server-info) : daemon;;
  354. upload-archive) : plumbing;;
  355. upload-pack) : plumbing;;
  356. write-tree) : plumbing;;
  357. verify-tag) : plumbing;;
  358. *) echo $i;;
  359. esac
  360. done
  361. }
  362. __git_commandlist=
  363. __git_commandlist="$(__git_commands 2>/dev/null)"
  364.  
  365. __git_aliases ()
  366. {
  367. local i IFS=$'\n'
  368. for i in $(git --git-dir="$(__gitdir)" config --list); do
  369. case "$i" in
  370. alias.*)
  371. i="${i#alias.}"
  372. echo "${i/=*/}"
  373. ;;
  374. esac
  375. done
  376. }
  377.  
  378. __git_aliased_command ()
  379. {
  380. local word cmdline=$(git --git-dir="$(__gitdir)" \
  381. config --get "alias.$1")
  382. for word in $cmdline; do
  383. if [ "${word##-*}" ]; then
  384. echo $word
  385. return
  386. fi
  387. done
  388. }
  389.  
  390. __git_whitespacelist="nowarn warn error error-all strip"
  391.  
  392. _git_am ()
  393. {
  394. local cur="${COMP_WORDS[COMP_CWORD]}"
  395. if [ -d .dotest ]; then
  396. __gitcomp "--skip --resolved"
  397. return
  398. fi
  399. case "$cur" in
  400. --whitespace=*)
  401. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  402. return
  403. ;;
  404. --*)
  405. __gitcomp "
  406. --signoff --utf8 --binary --3way --interactive
  407. --whitespace=
  408. "
  409. return
  410. esac
  411. COMPREPLY=()
  412. }
  413.  
  414. _git_apply ()
  415. {
  416. local cur="${COMP_WORDS[COMP_CWORD]}"
  417. case "$cur" in
  418. --whitespace=*)
  419. __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  420. return
  421. ;;
  422. --*)
  423. __gitcomp "
  424. --stat --numstat --summary --check --index
  425. --cached --index-info --reverse --reject --unidiff-zero
  426. --apply --no-add --exclude=
  427. --whitespace= --inaccurate-eof --verbose
  428. "
  429. return
  430. esac
  431. COMPREPLY=()
  432. }
  433.  
  434. _git_add ()
  435. {
  436. local cur="${COMP_WORDS[COMP_CWORD]}"
  437. case "$cur" in
  438. --*)
  439. __gitcomp "--interactive --refresh"
  440. return
  441. esac
  442. COMPREPLY=()
  443. }
  444.  
  445. _git_bisect ()
  446. {
  447. local i c=1 command
  448. while [ $c -lt $COMP_CWORD ]; do
  449. i="${COMP_WORDS[c]}"
  450. case "$i" in
  451. start|bad|good|reset|visualize|replay|log)
  452. command="$i"
  453. break
  454. ;;
  455. esac
  456. c=$((++c))
  457. done
  458.  
  459. if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
  460. __gitcomp "start bad good reset visualize replay log"
  461. return
  462. fi
  463.  
  464. case "$command" in
  465. bad|good|reset)
  466. __gitcomp "$(__git_refs)"
  467. ;;
  468. *)
  469. COMPREPLY=()
  470. ;;
  471. esac
  472. }
  473.  
  474. _git_branch ()
  475. {
  476. __gitcomp "$(__git_refs)"
  477. }
  478.  
  479. _git_bundle ()
  480. {
  481. local mycword="$COMP_CWORD"
  482. case "${COMP_WORDS[0]}" in
  483. git)
  484. local cmd="${COMP_WORDS[2]}"
  485. mycword="$((mycword-1))"
  486. ;;
  487. git-bundle*)
  488. local cmd="${COMP_WORDS[1]}"
  489. ;;
  490. esac
  491. case "$mycword" in
  492. 1)
  493. __gitcomp "create list-heads verify unbundle"
  494. ;;
  495. 2)
  496. # looking for a file
  497. ;;
  498. *)
  499. case "$cmd" in
  500. create)
  501. __git_complete_revlist
  502. ;;
  503. esac
  504. ;;
  505. esac
  506. }
  507.  
  508. _git_checkout ()
  509. {
  510. __gitcomp "$(__git_refs)"
  511. }
  512.  
  513. _git_cherry ()
  514. {
  515. __gitcomp "$(__git_refs)"
  516. }
  517.  
  518. _git_cherry_pick ()
  519. {
  520. local cur="${COMP_WORDS[COMP_CWORD]}"
  521. case "$cur" in
  522. --*)
  523. __gitcomp "--edit --no-commit"
  524. ;;
  525. *)
  526. __gitcomp "$(__git_refs)"
  527. ;;
  528. esac
  529. }
  530.  
  531. _git_commit ()
  532. {
  533. local cur="${COMP_WORDS[COMP_CWORD]}"
  534. case "$cur" in
  535. --*)
  536. __gitcomp "
  537. --all --author= --signoff --verify --no-verify
  538. --edit --amend --include --only
  539. "
  540. return
  541. esac
  542. COMPREPLY=()
  543. }
  544.  
  545. _git_describe ()
  546. {
  547. __gitcomp "$(__git_refs)"
  548. }
  549.  
  550. _git_diff ()
  551. {
  552. local cur="${COMP_WORDS[COMP_CWORD]}"
  553. case "$cur" in
  554. --*)
  555. __gitcomp "--cached --stat --numstat --shortstat --summary
  556. --patch-with-stat --name-only --name-status --color
  557. --no-color --color-words --no-renames --check
  558. --full-index --binary --abbrev --diff-filter
  559. --find-copies-harder --pickaxe-all --pickaxe-regex
  560. --text --ignore-space-at-eol --ignore-space-change
  561. --ignore-all-space --exit-code --quiet --ext-diff
  562. --no-ext-diff"
  563. return
  564. ;;
  565. esac
  566. __git_complete_file
  567. }
  568.  
  569. _git_diff_tree ()
  570. {
  571. __gitcomp "$(__git_refs)"
  572. }
  573.  
  574. _git_fetch ()
  575. {
  576. local cur="${COMP_WORDS[COMP_CWORD]}"
  577.  
  578. case "${COMP_WORDS[0]},$COMP_CWORD" in
  579. git-fetch*,1)
  580. __gitcomp "$(__git_remotes)"
  581. ;;
  582. git,2)
  583. __gitcomp "$(__git_remotes)"
  584. ;;
  585. *)
  586. case "$cur" in
  587. *:*)
  588. __gitcomp "$(__git_refs)" "" "${cur#*:}"
  589. ;;
  590. *)
  591. local remote
  592. case "${COMP_WORDS[0]}" in
  593. git-fetch) remote="${COMP_WORDS[1]}" ;;
  594. git) remote="${COMP_WORDS[2]}" ;;
  595. esac
  596. __gitcomp "$(__git_refs2 "$remote")"
  597. ;;
  598. esac
  599. ;;
  600. esac
  601. }
  602.  
  603. _git_format_patch ()
  604. {
  605. local cur="${COMP_WORDS[COMP_CWORD]}"
  606. case "$cur" in
  607. --*)
  608. __gitcomp "
  609. --stdout --attach --thread
  610. --output-directory
  611. --numbered --start-number
  612. --numbered-files
  613. --keep-subject
  614. --signoff
  615. --in-reply-to=
  616. --full-index --binary
  617. --not --all
  618. "
  619. return
  620. ;;
  621. esac
  622. __git_complete_revlist
  623. }
  624.  
  625. _git_gc ()
  626. {
  627. local cur="${COMP_WORDS[COMP_CWORD]}"
  628. case "$cur" in
  629. --*)
  630. __gitcomp "--prune --aggressive"
  631. return
  632. ;;
  633. esac
  634. COMPREPLY=()
  635. }
  636.  
  637. _git_ls_remote ()
  638. {
  639. __gitcomp "$(__git_remotes)"
  640. }
  641.  
  642. _git_ls_tree ()
  643. {
  644. __git_complete_file
  645. }
  646.  
  647. _git_log ()
  648. {
  649. local cur="${COMP_WORDS[COMP_CWORD]}"
  650. case "$cur" in
  651. --pretty=*)
  652. __gitcomp "
  653. oneline short medium full fuller email raw
  654. " "" "${cur##--pretty=}"
  655. return
  656. ;;
  657. --date=*)
  658. __gitcomp "
  659. relative iso8601 rfc2822 short local default
  660. " "" "${cur##--date=}"
  661. return
  662. ;;
  663. --*)
  664. __gitcomp "
  665. --max-count= --max-age= --since= --after=
  666. --min-age= --before= --until=
  667. --root --topo-order --date-order --reverse
  668. --no-merges --follow
  669. --abbrev-commit --abbrev=
  670. --relative-date --date=
  671. --author= --committer= --grep=
  672. --all-match
  673. --pretty= --name-status --name-only --raw
  674. --not --all
  675. --left-right --cherry-pick
  676. "
  677. return
  678. ;;
  679. esac
  680. __git_complete_revlist
  681. }
  682.  
  683. _git_merge ()
  684. {
  685. local cur="${COMP_WORDS[COMP_CWORD]}"
  686. case "${COMP_WORDS[COMP_CWORD-1]}" in
  687. -s|--strategy)
  688. __gitcomp "$(__git_merge_strategies)"
  689. return
  690. esac
  691. case "$cur" in
  692. --strategy=*)
  693. __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
  694. return
  695. ;;
  696. --*)
  697. __gitcomp "
  698. --no-commit --no-summary --squash --strategy
  699. "
  700. return
  701. esac
  702. __gitcomp "$(__git_refs)"
  703. }
  704.  
  705. _git_merge_base ()
  706. {
  707. __gitcomp "$(__git_refs)"
  708. }
  709.  
  710. _git_name_rev ()
  711. {
  712. __gitcomp "--tags --all --stdin"
  713. }
  714.  
  715. _git_pull ()
  716. {
  717. local cur="${COMP_WORDS[COMP_CWORD]}"
  718.  
  719. case "${COMP_WORDS[0]},$COMP_CWORD" in
  720. git-pull*,1)
  721. __gitcomp "$(__git_remotes)"
  722. ;;
  723. git,2)
  724. __gitcomp "$(__git_remotes)"
  725. ;;
  726. *)
  727. local remote
  728. case "${COMP_WORDS[0]}" in
  729. git-pull) remote="${COMP_WORDS[1]}" ;;
  730. git) remote="${COMP_WORDS[2]}" ;;
  731. esac
  732. __gitcomp "$(__git_refs "$remote")"
  733. ;;
  734. esac
  735. }
  736.  
  737. _git_push ()
  738. {
  739. local cur="${COMP_WORDS[COMP_CWORD]}"
  740.  
  741. case "${COMP_WORDS[0]},$COMP_CWORD" in
  742. git-push*,1)
  743. __gitcomp "$(__git_remotes)"
  744. ;;
  745. git,2)
  746. __gitcomp "$(__git_remotes)"
  747. ;;
  748. *)
  749. case "$cur" in
  750. *:*)
  751. local remote
  752. case "${COMP_WORDS[0]}" in
  753. git-push) remote="${COMP_WORDS[1]}" ;;
  754. git) remote="${COMP_WORDS[2]}" ;;
  755. esac
  756. __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
  757. ;;
  758. +*)
  759. __gitcomp "$(__git_refs)" + "${cur#+}"
  760. ;;
  761. *)
  762. __gitcomp "$(__git_refs)"
  763. ;;
  764. esac
  765. ;;
  766. esac
  767. }
  768.  
  769. _git_rebase ()
  770. {
  771. local cur="${COMP_WORDS[COMP_CWORD]}"
  772. if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
  773. __gitcomp "--continue --skip --abort"
  774. return
  775. fi
  776. case "${COMP_WORDS[COMP_CWORD-1]}" in
  777. -s|--strategy)
  778. __gitcomp "$(__git_merge_strategies)"
  779. return
  780. esac
  781. case "$cur" in
  782. --strategy=*)
  783. __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
  784. return
  785. ;;
  786. --*)
  787. __gitcomp "--onto --merge --strategy"
  788. return
  789. esac
  790. __gitcomp "$(__git_refs)"
  791. }
  792.  
  793. _git_config ()
  794. {
  795. local cur="${COMP_WORDS[COMP_CWORD]}"
  796. local prv="${COMP_WORDS[COMP_CWORD-1]}"
  797. case "$prv" in
  798. branch.*.remote)
  799. __gitcomp "$(__git_remotes)"
  800. return
  801. ;;
  802. branch.*.merge)
  803. __gitcomp "$(__git_refs)"
  804. return
  805. ;;
  806. remote.*.fetch)
  807. local remote="${prv#remote.}"
  808. remote="${remote%.fetch}"
  809. __gitcomp "$(__git_refs_remotes "$remote")"
  810. return
  811. ;;
  812. remote.*.push)
  813. local remote="${prv#remote.}"
  814. remote="${remote%.push}"
  815. __gitcomp "$(git --git-dir="$(__gitdir)" \
  816. for-each-ref --format='%(refname):%(refname)' \
  817. refs/heads)"
  818. return
  819. ;;
  820. pull.twohead|pull.octopus)
  821. __gitcomp "$(__git_merge_strategies)"
  822. return
  823. ;;
  824. color.branch|color.diff|color.status)
  825. __gitcomp "always never auto"
  826. return
  827. ;;
  828. color.*.*)
  829. __gitcomp "
  830. black red green yellow blue magenta cyan white
  831. bold dim ul blink reverse
  832. "
  833. return
  834. ;;
  835. *.*)
  836. COMPREPLY=()
  837. return
  838. ;;
  839. esac
  840. case "$cur" in
  841. --*)
  842. __gitcomp "
  843. --global --system --file=
  844. --list --replace-all
  845. --get --get-all --get-regexp
  846. --add --unset --unset-all
  847. --remove-section --rename-section
  848. "
  849. return
  850. ;;
  851. branch.*.*)
  852. local pfx="${cur%.*}."
  853. cur="${cur##*.}"
  854. __gitcomp "remote merge" "$pfx" "$cur"
  855. return
  856. ;;
  857. branch.*)
  858. local pfx="${cur%.*}."
  859. cur="${cur#*.}"
  860. __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
  861. return
  862. ;;
  863. remote.*.*)
  864. local pfx="${cur%.*}."
  865. cur="${cur##*.}"
  866. __gitcomp "
  867. url fetch push skipDefaultUpdate
  868. receivepack uploadpack tagopt
  869. " "$pfx" "$cur"
  870. return
  871. ;;
  872. remote.*)
  873. local pfx="${cur%.*}."
  874. cur="${cur#*.}"
  875. __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
  876. return
  877. ;;
  878. esac
  879. __gitcomp "
  880. apply.whitespace
  881. core.fileMode
  882. core.gitProxy
  883. core.ignoreStat
  884. core.preferSymlinkRefs
  885. core.logAllRefUpdates
  886. core.loosecompression
  887. core.repositoryFormatVersion
  888. core.sharedRepository
  889. core.warnAmbiguousRefs
  890. core.compression
  891. core.legacyHeaders
  892. core.packedGitWindowSize
  893. core.packedGitLimit
  894. clean.requireForce
  895. color.branch
  896. color.branch.current
  897. color.branch.local
  898. color.branch.remote
  899. color.branch.plain
  900. color.diff
  901. color.diff.plain
  902. color.diff.meta
  903. color.diff.frag
  904. color.diff.old
  905. color.diff.new
  906. color.diff.commit
  907. color.diff.whitespace
  908. color.pager
  909. color.status
  910. color.status.header
  911. color.status.added
  912. color.status.changed
  913. color.status.untracked
  914. diff.renameLimit
  915. diff.renames
  916. fetch.unpackLimit
  917. format.headers
  918. format.subjectprefix
  919. gitcvs.enabled
  920. gitcvs.logfile
  921. gitcvs.allbinary
  922. gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dvpass
  923. gc.packrefs
  924. gc.reflogexpire
  925. gc.reflogexpireunreachable
  926. gc.rerereresolved
  927. gc.rerereunresolved
  928. http.sslVerify
  929. http.sslCert
  930. http.sslKey
  931. http.sslCAInfo
  932. http.sslCAPath
  933. http.maxRequests
  934. http.lowSpeedLimit
  935. http.lowSpeedTime
  936. http.noEPSV
  937. i18n.commitEncoding
  938. i18n.logOutputEncoding
  939. log.showroot
  940. merge.tool
  941. merge.summary
  942. merge.verbosity
  943. pack.window
  944. pack.depth
  945. pack.windowMemory
  946. pack.compression
  947. pack.deltaCacheSize
  948. pack.deltaCacheLimit
  949. pull.octopus
  950. pull.twohead
  951. repack.useDeltaBaseOffset
  952. show.difftree
  953. showbranch.default
  954. tar.umask
  955. transfer.unpackLimit
  956. receive.unpackLimit
  957. receive.denyNonFastForwards
  958. user.name
  959. user.email
  960. user.signingkey
  961. whatchanged.difftree
  962. branch. remote.
  963. "
  964. }
  965.  
  966. _git_remote ()
  967. {
  968. local i c=1 command
  969. while [ $c -lt $COMP_CWORD ]; do
  970. i="${COMP_WORDS[c]}"
  971. case "$i" in
  972. add|rm|show|prune|update) command="$i"; break ;;
  973. esac
  974. c=$((++c))
  975. done
  976.  
  977. if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
  978. __gitcomp "add rm show prune update"
  979. return
  980. fi
  981.  
  982. case "$command" in
  983. rm|show|prune)
  984. __gitcomp "$(__git_remotes)"
  985. ;;
  986. update)
  987. local i c='' IFS=$'\n'
  988. for i in $(git --git-dir="$(__gitdir)" config --list); do
  989. case "$i" in
  990. remotes.*)
  991. i="${i#remotes.}"
  992. c="$c ${i/=*/}"
  993. ;;
  994. esac
  995. done
  996. __gitcomp "$c"
  997. ;;
  998. *)
  999. COMPREPLY=()
  1000. ;;
  1001. esac
  1002. }
  1003.  
  1004. _git_reset ()
  1005. {
  1006. local cur="${COMP_WORDS[COMP_CWORD]}"
  1007. case "$cur" in
  1008. --*)
  1009. __gitcomp "--mixed --hard --soft"
  1010. return
  1011. ;;
  1012. esac
  1013. __gitcomp "$(__git_refs)"
  1014. }
  1015.  
  1016. _git_shortlog ()
  1017. {
  1018. local cur="${COMP_WORDS[COMP_CWORD]}"
  1019. case "$cur" in
  1020. --*)
  1021. __gitcomp "
  1022. --max-count= --max-age= --since= --after=
  1023. --min-age= --before= --until=
  1024. --no-merges
  1025. --author= --committer= --grep=
  1026. --all-match
  1027. --not --all
  1028. --numbered --summary
  1029. "
  1030. return
  1031. ;;
  1032. esac
  1033. __git_complete_revlist
  1034. }
  1035.  
  1036. _git_show ()
  1037. {
  1038. local cur="${COMP_WORDS[COMP_CWORD]}"
  1039. case "$cur" in
  1040. --pretty=*)
  1041. __gitcomp "
  1042. oneline short medium full fuller email raw
  1043. " "" "${cur##--pretty=}"
  1044. return
  1045. ;;
  1046. --*)
  1047. __gitcomp "--pretty="
  1048. return
  1049. ;;
  1050. esac
  1051. __git_complete_file
  1052. }
  1053.  
  1054. _git_stash ()
  1055. {
  1056. __gitcomp 'list show apply clear'
  1057. }
  1058.  
  1059. _git_submodule ()
  1060. {
  1061. local i c=1 command
  1062. while [ $c -lt $COMP_CWORD ]; do
  1063. i="${COMP_WORDS[c]}"
  1064. case "$i" in
  1065. add|status|init|update) command="$i"; break ;;
  1066. esac
  1067. c=$((++c))
  1068. done
  1069.  
  1070. if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
  1071. local cur="${COMP_WORDS[COMP_CWORD]}"
  1072. case "$cur" in
  1073. --*)
  1074. __gitcomp "--quiet --cached"
  1075. ;;
  1076. *)
  1077. __gitcomp "add status init update"
  1078. ;;
  1079. esac
  1080. return
  1081. fi
  1082. }
  1083.  
  1084. _git_tag ()
  1085. {
  1086. local i c=1 f=0
  1087. while [ $c -lt $COMP_CWORD ]; do
  1088. i="${COMP_WORDS[c]}"
  1089. case "$i" in
  1090. -d|-v)
  1091. __gitcomp "$(__git_tags)"
  1092. return
  1093. ;;
  1094. -f)
  1095. f=1
  1096. ;;
  1097. esac
  1098. c=$((++c))
  1099. done
  1100.  
  1101. case "${COMP_WORDS[COMP_CWORD-1]}" in
  1102. -m|-F)
  1103. COMPREPLY=()
  1104. ;;
  1105. -*|tag|git-tag)
  1106. if [ $f = 1 ]; then
  1107. __gitcomp "$(__git_tags)"
  1108. else
  1109. COMPREPLY=()
  1110. fi
  1111. ;;
  1112. *)
  1113. __gitcomp "$(__git_refs)"
  1114. ;;
  1115. esac
  1116. }
  1117.  
  1118. _git ()
  1119. {
  1120. local i c=1 command __git_dir
  1121.  
  1122. while [ $c -lt $COMP_CWORD ]; do
  1123. i="${COMP_WORDS[c]}"
  1124. case "$i" in
  1125. --git-dir=*) __git_dir="${i#--git-dir=}" ;;
  1126. --bare) __git_dir="." ;;
  1127. --version|--help|-p|--paginate) ;;
  1128. *) command="$i"; break ;;
  1129. esac
  1130. c=$((++c))
  1131. done
  1132.  
  1133. if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
  1134. case "${COMP_WORDS[COMP_CWORD]}" in
  1135. --*=*) COMPREPLY=() ;;
  1136. --*) __gitcomp "
  1137. --no-pager
  1138. --git-dir=
  1139. --bare
  1140. --version
  1141. --exec-path
  1142. "
  1143. ;;
  1144. *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
  1145. esac
  1146. return
  1147. fi
  1148.  
  1149. local expansion=$(__git_aliased_command "$command")
  1150. [ "$expansion" ] && command="$expansion"
  1151.  
  1152. case "$command" in
  1153. am) _git_am ;;
  1154. add) _git_add ;;
  1155. apply) _git_apply ;;
  1156. bisect) _git_bisect ;;
  1157. bundle) _git_bundle ;;
  1158. branch) _git_branch ;;
  1159. checkout) _git_checkout ;;
  1160. cherry) _git_cherry ;;
  1161. cherry-pick) _git_cherry_pick ;;
  1162. commit) _git_commit ;;
  1163. config) _git_config ;;
  1164. describe) _git_describe ;;
  1165. diff) _git_diff ;;
  1166. fetch) _git_fetch ;;
  1167. format-patch) _git_format_patch ;;
  1168. gc) _git_gc ;;
  1169. log) _git_log ;;
  1170. ls-remote) _git_ls_remote ;;
  1171. ls-tree) _git_ls_tree ;;
  1172. merge) _git_merge;;
  1173. merge-base) _git_merge_base ;;
  1174. name-rev) _git_name_rev ;;
  1175. pull) _git_pull ;;
  1176. push) _git_push ;;
  1177. rebase) _git_rebase ;;
  1178. remote) _git_remote ;;
  1179. reset) _git_reset ;;
  1180. shortlog) _git_shortlog ;;
  1181. show) _git_show ;;
  1182. show-branch) _git_log ;;
  1183. stash) _git_stash ;;
  1184. submodule) _git_submodule ;;
  1185. tag) _git_tag ;;
  1186. whatchanged) _git_log ;;
  1187. *) COMPREPLY=() ;;
  1188. esac
  1189. }
  1190.  
  1191. _gitk ()
  1192. {
  1193. local cur="${COMP_WORDS[COMP_CWORD]}"
  1194. case "$cur" in
  1195. --*)
  1196. __gitcomp "--not --all"
  1197. return
  1198. ;;
  1199. esac
  1200. __git_complete_revlist
  1201. }
  1202.  
  1203. complete -o default -o nospace -F _git git
  1204. complete -o default -o nospace -F _gitk gitk
  1205. complete -o default -o nospace -F _git_am git-am
  1206. complete -o default -o nospace -F _git_apply git-apply
  1207. complete -o default -o nospace -F _git_bisect git-bisect
  1208. complete -o default -o nospace -F _git_branch git-branch
  1209. complete -o default -o nospace -F _git_bundle git-bundle
  1210. complete -o default -o nospace -F _git_checkout git-checkout
  1211. complete -o default -o nospace -F _git_cherry git-cherry
  1212. complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
  1213. complete -o default -o nospace -F _git_commit git-commit
  1214. complete -o default -o nospace -F _git_describe git-describe
  1215. complete -o default -o nospace -F _git_diff git-diff
  1216. complete -o default -o nospace -F _git_fetch git-fetch
  1217. complete -o default -o nospace -F _git_format_patch git-format-patch
  1218. complete -o default -o nospace -F _git_gc git-gc
  1219. complete -o default -o nospace -F _git_log git-log
  1220. complete -o default -o nospace -F _git_ls_remote git-ls-remote
  1221. complete -o default -o nospace -F _git_ls_tree git-ls-tree
  1222. complete -o default -o nospace -F _git_merge git-merge
  1223. complete -o default -o nospace -F _git_merge_base git-merge-base
  1224. complete -o default -o nospace -F _git_name_rev git-name-rev
  1225. complete -o default -o nospace -F _git_pull git-pull
  1226. complete -o default -o nospace -F _git_push git-push
  1227. complete -o default -o nospace -F _git_rebase git-rebase
  1228. complete -o default -o nospace -F _git_config git-config
  1229. complete -o default -o nospace -F _git_remote git-remote
  1230. complete -o default -o nospace -F _git_reset git-reset
  1231. complete -o default -o nospace -F _git_shortlog git-shortlog
  1232. complete -o default -o nospace -F _git_show git-show
  1233. complete -o default -o nospace -F _git_stash git-stash
  1234. complete -o default -o nospace -F _git_submodule git-submodule
  1235. complete -o default -o nospace -F _git_log git-show-branch
  1236. complete -o default -o nospace -F _git_tag git-tag
  1237. complete -o default -o nospace -F _git_log git-whatchanged
  1238.  
  1239. # The following are necessary only for Cygwin, and only are needed
  1240. # when the user has tab-completed the executable name and consequently
  1241. # included the '.exe' suffix.
  1242. #
  1243. if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
  1244. complete -o default -o nospace -F _git_add git-add.exe
  1245. complete -o default -o nospace -F _git_apply git-apply.exe
  1246. complete -o default -o nospace -F _git git.exe
  1247. complete -o default -o nospace -F _git_branch git-branch.exe
  1248. complete -o default -o nospace -F _git_bundle git-bundle.exe
  1249. complete -o default -o nospace -F _git_cherry git-cherry.exe
  1250. complete -o default -o nospace -F _git_describe git-describe.exe
  1251. complete -o default -o nospace -F _git_diff git-diff.exe
  1252. complete -o default -o nospace -F _git_format_patch git-format-patch.exe
  1253. complete -o default -o nospace -F _git_log git-log.exe
  1254. complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
  1255. complete -o default -o nospace -F _git_merge_base git-merge-base.exe
  1256. complete -o default -o nospace -F _git_name_rev git-name-rev.exe
  1257. complete -o default -o nospace -F _git_push git-push.exe
  1258. complete -o default -o nospace -F _git_config git-config
  1259. complete -o default -o nospace -F _git_shortlog git-shortlog.exe
  1260. complete -o default -o nospace -F _git_show git-show.exe
  1261. complete -o default -o nospace -F _git_log git-show-branch.exe
  1262. complete -o default -o nospace -F _git_tag git-tag.exe
  1263. complete -o default -o nospace -F _git_log git-whatchanged.exe
  1264. fi
  1265.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.