mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-10-16 11:40:46 +00:00
Compare commits
7 commits
0e537c03b5
...
c33da7f187
Author | SHA1 | Date | |
---|---|---|---|
|
c33da7f187 | ||
|
1514145a09 | ||
|
99e2c31484 | ||
|
e52598a5cc | ||
|
d91944d47e | ||
|
865291cb7a | ||
|
1bc00257fb |
10 changed files with 168 additions and 28 deletions
12
lib/git.zsh
12
lib/git.zsh
|
@ -162,6 +162,18 @@ function git_current_branch() {
|
|||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
# Outputs the name of the previously checked out branch
|
||||
# Usage example: git pull origin $(git_current_branch)
|
||||
# rev-parse --symbolic-full-name @{-1} only prints if it is a branch
|
||||
function git_previous_branch() {
|
||||
local ref
|
||||
ref=$(__git_prompt_git rev-parse --quiet --symbolic-full-name @{-1} 2> /dev/null)
|
||||
local ret=$?
|
||||
if [[ $ret != 0 ]] || [[ -z $ref ]]; then
|
||||
return # no git repo or non-branch previous ref
|
||||
fi
|
||||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
# Gets the number of commits ahead from remote
|
||||
function git_commits_ahead() {
|
||||
|
|
61
plugins/jj/README.md
Normal file
61
plugins/jj/README.md
Normal file
|
@ -0,0 +1,61 @@
|
|||
# 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)
|
||||
```
|
||||
|
||||
## 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, you can try adding `ZSH_THEME_JJ_IGNORE_WORKING_COPY=1` to your theme, which will add
|
||||
`--ignore-working-copy` to all calls made to `jj`. The downside here is that your prompt might stay outdated
|
||||
until the next time `jj` gets a chance to _not_ ignore the working copy.
|
||||
|
||||
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
|
55
plugins/jj/jj.plugin.zsh
Normal file
55
plugins/jj/jj.plugin.zsh
Normal file
|
@ -0,0 +1,55 @@
|
|||
# if jj is not found, don't do the rest of the script
|
||||
if (( ! $+commands[jj] )); then
|
||||
return
|
||||
fi
|
||||
|
||||
source <(jj util completion zsh)
|
||||
compdef _jj jj
|
||||
|
||||
function __jj_prompt_jj() {
|
||||
local flags=("--no-pager")
|
||||
if (( ${ZSH_THEME_JJ_IGNORE_WORKING_COPY:-0} )); 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 j='jj'
|
||||
alias jb='jj branch'
|
||||
alias jbc='jj branch create'
|
||||
alias jbd='jj branch d'
|
||||
alias jbl='jj branch list'
|
||||
alias jbr='jj branch rename'
|
||||
alias jbs='jj branch set'
|
||||
alias jbt='jj branch track'
|
||||
alias jc='jj commit'
|
||||
alias jcmsg='jj commit --message'
|
||||
alias jd='jj diff'
|
||||
alias jdmsg='jj desc --message'
|
||||
alias jds='jj desc'
|
||||
alias je='jj edit'
|
||||
alias jgcl='jj git clone'
|
||||
alias jgf='jj git fetch'
|
||||
alias jgp='jj git push'
|
||||
alias jl='jj log'
|
||||
alias jn='jj new'
|
||||
alias jrb='jj rebase'
|
||||
alias jrs='jj restore'
|
||||
alias jrt='cd "$(jj root || echo .)"'
|
||||
alias js='jj squash'
|
||||
alias jsp='jj split'
|
||||
alias jsps='jj split --siblings'
|
||||
alias jst='jj st'
|
||||
alias jsto='jj squash --into'
|
|
@ -42,6 +42,8 @@ as you want:
|
|||
zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ...
|
||||
```
|
||||
|
||||
There will be a function `_omz_nvm_load` available to load `nvm` without executing any other trigger command.
|
||||
|
||||
#### `.nvmrc` autoload
|
||||
|
||||
Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_
|
||||
|
|
|
@ -20,7 +20,7 @@ if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then
|
|||
return
|
||||
fi
|
||||
|
||||
function _omz_load_nvm_completion {
|
||||
function _omz_nvm_setup_completion {
|
||||
local _nvm_completion
|
||||
# Load nvm bash completion
|
||||
for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
|
||||
|
@ -33,12 +33,12 @@ function _omz_load_nvm_completion {
|
|||
break
|
||||
fi
|
||||
done
|
||||
unfunction _omz_load_nvm_completion
|
||||
unfunction _omz_nvm_setup_completion
|
||||
}
|
||||
|
||||
function _omz_setup_autoload {
|
||||
function _omz_nvm_setup_autoload {
|
||||
if ! zstyle -t ':omz:plugins:nvm' autoload; then
|
||||
unfunction _omz_setup_autoload
|
||||
unfunction _omz_nvm_setup_autoload
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -68,13 +68,13 @@ function _omz_setup_autoload {
|
|||
add-zsh-hook chpwd load-nvmrc
|
||||
|
||||
load-nvmrc
|
||||
unfunction _omz_setup_autoload
|
||||
unfunction _omz_nvm_setup_autoload
|
||||
}
|
||||
|
||||
if zstyle -t ':omz:plugins:nvm' lazy; then
|
||||
# Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd
|
||||
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
|
||||
nvm_lazy_cmd=(nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
|
||||
nvm_lazy_cmd=(_omz_nvm_load nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
|
||||
eval "
|
||||
function $nvm_lazy_cmd {
|
||||
for func in $nvm_lazy_cmd; do
|
||||
|
@ -84,14 +84,16 @@ if zstyle -t ':omz:plugins:nvm' lazy; then
|
|||
done
|
||||
# Load nvm if it exists in \$NVM_DIR
|
||||
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
|
||||
_omz_load_nvm_completion
|
||||
_omz_setup_autoload
|
||||
_omz_nvm_setup_completion
|
||||
_omz_nvm_setup_autoload
|
||||
if [[ \"\$0\" != _omz_nvm_load ]]; then
|
||||
\"\$0\" \"\$@\"
|
||||
fi
|
||||
}
|
||||
"
|
||||
unset nvm_lazy_cmd
|
||||
else
|
||||
source "$NVM_DIR/nvm.sh"
|
||||
_omz_load_nvm_completion
|
||||
_omz_setup_autoload
|
||||
_omz_nvm_setup_completion
|
||||
_omz_nvm_setup_autoload
|
||||
fi
|
||||
|
|
|
@ -16,9 +16,10 @@ plugins=(... terraform)
|
|||
## Aliases
|
||||
|
||||
| Alias | Command |
|
||||
|--------|----------------------------|
|
||||
|---------|----------------------------------|
|
||||
| `tf` | `terraform` |
|
||||
| `tfa` | `terraform apply` |
|
||||
| `tfaa` | `terraform apply -auto-approve` |
|
||||
| `tfc` | `terraform console` |
|
||||
| `tfd` | `terraform destroy` |
|
||||
| `tff` | `terraform fmt` |
|
||||
|
|
|
@ -17,6 +17,7 @@ function tf_version_prompt_info() {
|
|||
|
||||
alias tf='terraform'
|
||||
alias tfa='terraform apply'
|
||||
alias tfaa='terraform apply -auto-approve'
|
||||
alias tfc='terraform console'
|
||||
alias tfd='terraform destroy'
|
||||
alias tff='terraform fmt'
|
||||
|
|
|
@ -51,6 +51,7 @@ Available search contexts are:
|
|||
| `packagist` | `https://packagist.org/?query=` |
|
||||
| `gopkg` | `https://pkg.go.dev/search?m=package&q=` |
|
||||
| `chatgpt` | `https://chatgpt.com/?q=` |
|
||||
| `reddit` | `https://www.reddit.com/search/?q=` |
|
||||
|
||||
Also there are aliases for bang-searching DuckDuckGo:
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ function web_search() {
|
|||
packagist "https://packagist.org/?query="
|
||||
gopkg "https://pkg.go.dev/search?m=package&q="
|
||||
chatgpt "https://chatgpt.com/?q="
|
||||
reddit "https://www.reddit.com/search/?q="
|
||||
)
|
||||
|
||||
# check whether the search engine is supported
|
||||
|
@ -85,6 +86,7 @@ alias npmpkg='web_search npmpkg'
|
|||
alias packagist='web_search packagist'
|
||||
alias gopkg='web_search gopkg'
|
||||
alias chatgpt='web_search chatgpt'
|
||||
alias reddit='web_search reddit'
|
||||
|
||||
#add your own !bang searches here
|
||||
alias wiki='web_search duckduckgo \!w'
|
||||
|
|
|
@ -30,8 +30,9 @@ local return_code="%(?..%F{red}%? ↵%f)"
|
|||
local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
|
||||
local current_dir="%B%F{blue}%~%f%b"
|
||||
local git_branch='$(git_prompt_info)'
|
||||
local venv_prompt='$(virtualenv_prompt_info)'
|
||||
|
||||
PROMPT="╭─${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
|
||||
PROMPT="╭─${venv_prompt}${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
|
||||
╰─$PR_PROMPT "
|
||||
RPROMPT="${return_code}"
|
||||
|
||||
|
@ -39,5 +40,7 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}‹"
|
|||
ZSH_THEME_GIT_PROMPT_SUFFIX="› %f"
|
||||
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}‹"
|
||||
ZSH_THEME_RUBY_PROMPT_SUFFIX="›%f"
|
||||
ZSH_THEME_VIRTUALENV_PREFIX="%F{red}("
|
||||
ZSH_THEME_VIRTUALENV_SUFFIX=")%f "
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue