jj.plugin.zsh
1982 bytes
1# if jj is not found, don't do the rest of the script
2if (( ! $+commands[jj] )); then
3 return
4fi
5
6# If the completion file doesn't exist yet, we need to autoload it and
7# bind it to `jj`. Otherwise, compinit will have already done that.
8if [[ ! -f "$ZSH_CACHE_DIR/completions/_jj" ]]; then
9 typeset -g -A _comps
10 autoload -Uz _jj
11 _comps[jj]=_jj
12fi
13
14COMPLETE=zsh jj >| "$ZSH_CACHE_DIR/completions/_jj" &|
15
16function __jj_prompt_jj() {
17 local -a flags
18 flags=("--no-pager")
19 if zstyle -t ':omz:plugins:jj' ignore-working-copy; then
20 flags+=("--ignore-working-copy")
21 fi
22 command jj $flags "$@"
23}
24
25# convenience functions for themes
26function jj_prompt_template_raw() {
27 __jj_prompt_jj log --no-graph -r @ -T "$@" 2> /dev/null
28}
29
30function jj_prompt_template() {
31 local out
32 out=$(jj_prompt_template_raw "$@") || return 1
33 echo "${out:gs/%/%%}"
34}
35
36# Aliases (sorted alphabetically)
37alias jja='jj abandon'
38alias jjb='jj bookmark'
39alias jjba='jj bookmark advance'
40alias jjbc='jj bookmark create'
41alias jjbd='jj bookmark delete'
42alias jjbf='jj bookmark forget'
43alias jjbl='jj bookmark list'
44alias jjbm='jj bookmark move'
45alias jjbr='jj bookmark rename'
46alias jjbs='jj bookmark set'
47alias jjbt='jj bookmark track'
48alias jjbu='jj bookmark untrack'
49alias jjc='jj commit'
50alias jjcmsg='jj commit --message'
51alias jjd='jj diff'
52alias jjdmsg='jj desc --message'
53alias jjds='jj desc'
54alias jje='jj edit'
55alias jjgcl='jj git clone'
56alias jjgf='jj git fetch'
57alias jjgfa='jj git fetch --all-remotes'
58alias jjgp='jj git push'
59alias jjgpa='jj git push --all'
60alias jjgpd='jj git push --deleted'
61alias jjgpt='jj git push --tracked'
62alias jjl='jj log'
63alias jjla='jj log -r "all()"'
64alias jjn='jj new'
65alias jjnt='jj new "trunk()"'
66alias jjrb='jj rebase'
67alias jjrbm='jj rebase -d "trunk()"'
68alias jjrs='jj restore'
69alias jjrt='cd "$(jj root || echo .)"'
70alias jjsp='jj split'
71alias jjsq='jj squash'
72alias jjst='jj status'
73alias jjwa='jj workspace add'
74alias jjwf='jj workspace forget'
75