my xfce4 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.

498 lines
14 KiB

3 years ago
  1. # ------------------------------------------------------------------------------
  2. # Description
  3. # -----------
  4. #
  5. # Completion script for git-extras (https://github.com/tj/git-extras).
  6. #
  7. # This depends on and reuses some of the internals of the _git completion
  8. # function that ships with zsh itself. It will not work with the _git that ships
  9. # with git.
  10. #
  11. # ------------------------------------------------------------------------------
  12. # Authors
  13. # -------
  14. #
  15. # * Alexis GRIMALDI (https://github.com/agrimaldi)
  16. # * spacewander (https://github.com/spacewander)
  17. #
  18. # ------------------------------------------------------------------------------
  19. # Inspirations
  20. # -----------
  21. #
  22. # * git-extras (https://github.com/tj/git-extras)
  23. # * git-flow-completion (https://github.com/bobthecow/git-flow-completion)
  24. #
  25. # ------------------------------------------------------------------------------
  26. # Internal functions
  27. # These are a lot like their __git_* equivalents inside _git
  28. __gitex_command_successful () {
  29. if (( ${#*:#0} > 0 )); then
  30. _message 'not a git repository'
  31. return 1
  32. fi
  33. return 0
  34. }
  35. __gitex_commits() {
  36. declare -A commits
  37. git log --oneline -15 | sed 's/\([[:alnum:]]\{7\}\) /\1:/' | while read commit
  38. do
  39. hash=$(echo $commit | cut -d':' -f1)
  40. commits[$hash]="$commit"
  41. done
  42. local ret=1
  43. _describe -t commits commit commits && ret=0
  44. }
  45. __gitex_remote_names() {
  46. local expl
  47. declare -a remote_names
  48. remote_names=(${(f)"$(_call_program remotes git remote 2>/dev/null)"})
  49. __git_command_successful || return
  50. _wanted remote-names expl remote-name compadd $* - $remote_names
  51. }
  52. __gitex_tag_names() {
  53. local expl
  54. declare -a tag_names
  55. tag_names=(${${(f)"$(_call_program tags git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
  56. __git_command_successful || return
  57. _wanted tag-names expl tag-name compadd $* - $tag_names
  58. }
  59. __gitex_branch_names() {
  60. local expl
  61. declare -a branch_names
  62. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
  63. __git_command_successful || return
  64. _wanted branch-names expl branch-name compadd $* - $branch_names
  65. }
  66. __gitex_specific_branch_names() {
  67. local expl
  68. declare -a branch_names
  69. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/"$1" 2>/dev/null)"}#refs/heads/$1/})
  70. __git_command_successful || return
  71. _wanted branch-names expl branch-name compadd - $branch_names
  72. }
  73. __gitex_chore_branch_names() {
  74. __gitex_specific_branch_names 'chore'
  75. }
  76. __gitex_feature_branch_names() {
  77. __gitex_specific_branch_names 'feature'
  78. }
  79. __gitex_refactor_branch_names() {
  80. __gitex_specific_branch_names 'refactor'
  81. }
  82. __gitex_bug_branch_names() {
  83. __gitex_specific_branch_names 'bug'
  84. }
  85. __gitex_submodule_names() {
  86. local expl
  87. declare -a submodule_names
  88. submodule_names=(${(f)"$(_call_program branchrefs git submodule status | awk '{print $2}')"}) # '
  89. __git_command_successful || return
  90. _wanted submodule-names expl submodule-name compadd $* - $submodule_names
  91. }
  92. __gitex_author_names() {
  93. local expl
  94. declare -a author_names
  95. author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"})
  96. __git_command_successful || return
  97. _wanted author-names expl author-name compadd $* - $author_names
  98. }
  99. # subcommands
  100. _git-authors() {
  101. _arguments -C \
  102. '(--list -l)'{--list,-l}'[show authors]' \
  103. '--no-email[without email]' \
  104. }
  105. _git-bug() {
  106. local curcontext=$curcontext state line ret=1
  107. declare -A opt_args
  108. _arguments -C \
  109. ': :->command' \
  110. '*:: :->option-or-argument' && ret=0
  111. case $state in
  112. (command)
  113. declare -a commands
  114. commands=(
  115. 'finish:merge bug into the current branch'
  116. )
  117. _describe -t commands command commands && ret=0
  118. ;;
  119. (option-or-argument)
  120. curcontext=${curcontext%:*}-$line[1]:
  121. case $line[1] in
  122. (finish)
  123. _arguments -C \
  124. ':branch-name:__gitex_bug_branch_names'
  125. ;;
  126. -r|--remote )
  127. _arguments -C \
  128. ':remote-name:__gitex_remote_names'
  129. ;;
  130. esac
  131. return 0
  132. esac
  133. _arguments \
  134. '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
  135. }
  136. _git-changelog() {
  137. _arguments \
  138. '(-l --list)'{-l,--list}'[list commits]' \
  139. }
  140. _git-chore() {
  141. local curcontext=$curcontext state line ret=1
  142. declare -A opt_args
  143. _arguments -C \
  144. ': :->command' \
  145. '*:: :->option-or-argument' && ret=0
  146. case $state in
  147. (command)
  148. declare -a commands
  149. commands=(
  150. 'finish:merge and delete the chore branch'
  151. )
  152. _describe -t commands command commands && ret=0
  153. ;;
  154. (option-or-argument)
  155. curcontext=${curcontext%:*}-$line[1]:
  156. case $line[1] in
  157. (finish)
  158. _arguments -C \
  159. ':branch-name:__gitex_chore_branch_names'
  160. ;;
  161. -r|--remote )
  162. _arguments -C \
  163. ':remote-name:__gitex_remote_names'
  164. ;;
  165. esac
  166. return 0
  167. esac
  168. _arguments \
  169. '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
  170. }
  171. _git-contrib() {
  172. _arguments \
  173. ':author:__gitex_author_names'
  174. }
  175. _git-count() {
  176. _arguments \
  177. '--all[detailed commit count]'
  178. }
  179. _git-create-branch() {
  180. local curcontext=$curcontext state line
  181. _arguments -C \
  182. ': :->command' \
  183. '*:: :->option-or-argument'
  184. case "$state" in
  185. (command)
  186. _arguments \
  187. '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
  188. ;;
  189. (option-or-argument)
  190. curcontext=${curcontext%:*}-$line[1]:
  191. case $line[1] in
  192. -r|--remote )
  193. _arguments -C \
  194. ':remote-name:__gitex_remote_names'
  195. ;;
  196. esac
  197. esac
  198. }
  199. _git-delete-branch() {
  200. _arguments \
  201. ':branch-name:__gitex_branch_names'
  202. }
  203. _git-delete-submodule() {
  204. _arguments \
  205. ':submodule-name:__gitex_submodule_names'
  206. }
  207. _git-delete-tag() {
  208. _arguments \
  209. ':tag-name:__gitex_tag_names'
  210. }
  211. _git-effort() {
  212. _arguments \
  213. '--above[ignore file with less than x commits]'
  214. }
  215. _git-extras() {
  216. local curcontext=$curcontext state line ret=1
  217. declare -A opt_args
  218. _arguments -C \
  219. ': :->command' \
  220. '*:: :->option-or-argument' && ret=0
  221. case $state in
  222. (command)
  223. declare -a commands
  224. commands=(
  225. 'update:update git-extras'
  226. )
  227. _describe -t commands command commands && ret=0
  228. ;;
  229. esac
  230. _arguments \
  231. '(-v --version)'{-v,--version}'[show current version]'
  232. }
  233. _git-feature() {
  234. local curcontext=$curcontext state line ret=1
  235. declare -A opt_args
  236. _arguments -C \
  237. ': :->command' \
  238. '*:: :->option-or-argument' && ret=0
  239. case $state in
  240. (command)
  241. declare -a commands
  242. commands=(
  243. 'finish:merge feature into the current branch'
  244. )
  245. _describe -t commands command commands && ret=0
  246. ;;
  247. (option-or-argument)
  248. curcontext=${curcontext%:*}-$line[1]:
  249. case $line[1] in
  250. (finish)
  251. _arguments -C \
  252. ':branch-name:__gitex_feature_branch_names'
  253. ;;
  254. -r|--remote )
  255. _arguments -C \
  256. ':remote-name:__gitex_remote_names'
  257. ;;
  258. esac
  259. return 0
  260. esac
  261. _arguments \
  262. '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
  263. }
  264. _git-graft() {
  265. _arguments \
  266. ':src-branch-name:__gitex_branch_names' \
  267. ':dest-branch-name:__gitex_branch_names'
  268. }
  269. _git-guilt() {
  270. _arguments -C \
  271. '(--email -e)'{--email,-e}'[display author emails instead of names]' \
  272. '(--ignore-whitespace -w)'{--ignore-whitespace,-w}'[ignore whitespace only changes]' \
  273. '(--debug -d)'{--debug,-d}'[output debug information]' \
  274. '-h[output usage information]'
  275. }
  276. _git-ignore() {
  277. _arguments -C \
  278. '(--local -l)'{--local,-l}'[show local gitignore]' \
  279. '(--global -g)'{--global,-g}'[show global gitignore]' \
  280. '(--private -p)'{--private,-p}'[show repo gitignore]'
  281. }
  282. _git-ignore() {
  283. _arguments -C \
  284. '(--append -a)'{--append,-a}'[append .gitignore]' \
  285. '(--replace -r)'{--replace,-r}'[replace .gitignore]' \
  286. '(--list-in-table -l)'{--list-in-table,-l}'[print available types in table format]' \
  287. '(--list-alphabetically -L)'{--list-alphabetically,-L}'[print available types in alphabetical order]' \
  288. '(--search -s)'{--search,-s}'[search word in available types]'
  289. }
  290. _git-merge-into() {
  291. _arguments '--ff-only[merge only fast-forward]'
  292. _arguments \
  293. ':src:__gitex_branch_names' \
  294. ':dest:__gitex_branch_names'
  295. }
  296. _git-missing() {
  297. _arguments \
  298. ':first-branch-name:__gitex_branch_names' \
  299. ':second-branch-name:__gitex_branch_names'
  300. }
  301. _git-refactor() {
  302. local curcontext=$curcontext state line ret=1
  303. declare -A opt_args
  304. _arguments -C \
  305. ': :->command' \
  306. '*:: :->option-or-argument' && ret=0
  307. case $state in
  308. (command)
  309. declare -a commands
  310. commands=(
  311. 'finish:merge refactor into the current branch'
  312. )
  313. _describe -t commands command commands && ret=0
  314. ;;
  315. (option-or-argument)
  316. curcontext=${curcontext%:*}-$line[1]:
  317. case $line[1] in
  318. (finish)
  319. _arguments -C \
  320. ':branch-name:__gitex_refactor_branch_names'
  321. ;;
  322. -r|--remote )
  323. _arguments -C \
  324. ':remote-name:__gitex_remote_names'
  325. ;;
  326. esac
  327. return 0
  328. esac
  329. _arguments \
  330. '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
  331. }
  332. _git-squash() {
  333. _arguments \
  334. ':branch-name:__gitex_branch_names'
  335. }
  336. _git-stamp() {
  337. _arguments -C \
  338. '(--replace -r)'{--replace,-r}'[replace stamps with same id]'
  339. }
  340. _git-standup() {
  341. _arguments -C \
  342. '-a[Specify the author of commits. Use "all" to specify all authors.]' \
  343. '-d[Show history since N days ago]' \
  344. '-D[Specify the date format displayed in commit history]' \
  345. '-f[Fetch commits before showing history]' \
  346. '-g[Display GPG signed info]' \
  347. '-h[Display help message]' \
  348. '-L[Enable the inclusion of symbolic links]' \
  349. '-m[The depth of recursive directory search]'
  350. }
  351. _git-summary() {
  352. _arguments '--line[summarize with lines rather than commits]'
  353. __gitex_commits
  354. }
  355. _git-undo(){
  356. _arguments -C \
  357. '(--soft -s)'{--soft,-s}'[only rolls back the commit but changes remain un-staged]' \
  358. '(--hard -h)'{--hard,-h}'[wipes your commit(s)]'
  359. }
  360. zstyle -g existing_user_commands ':completion:*:*:git:*' user-commands
  361. zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
  362. alias:'define, search and show aliases' \
  363. archive-file:'export the current head of the git repository to an archive' \
  364. authors:'generate authors report' \
  365. back:'undo and stage latest commits' \
  366. bug:'create bug branch' \
  367. bulk:'run bulk commands' \
  368. changelog:'generate a changelog report' \
  369. chore:'create chore branch' \
  370. clear-soft:'soft clean up a repository' \
  371. clear:'rigorously clean up a repository' \
  372. commits-since:'show commit logs since some date' \
  373. contrib:'show user contributions' \
  374. count:'show commit count' \
  375. create-branch:'create branches' \
  376. delete-branch:'delete branches' \
  377. delete-merged-branches:'delete merged branches' \
  378. delete-submodule:'delete submodules' \
  379. delete-tag:'delete tags' \
  380. delta:'lists changed files' \
  381. effort:'show effort statistics on file(s)' \
  382. extras:'awesome git utilities' \
  383. feature:'create/merge feature branch' \
  384. force-clone:'overwrite local repositories with clone' \
  385. fork:'fork a repo on GitHub' \
  386. fresh-branch:'create fresh branches' \
  387. gh-pages:'create the GitHub pages branch' \
  388. graft:'merge and destroy a given branch' \
  389. guilt:'calculate change between two revisions' \
  390. ignore-io:'get sample gitignore file' \
  391. ignore:'add .gitignore patterns' \
  392. info:'returns information on current repository' \
  393. local-commits:'list local commits' \
  394. lock:'lock a file excluded from version control' \
  395. locked:'ls files that have been locked' \
  396. merge-into:'merge one branch into another' \
  397. merge-repo:'merge two repo histories' \
  398. missing:'show commits missing from another branch' \
  399. mr:'checks out a merge request locally' \
  400. obliterate:'rewrite past commits to remove some files' \
  401. pr:'checks out a pull request locally' \
  402. psykorebase:'rebase a branch with a merge commit' \
  403. pull-request:'create pull request to GitHub project' \
  404. reauthor:'replace the author and/or committer identities in commits and tags' \
  405. rebase-patch:'rebases a patch' \
  406. refactor:'create refactor branch' \
  407. release:'commit, tag and push changes to the repository' \
  408. rename-branch:'rename a branch' \
  409. rename-tag:'rename a tag' \
  410. repl:'git read-eval-print-loop' \
  411. reset-file:'reset one file' \
  412. root:'show path of root' \
  413. scp:'copy files to ssh compatible `git-remote`' \
  414. sed:'replace patterns in git-controlled files' \
  415. setup:'set up a git repository' \
  416. show-merged-branches:'show merged branches' \
  417. show-tree:'show branch tree of commit history' \
  418. show-unmerged-branches:'show unmerged branches' \
  419. squash:'import changes from a branch' \
  420. stamp:'stamp the last commit message' \
  421. standup:'recall the commit history' \
  422. summary:'show repository summary' \
  423. sync:'sync local branch with remote branch' \
  424. touch:'touch and add file to the index' \
  425. undo:'remove latest commits' \
  426. unlock:'unlock a file excluded from version control'