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.

186 lines
7.9 KiB

  1. # fish completion for gl (gitless)
  2. set -x __fish_gl_command_list track untrack status diff commit branch tag checkout merge resolve fuse remote publish switch init history
  3. function __fish_gl_commands
  4. for command in $__fish_gl_command_list
  5. switch $command
  6. case "track"
  7. printf "$command\tstart tracking changes to files\n"
  8. case "untrack"
  9. printf "$command\tstop tracking changes to files\n"
  10. case "status"
  11. printf "$command\tshow status of the repo\n"
  12. case "diff"
  13. printf "$command\tshow changes to files\n"
  14. case "commit"
  15. printf "$command\tsave changes to the local repository\n"
  16. case "branch"
  17. printf "$command\tlist, create, delete, or edit branches\n"
  18. case "tag"
  19. printf "$command\tlist, create, or delete tags\n"
  20. case "checkout"
  21. printf "$command\tcheckout committed versions of files\n"
  22. case "merge"
  23. printf "$command\tmerge the divergent changes of one branch onto another\n"
  24. case "resolve"
  25. printf "$command\tmark files with conflicts as resolved\n"
  26. case "fuse"
  27. printf "$command\tfuse the divergent changes of a branch onto the current branch\n"
  28. case "remote"
  29. printf "$command\tlist, create, edit or delete remotes\n"
  30. case "publish"
  31. printf "$command\tpublish commits upstream\n"
  32. case "switch"
  33. printf "$command\tswitch branches\n"
  34. case "init"
  35. printf "$command\tcreate an empty Gitless's repository or create one from an existing remote repository\n"
  36. case "history"
  37. printf "$command\tshow commit history\n"
  38. end
  39. end
  40. end
  41. function __fish_gl_get_command
  42. set -l cmdline (commandline -poc)
  43. if [ (count $cmdline) -gt 1 ]
  44. for command in $__fish_gl_command_list
  45. if [ "$cmdline[2]" = "$command" ]
  46. echo $cmdline[2]
  47. return 0
  48. end
  49. end
  50. end
  51. return 1
  52. end
  53. function __fish_gl_is_command --argument-names cmd
  54. if set -l token (__fish_gl_get_command)
  55. if [ "$token" = "$cmd" ]
  56. return 0
  57. end
  58. end
  59. return 1
  60. end
  61. function __fish_gl_needs_command
  62. not __fish_gl_get_command > /dev/null
  63. end
  64. function __fish_gl_list_tracked
  65. end
  66. function __fish_gl_list_untracked
  67. set -l output (gl status)
  68. set -l state 0
  69. for line in $output
  70. if [ $state -eq 0 ]
  71. if string match -q -r "Untracked" "$line"
  72. set state 1
  73. end
  74. else if [ $state -eq 1 ]
  75. if string match -q -r '^\s*$' "$line"
  76. set state 2
  77. end
  78. else if string match -q -v 'There are no untracked files to list' "$line"
  79. and string match -q -v -r '^\s*$' "$line"
  80. echo 1
  81. string replace -r '^\s+(.+)$' '$1' "$line"
  82. else
  83. echo 2
  84. break
  85. end
  86. end
  87. echo
  88. end
  89. function __fish_gl_list_tags
  90. set -l output (gl tag)
  91. for line in $output
  92. if string match -q -r '^\s{4}.+\s+tags [0-9a-f]{7,8}' "$line"
  93. string replace -r '^\s+(.*\w)\s+tags [0-9a-f]{7,8} (.+)$' '$1\t$2' "$line"
  94. end
  95. end
  96. end
  97. function __fish_gl_list_branches
  98. set -l output (gl branch)
  99. for line in $output
  100. if string match -q -r '^\s{4}\*?\s+.+' "$line"
  101. string replace -r '^\s+\*?\s+(.*\w)\s+\((.+)\)$' '$1\t$2' "$line"
  102. end
  103. end
  104. end
  105. function __fish_gl_list_remotes
  106. set -l output (gl remote)
  107. for line in $output
  108. if string match -q -r '^\s{4}.+ \(maps to' "$line"
  109. string replace -r '^\s+(.+) \(maps to (.+)\)$' '$1\t$2' "$line"
  110. end
  111. end
  112. end
  113. # global options
  114. complete -c gl -s h -l help -d "show help message and quit"
  115. complete -c gl -l version -d "show version number and exit"
  116. # subcommands
  117. complete -c gl -n "__fish_gl_needs_command" -x -a "(__fish_gl_commands)"
  118. # track
  119. complete -c gl -n "__fish_gl_is_command track" -r -f -a "(__fish_gl_list_untracked)"
  120. # untrack
  121. complete -c gl -n "__fish_gl_is_command untrack" -r #-f -a "(__fish_gl_list_tracked)"
  122. # status
  123. #complete -c gl -n "__fish_gl_is_command status" -f -a "(__fish_gl_list_tracked)"
  124. # diff
  125. complete -c gl -n "__fish_gl_is_command diff" -d "only these files" #-f -a "(__fish_gl_list_tracked)"
  126. complete -c gl -n "__fish_gl_is_command diff" -s e -l exclude -d "exclude files" #-f -a "(__fish_gl_list_tracked)"
  127. complete -c gl -n "__fish_gl_is_command diff" -s i -l include -d "include files" #-f -a "(__fish_gl_list_tracked)"
  128. # commit
  129. complete -c gl -n "__fish_gl_is_command commit" -s m -l message -f -d "commit message"
  130. complete -c gl -n "__fish_gl_is_command commit" -d "only these files" #-f -a "(__fish_gl_list_tracked)"
  131. complete -c gl -n "__fish_gl_is_command commit" -s e -l exclude -d "exclude files" #-f -a "(__fish_gl_list_tracked)"
  132. complete -c gl -n "__fish_gl_is_command commit" -s i -l include -d "include files" #-f -a "(__fish_gl_list_tracked)"
  133. complete -c gl -n "__fish_gl_is_command commit" -s p -l partial -d "partial commit"
  134. # branch
  135. complete -c gl -n "__fish_gl_is_command branch" -s r -l remote -f -d "also list remote branches"
  136. complete -c gl -n "__fish_gl_is_command branch" -s v -l verbose -f -d "be verbose"
  137. complete -c gl -n "__fish_gl_is_command branch" -s c -l create -f -d "create branch"
  138. complete -c gl -n "__fish_gl_is_command branch" -o dp -l divergent-point -f -d "commit from where to branch out"
  139. complete -c gl -n "__fish_gl_is_command branch" -s d -l delete -f -a "(__fish_gl_list_branch)" -d "delete branch"
  140. complete -c gl -n "__fish_gl_is_command branch" -o sh -l set-head -f -d "set head of the current branch"
  141. complete -c gl -n "__fish_gl_is_command branch" -o su -l set-upstream -f -d "set upstream branch of the current branch"
  142. complete -c gl -n "__fish_gl_is_command branch" -o uu -l unset-upstream -f -d "unset upstream branch of the current branch"
  143. # tag
  144. complete -c gl -n "__fish_gl_is_command tag" -s r -l remote -f -d "also list remote tags"
  145. complete -c gl -n "__fish_gl_is_command tag" -s c -l create -f -d "create tag"
  146. complete -c gl -n "__fish_gl_is_command tag" -o ci -l commit -f -d "the commit to tag"
  147. complete -c gl -n "__fish_gl_is_command tag" -s d -l delete -r -f -a "(__fish_gl_list_tags)" -d "delete tag"
  148. # checkout
  149. complete -c gl -n "__fish_gl_is_command checkout" -o cp -l commit-point -f -d "commit point to check out files at"
  150. # merge
  151. complete -c gl -n "__fish_gl_is_command merge" -s a -l abort -f -d "abort merge in progress"
  152. # resolve
  153. #complete -c gl -n "__fish_gl_is_command resolve" -f -a "(__fish_gl_list_tracked)"
  154. # fuse
  155. complete -c gl -n "__fish_gl_is_command fuse" -s o -l only -f -d "only these commits"
  156. complete -c gl -n "__fish_gl_is_command fuse" -s e -l exclude -f -d "exclude these commits"
  157. complete -c gl -n "__fish_gl_is_command fuse" -o ip -l insertion-point -f -d "insert divergent changes after the given commit"
  158. complete -c gl -n "__fish_gl_is_command fuse" -s a -l abort -f -d "abort fuse in progress"
  159. # remote
  160. complete -c gl -n "__fish_gl_is_command remote" -s c -l create -f -d "create remote"
  161. complete -c gl -n "__fish_gl_is_command remote" -s d -l delete -f -a "(__fish_gl_list_remotes)" -d "delete remote"
  162. # publish
  163. # switch
  164. complete -c gl -n "__fish_gl_is_command switch" -o mo -l move-over -f -d "move uncommitted changes to other branch"
  165. # init
  166. complete -c gl -n "__fish_gl_is_command init" -f -a "https://" -d "url of repo to clone"
  167. # history
  168. complete -c gl -n "__fish_gl_is_command history" -s v -l verbose -f -d "be verbose"
  169. complete -c gl -n "__fish_gl_is_command history" -s l -l limit -f -d "limit number of commits displayed"
  170. complete -c gl -n "__fish_gl_is_command history" -s c -l compact -f -d "output in compact format"
  171. complete -c gl -n "__fish_gl_is_command history" -s b -l branch -f -d "branch to show history of"