Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. use re
  2. use str
  3. use util
  4. use github.com/xiaq/edit.elv/compl/git
  5. git:apply
  6. fn overlap-at [a b]{
  7. for i [(range 1 (- (count $b) 1))] {
  8. if (has-value $a $b[$i]) { put $i; return }
  9. }
  10. put $false
  11. }
  12. fn prefix-completer [p a]{
  13. edit:completion:arg-completer[$p] = [@cmd]{
  14. if (eq (count $cmd) 2) {
  15. $a $@cmd
  16. } elif (has-key $edit:completion:arg-completer $cmd[1]) {
  17. $edit:completion:arg-completer[$cmd[1]] (all $cmd[1:])
  18. } else {
  19. edit:complete-filename $cmd[-1]
  20. }
  21. }
  22. }
  23. fn complete-directory [a]{
  24. dir = (path-dir $a)/
  25. if (has-prefix $a $dir) {
  26. a = (str:replace &max=1 $dir '' $a)
  27. } else {
  28. dir = ''
  29. }
  30. for x [$dir*[match-hidden][nomatch-ok]$a*[match-hidden][nomatch-ok]] {
  31. if (-is-dir $x) { edit:complex-candidate &code-suffix=/ &style='blue;bold' $x }
  32. }
  33. }
  34. edit:completion:arg-completer[cd] = [@cmd]{
  35. if (eq (count $cmd) 2) {
  36. complete-directory $cmd[1]
  37. }
  38. }
  39. edit:completion:arg-completer[kak] = [@cmd]{
  40. if (eq $cmd[-2] -c) {
  41. kak -l
  42. } else {
  43. edit:complete-filename $cmd[-1]
  44. }
  45. }
  46. edit:completion:arg-completer[waifu2x-converter-cpp] = [@cmd]{
  47. if (has-value [-i --input -o --output] $cmd[-2]) {
  48. edit:complete-filename $cmd[-1]
  49. } elif (has-value [-m --mode] $cmd[-2]) {
  50. put noise scale noise-scale
  51. } elif (eq $cmd[-2] --noise-level) {
  52. put 0 1 2 3
  53. } else {
  54. put --scale-ratio --noise-level --mode --jobs --png-compression \
  55. --image-quality --silent -i -o
  56. }
  57. }
  58. kitty-cmds = $nil
  59. kitty-kittens = $nil
  60. edit:completion:arg-completer[kitty] = [@cmd]{
  61. if (not $kitty-cmds) {
  62. @kitty-cmds = (kitty @ --help | peach [x]{ if (re:match '^ \w' $x) { put $x[2:] } })
  63. @kitty-kittens = (pwd=/usr/lib/kitty/kittens fd main.py | peach [x]{ path-dir $x })
  64. }
  65. if (has-value [kitten '+kitten'] $cmd[-2]) {
  66. all $kitty-kittens
  67. } elif (eq $cmd[-2] '@') {
  68. all $kitty-cmds
  69. } else {
  70. edit:complete-filename $cmd[-1]
  71. }
  72. }
  73. edit:completion:arg-completer[sv] = [@cmd]{
  74. if (eq (count $cmd) 2) {
  75. put status up down once pause cont hup alarm interrupt quit kill term 1 2 \
  76. exit start try-restart check {force-,}{stop,reload,restart,shutdown}
  77. } else {
  78. pwd=/var/service put *
  79. }
  80. }
  81. edit:completion:arg-completer[man] = [@cmd]{
  82. pwd=/bedrock/cross/man put man*/* | each [a]{
  83. re:replace &literal=$true '(\.\dp?)?(\.gz)?$' '' (path-base $a)
  84. }
  85. }
  86. edit:completion:arg-completer[kill] = [@cmd]{
  87. ps -u (whoami) --no-headers -o pid,command |\
  88. eawk [_ p @c]{ edit:complex-candidate &display=(print ' '$@c) $p }
  89. }
  90. edit:completion:arg-completer[nimble] = [@cmd]{
  91. if (eq (count $cmd) 2) {
  92. put {un,}install develop check init publish build c cc js test doc{,2} \
  93. refresh search list tasks path dump
  94. if ?(isnimbleproject) {
  95. nimble tasks 2>&- | eawk [_ a @_]{ put $a }
  96. }
  97. } elif (eq $cmd[-2] install) {
  98. for x (from-json <~/.nimble/packages_official.json) { put $x[name] }
  99. } elif (eq $cmd[-2] uninstall) {
  100. idx = (util:index-of $cmd[-1] '@')
  101. if (== $idx -1) {
  102. nimble list -i | eawk [_ n @_]{ put $n }
  103. } else {
  104. pkgs = [&]
  105. nimble list -i | eawk [_ n @v]{
  106. @ver = $@v[:-1]
  107. ver[0] = $ver[0][1:]
  108. pkgs[$n] = $ver
  109. }
  110. pkg = $cmd[-1][:$idx]
  111. if (has-key $pkgs $pkg) {
  112. for v $pkgs[$pkg] { put $pkg@$v }
  113. }
  114. }
  115. }
  116. }
  117. pijul-cmds = [add apply branches checkout clone credit delete-branch diff dist\
  118. generate-completions help init key log ls mv patch pull push\
  119. record remove revert rollback show-dependencies sign status tag unrecord]
  120. edit:completion:arg-completer[pijul] = [@cmd]{
  121. if (eq (count $cmd) 2) {
  122. all $pijul-cmds
  123. }
  124. }
  125. neofetch-img = [ascii caca iterm2 jp2a kitty pixterm sixel termpix tycat w3m off]
  126. neofetch-opts = $nil
  127. edit:completion:arg-completer[neofetch] = [@cmd]{
  128. if (not $neofetch-opts) {
  129. neofetch-opts = [(_ = ?(neofetch --help | each [x]{
  130. if (has-prefix $x ' --') {
  131. put $x | eawk [_ a @_]{ put $a }
  132. }
  133. })) --logo -L -v -vv]
  134. }
  135. all $neofetch-opts
  136. }
  137. edit:completion:arg-completer[bspc] = [@cmd]{
  138. if (eq (count $cmd) 2) {
  139. put node desktop monitor query wm rule config subscribe quit
  140. } elif (eq $cmd[1] subscribe) {
  141. put all report monitor desktop node pointer
  142. } elif (eq $cmd[1] rule) {
  143. put --add --remove --list
  144. } elif (eq $cmd[1] wm) {
  145. put --dump-state --load-state --add-monitor --adopt-orphans --record-history --get-status
  146. } elif (eq $cmd[1] query) {
  147. put --nodes --desktops --monitors --tree
  148. }
  149. }
  150. edit:completion:arg-completer[ntr] = [@cmd]{
  151. if (not (has-prefix $cmd[-1] '-')) {
  152. pwd=$E:XDG_CONFIG_HOME/ntr/contexts put **
  153. }
  154. }
  155. edit:completion:arg-completer[mpv] = [@cmd]{
  156. if (and (> (count $cmd[-1]) 0) (eq $cmd[-1][0] '-')) {
  157. mpv --list-options | drop 2 | take 872 | eawk [_ a @b]{
  158. if (eq (count $b) 0) {
  159. put $a
  160. } else {
  161. edit:complex-candidate $a &display=' '(str:join ' ' $b)
  162. }
  163. }
  164. } else {
  165. edit:complete-filename $cmd[-1]
  166. }
  167. }
  168. edit:completion:arg-completer[update] = [@cmd]{
  169. update | each [x]{ if (has-prefix $x " ") { put $x[4:] } }
  170. }
  171. edit:completion:arg-completer[xr] = [@cmd]{
  172. xpkg -m
  173. xpkg -O | peach [x]{ edit:complex-candidate &style='red;inverse' $x }
  174. }
  175. edit:completion:arg-completer[xi] = [@cmd]{
  176. pwd=$E:XBPS_DISTDIR/srcpkgs put *
  177. }
  178. xbps-src-cmds = $nil
  179. xbps-src-arch = $nil
  180. edit:completion:arg-completer[xbps-src] = [@cmd]{
  181. if (not $xbps-src-cmds) {
  182. @xbps-src-cmds = (xbps-src -h | take 129 | drop 4 | each [x]{ put (re:find &max=1 '^\w+(\-\w+)*' $x)[text] })
  183. @xbps-src-arch = (xbps-src -h | take 162 | drop 136)[1:]
  184. }
  185. if (eq $cmd[-2] '-a') {
  186. all $xbps-src-arch
  187. } else {
  188. if (not (overlap-at $xbps-src-cmds $cmd)) {
  189. all $xbps-src-cmds
  190. } else {
  191. pwd=$E:XBPS_DISTDIR/srcpkgs put *
  192. }
  193. }
  194. }
  195. edit:completion:arg-completer[strat] = [@cmd]{
  196. @strata = (brl list)
  197. has-strat = (overlap-at $strata $cmd)
  198. if (not $has-strat) {
  199. all $strata
  200. } else {
  201. edit:complete-sudo (all $cmd[(put $has-strat):])
  202. }
  203. }
  204. brl-cmds = $nil
  205. edit:completion:arg-completer[brl] = [@cmd]{
  206. if (not $brl-cmds) {
  207. @brl-cmds = (brl -h | take 36 | drop 5 | each [x]{ put (re:find &max=1 '^ \w+' $x)[text][2:] })
  208. }
  209. len = (count $cmd)
  210. if (== $len 2) {
  211. all $brl-cmds
  212. } else {
  213. c = $cmd[1]
  214. if (has-value [status enable disable hide show] $c) {
  215. brl list
  216. } elif (eq $c fetch) {
  217. brl fetch -L
  218. }
  219. }
  220. }
  221. edit:completion:arg-completer[tam] = [@cmd]{
  222. if (== (count $cmd) 2) {
  223. put install uninstall enable disable update list query search
  224. } else {
  225. c = $cmd[1]
  226. if (has-value [uninstall update query] $c) {
  227. tam list -s
  228. } elif (eq $c enable) {
  229. tam list -s -d
  230. } elif (eq $c disable) {
  231. tam list -s -e
  232. } elif (eq $c list) {
  233. put '--short' '--enabled' '--disabled'
  234. }
  235. }
  236. }
  237. edit:completion:arg-completer[promotescript] = [@cmd]{
  238. pwd=~/.local/bin fd -t f
  239. }
  240. edit:completion:arg-completer[edit-script] = $edit:complete-sudo~
  241. edit:completion:arg-completer[whereis] = $edit:complete-sudo~
  242. edit:completion:arg-completer[which] = $edit:complete-sudo~
  243. edit:completion:arg-completer[xq] = $edit:completion:arg-completer[xi]
  244. edit:completion:arg-completer[xqt] = $edit:completion:arg-completer[xi]
  245. edit:completion:arg-completer[xbps-install] = $edit:completion:arg-completer[xi]
  246. prefixes = [
  247. &sudo=$edit:complete-sudo~
  248. &strace=$edit:complete-sudo~
  249. &time=$edit:complete-sudo~
  250. &torify=$edit:complete-sudo~
  251. ]
  252. for k [(keys $prefixes)] { prefix-completer $k $prefixes[$k] }