jj.plugin.zsh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # if jj is not found, don't do the rest of the script
  2. if (( ! $+commands[jj] )); then
  3. return
  4. fi
  5. # If the completion file doesn't exist yet, we need to autoload it and
  6. # bind it to `jj`. Otherwise, compinit will have already done that.
  7. if [[ ! -f "$ZSH_CACHE_DIR/completions/_jj" ]]; then
  8. typeset -g -A _comps
  9. autoload -Uz _jj
  10. _comps[jj]=_jj
  11. fi
  12. COMPLETE=zsh jj >| "$ZSH_CACHE_DIR/completions/_jj" &|
  13. function __jj_prompt_jj() {
  14. local -a flags
  15. flags=("--no-pager")
  16. if zstyle -t ':omz:plugins:jj' ignore-working-copy; then
  17. flags+=("--ignore-working-copy")
  18. fi
  19. command jj $flags "$@"
  20. }
  21. # convenience functions for themes
  22. function jj_prompt_template_raw() {
  23. __jj_prompt_jj log --no-graph -r @ -T "$@" 2> /dev/null
  24. }
  25. function jj_prompt_template() {
  26. local out
  27. out=$(jj_prompt_template_raw "$@") || return 1
  28. echo "${out:gs/%/%%}"
  29. }
  30. # Aliases (sorted alphabetically)
  31. alias jjc='jj commit'
  32. alias jjcmsg='jj commit --message'
  33. alias jjd='jj diff'
  34. alias jjdmsg='jj desc --message'
  35. alias jjds='jj desc'
  36. alias jje='jj edit'
  37. alias jjgcl='jj git clone'
  38. alias jjgf='jj git fetch'
  39. alias jjgp='jj git push'
  40. alias jjl='jj log'
  41. alias jjla='jj log -r "all()"'
  42. alias jjn='jj new'
  43. alias jjrb='jj rebase'
  44. alias jjrs='jj restore'
  45. alias jjrt='cd "$(jj root || echo .)"'
  46. alias jjsp='jj split'
  47. alias jjsq='jj squash'