mirror of https://github.com/ohmyzsh/ohmyzsh.git
Compare commits
5 Commits
39e663afdc
...
32d22e9797
Author | SHA1 | Date |
---|---|---|
|
32d22e9797 | |
|
1c2127727a | |
|
30e516a3aa | |
|
d2f071f8dd | |
|
440b66da14 |
|
@ -1,7 +1,6 @@
|
|||
# git-commit plugin
|
||||
|
||||
The git-commit plugin adds several
|
||||
[git aliases](https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-alias) for
|
||||
The git-commit plugin adds several git subcommands for
|
||||
[conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) messages.
|
||||
|
||||
To use it, add `git-commit` to the plugins array in your zshrc file:
|
||||
|
@ -31,15 +30,13 @@ Where `type` is one of the following:
|
|||
- `test`
|
||||
- `wip`
|
||||
|
||||
> NOTE: the alias for `revert` type is `rev`, as otherwise it conflicts with the git command of the same name.
|
||||
> It will still generate a commit message in the format `revert: <message>`
|
||||
|
||||
> ⚠️ Enabling this plugin will (potentially) overwrite all `alias.<type>` that you manually set. Use with
|
||||
> care!
|
||||
> NOTE: the subcommand for `revert` type is `rev`, as otherwise it conflicts with the
|
||||
> git command of the same name. It will still generate a commit message in the format
|
||||
> `revert: <message>`
|
||||
|
||||
## Examples
|
||||
|
||||
| Git alias | Command |
|
||||
| Git subcommand | Command |
|
||||
| --------------------------------------------- | ---------------------------------------------------- |
|
||||
| `git style "remove trailing whitespace"` | `git commit -m "style: remove trailing whitespace"` |
|
||||
| `git wip "work in progress"` | `git commit -m "work in progress"` |
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1 @@
|
|||
./omz_git_commit
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
_omz_git_commit() {
|
||||
0=${(%):-%x}
|
||||
if [[ "$0" != */git-* ]]; then
|
||||
echo >&2 "Expecting command named git-foo. Got '$0'."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local _type="${0##*/git-}"
|
||||
local _scope _attention _message
|
||||
while [ $# -ne 0 ]; do
|
||||
case $1 in
|
||||
-s | --scope )
|
||||
if [ -z $2 ]; then
|
||||
echo >&2 "Missing scope!"
|
||||
return 1
|
||||
fi
|
||||
_scope="$2"
|
||||
shift 2
|
||||
;;
|
||||
-a | --attention )
|
||||
_attention="!"
|
||||
shift 1
|
||||
;;
|
||||
* )
|
||||
_message="${_message} $1"
|
||||
shift 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
git commit -m "${_type}${_scope:+(${_scope})}${_attention}:${_message}"
|
||||
}
|
||||
_omz_git_commit "$@"
|
|
@ -1,58 +1,48 @@
|
|||
local _rev="$(git -C $ZSH rev-parse HEAD 2> /dev/null)"
|
||||
if [[ $_rev == $(git config --global --get oh-my-zsh.git-commit-alias 2> /dev/null) ]]; then
|
||||
return
|
||||
fi
|
||||
git config --global oh-my-zsh.git-commit-alias "$_rev"
|
||||
# Add git-commit commands directory to path
|
||||
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
||||
0="${${(M)0:#/*}:-$PWD/$0}"
|
||||
path=("${0:a:h}/git-commands" $path)
|
||||
|
||||
local -a _git_commit_aliases
|
||||
_git_commit_aliases=(
|
||||
'build'
|
||||
'chore'
|
||||
'ci'
|
||||
'docs'
|
||||
'feat'
|
||||
'fix'
|
||||
'perf'
|
||||
'refactor'
|
||||
'revert'
|
||||
'style'
|
||||
'test'
|
||||
'wip'
|
||||
# Append completions for custom git commands
|
||||
() {
|
||||
local -a git_user_commands
|
||||
zstyle -a ':completion:*:*:git:*' user-commands 'git_user_commands' \
|
||||
|| git_user_commands=()
|
||||
git_user_commands+=(
|
||||
build:'Commit with a message indicating a build' \
|
||||
chore:'Commit with a message indicating a chore' \
|
||||
ci:'Commit with a message indicating a CI change' \
|
||||
docs:'Commit with a message indicating an update to the documentation' \
|
||||
feat:'Commit with a message indicating a feature' \
|
||||
fix:'Commit with a message indicating a fix' \
|
||||
perf:'Commit with a message indicating a performance enhancement' \
|
||||
refactor:'Commit with a message indicating a refactor' \
|
||||
revert:'Commit with a message indicating a revert' \
|
||||
style:'Commit with a message indicating a style change' \
|
||||
test:'Commit with a message indicating updates to tests' \
|
||||
wip:'Commit with a message indicating a work in progress'
|
||||
)
|
||||
zstyle ':completion:*:*:git:*' user-commands "${git_user_commands[@]}"
|
||||
}
|
||||
|
||||
local _alias _type
|
||||
for _type in "${_git_commit_aliases[@]}"; do
|
||||
# an alias can't be named "revert" because the git command takes precedence
|
||||
# https://stackoverflow.com/a/3538791
|
||||
case "$_type" in
|
||||
revert) _alias=rev ;;
|
||||
*) _alias=$_type ;;
|
||||
esac
|
||||
|
||||
local _func='!a() {
|
||||
local _scope _attention _message
|
||||
while [ $# -ne 0 ]; do
|
||||
case $1 in
|
||||
-s | --scope )
|
||||
if [ -z $2 ]; then
|
||||
echo "Missing scope!"
|
||||
return 1
|
||||
########################################################################################
|
||||
### Remove below after Jan 2025:
|
||||
########################################################################################
|
||||
# Clean up aliases from the prior implementation of git-commit. Can be safely removed
|
||||
# once everyone's .gitconfig has been restored.
|
||||
() {
|
||||
git config --global --get oh-my-zsh.git-commit-alias &> /dev/null || return 0
|
||||
local -a old_git_aliases=(
|
||||
'build' 'chore' 'ci'
|
||||
'docs' 'feat' 'fix'
|
||||
'perf' 'refactor' 'rev'
|
||||
'style' 'test' 'wip'
|
||||
)
|
||||
local git_alias
|
||||
for git_alias in $old_git_aliases; do
|
||||
if [[ "$(git config --global --get alias.$git_alias | tr '\n' ' ')" == "!a() { local _scope _attention _message"* ]]; then
|
||||
git config --global --unset alias.$git_alias
|
||||
fi
|
||||
_scope="$2"
|
||||
shift 2
|
||||
;;
|
||||
-a | --attention )
|
||||
_attention="!"
|
||||
shift 1
|
||||
;;
|
||||
* )
|
||||
_message="${_message} $1"
|
||||
shift 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
git commit -m "'$_type'${_scope:+(${_scope})}${_attention}:${_message}"
|
||||
}; a'
|
||||
|
||||
git config --global alias.$_alias "$_func"
|
||||
done
|
||||
git config --global --unset oh-my-zsh.git-commit-alias
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
# jj - Jujutsu CLI
|
||||
|
||||
This plugin provides autocompletion for [jj](https://martinvonz.github.io/jj).
|
||||
|
||||
To use it, add `jj` to the plugins array of your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... jj)
|
||||
```
|
||||
|
||||
## Aliases
|
||||
|
||||
| Alias | Command |
|
||||
| ------ | ----------------------------- |
|
||||
| jjc | `jj commit` |
|
||||
| jjcmsg | `jj commit --message` |
|
||||
| jjd | `jj diff` |
|
||||
| jjdmsg | `jj desc --message` |
|
||||
| jjds | `jj desc` |
|
||||
| jje | `jj edit` |
|
||||
| jjgcl | `jj git clone` |
|
||||
| jjgf | `jj git fetch` |
|
||||
| jjgp | `jj git push` |
|
||||
| jjl | `jj log` |
|
||||
| jjla | `jj log -r "all()"` |
|
||||
| jjn | `jj new` |
|
||||
| jjrb | `jj rebase` |
|
||||
| jjrs | `jj restore` |
|
||||
| jjrt | `cd "$(jj root \|\| echo .)"` |
|
||||
| jjsp | `jj split` |
|
||||
| jjsq | `jj squash` |
|
||||
|
||||
## Prompt usage
|
||||
|
||||
Because `jj` has a very powerful [template syntax](https://martinvonz.github.io/jj/latest/templates/), this
|
||||
plugin only exposes a convenience function `jj_prompt_template` to read information from the current change.
|
||||
It is basically the same as `jj log --no-graph -r @ -T $1`:
|
||||
|
||||
```sh
|
||||
_my_theme_jj_info() {
|
||||
jj_prompt_template 'self.change_id().shortest(3)'
|
||||
}
|
||||
|
||||
PROMPT='$(_my_theme_jj_info) $'
|
||||
```
|
||||
|
||||
`jj_prompt_template` escapes `%` signs in the output. Use `jj_prompt_template_raw` if you don't want that
|
||||
(e.g. to colorize the output).
|
||||
|
||||
However, because `jj` can be used inside a Git repository, some themes might clash with it. Generally, you can
|
||||
fix it with a wrapper function that tries `jj` first and then falls back to `git` if it didn't work:
|
||||
|
||||
```sh
|
||||
_my_theme_vcs_info() {
|
||||
jj_prompt_template 'self.change_id().shortest(3)' \
|
||||
|| git_prompt_info
|
||||
}
|
||||
|
||||
PROMPT='$(_my_theme_vcs_info) $'
|
||||
```
|
||||
|
||||
You can find an example
|
||||
[here](https://github.com/nasso/omzsh/blob/e439e494f22f4fd4ef1b6cb64626255f4b341c1b/themes/sunakayu.zsh-theme).
|
||||
|
||||
### Performance
|
||||
|
||||
Sometimes `jj` can be slower than `git`.
|
||||
|
||||
If you feel slowdowns, consider using the following:
|
||||
|
||||
```
|
||||
zstyle :omz:plugins:jj ignore-working-copy yes
|
||||
```
|
||||
|
||||
This will add `--ignore-working-copy` to all `jj` commands executed by your prompt. The downside here is that
|
||||
your prompt might be out-of-sync until the next time `jj` gets a chance to _not_ ignore the working copy (i.e.
|
||||
you manually run a `jj` command).
|
||||
|
||||
If you prefer to keep your prompt always up-to-date but still don't want to _feel_ the slowdown, you can make
|
||||
your prompt asynchronous. This plugin doesn't do this automatically so you'd have to hack your theme a bit for
|
||||
that.
|
||||
|
||||
## See Also
|
||||
|
||||
- [martinvonz/jj](https://github.com/martinvonz/jj)
|
||||
|
||||
## Contributors
|
||||
|
||||
- [nasso](https://github.com/nasso) - Plugin Author
|
|
@ -0,0 +1,53 @@
|
|||
# if jj is not found, don't do the rest of the script
|
||||
if (( ! $+commands[jj] )); then
|
||||
return
|
||||
fi
|
||||
|
||||
# If the completion file doesn't exist yet, we need to autoload it and
|
||||
# bind it to `jj`. Otherwise, compinit will have already done that.
|
||||
if [[ ! -f "$ZSH_CACHE_DIR/completions/_jj" ]]; then
|
||||
typeset -g -A _comps
|
||||
autoload -Uz _jj
|
||||
_comps[jj]=_jj
|
||||
fi
|
||||
|
||||
COMPLETE=zsh jj >| "$ZSH_CACHE_DIR/completions/_jj" &|
|
||||
|
||||
function __jj_prompt_jj() {
|
||||
local -a flags
|
||||
flags=("--no-pager")
|
||||
if zstyle -t ':omz:plugins:jj' ignore-working-copy; then
|
||||
flags+=("--ignore-working-copy")
|
||||
fi
|
||||
command jj $flags "$@"
|
||||
}
|
||||
|
||||
# convenience functions for themes
|
||||
function jj_prompt_template_raw() {
|
||||
__jj_prompt_jj log --no-graph -r @ -T "$@" 2> /dev/null
|
||||
}
|
||||
|
||||
function jj_prompt_template() {
|
||||
local out
|
||||
out=$(jj_prompt_template_raw "$@") || return 1
|
||||
echo "${out:gs/%/%%}"
|
||||
}
|
||||
|
||||
# Aliases (sorted alphabetically)
|
||||
alias jjc='jj commit'
|
||||
alias jjcmsg='jj commit --message'
|
||||
alias jjd='jj diff'
|
||||
alias jjdmsg='jj desc --message'
|
||||
alias jjds='jj desc'
|
||||
alias jje='jj edit'
|
||||
alias jjgcl='jj git clone'
|
||||
alias jjgf='jj git fetch'
|
||||
alias jjgp='jj git push'
|
||||
alias jjl='jj log'
|
||||
alias jjla='jj log -r "all()"'
|
||||
alias jjn='jj new'
|
||||
alias jjrb='jj rebase'
|
||||
alias jjrs='jj restore'
|
||||
alias jjrt='cd "$(jj root || echo .)"'
|
||||
alias jjsp='jj split'
|
||||
alias jjsq='jj squash'
|
Loading…
Reference in New Issue