git_write_keyword.fish 957 B

12345678910111213141516171819202122232425
  1. function git_write_keyword --description 'Write git in terminal prompt'
  2. set -l cmd (commandline -po)
  3. set -l cursor (commandline -C)
  4. set -l keywords 'git commit' 'git add' 'git stash'
  5. if test "$cmd[1]" != 'git'
  6. commandline -C 0
  7. commandline -i 'git '
  8. commandline -C (math $cursor + 4)
  9. else if test (commandline -p) = 'git '
  10. commandline -r $keywords[1]
  11. commandline -C (string length $keywords[1])
  12. else if test (commandline -p) = $keywords[1]
  13. commandline -r $keywords[2]
  14. commandline -C (string length $keywords[2])
  15. else if test (commandline -p) = $keywords[2]
  16. commandline -r $keywords[3]
  17. commandline -C (string length $keywords[3])
  18. else if test (commandline -p) = $keywords[3]
  19. commandline -r ''
  20. commandline -C 0
  21. else
  22. commandline -r (string sub --start=5 (commandline -p))
  23. commandline -C -- (math $cursor - 4)
  24. end
  25. end