1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-10-16 11:40:46 +00:00

Compare commits

...

7 commits

Author SHA1 Message Date
nasso
c33da7f187
Merge 1bc00257fb into 1514145a09 2024-09-19 15:32:02 +01:00
Carlo Sala
1514145a09
feat(nvm): add _omz_nvm_load function 2024-09-19 11:44:51 +02:00
Carlo Sala
99e2c31484
feat(git): add git_previous_branch function
Closes #12538
2024-09-18 21:05:45 +02:00
Francesco Cataldo
e52598a5cc
feat(web-search): add reddit (#12664) 2024-09-18 20:43:52 +02:00
rakeshgm
d91944d47e
feat(gnzh): add virtualenv prompt (#12666) 2024-09-18 20:42:18 +02:00
Tushar Mohod
865291cb7a
feat (terraform): add apply -auto-approve alias (#12658)
Closes #12591
2024-09-18 20:40:54 +02:00
nasso
1bc00257fb feat(jj): completions, aliases and prompt utils 2024-05-11 19:06:04 +02:00
10 changed files with 168 additions and 28 deletions

View file

@ -162,6 +162,18 @@ function git_current_branch() {
echo ${ref#refs/heads/} 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 # Gets the number of commits ahead from remote
function git_commits_ahead() { function git_commits_ahead() {

61
plugins/jj/README.md Normal file
View 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
View 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'

View file

@ -42,6 +42,8 @@ as you want:
zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ... 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 #### `.nvmrc` autoload
Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_ Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_

View file

@ -20,7 +20,7 @@ if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then
return return
fi fi
function _omz_load_nvm_completion { function _omz_nvm_setup_completion {
local _nvm_completion local _nvm_completion
# Load nvm bash completion # Load nvm bash completion
for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do 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 break
fi fi
done 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 if ! zstyle -t ':omz:plugins:nvm' autoload; then
unfunction _omz_setup_autoload unfunction _omz_nvm_setup_autoload
return return
fi fi
@ -68,13 +68,13 @@ function _omz_setup_autoload {
add-zsh-hook chpwd load-nvmrc add-zsh-hook chpwd load-nvmrc
load-nvmrc load-nvmrc
unfunction _omz_setup_autoload unfunction _omz_nvm_setup_autoload
} }
if zstyle -t ':omz:plugins:nvm' lazy; then 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 # 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 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 " eval "
function $nvm_lazy_cmd { function $nvm_lazy_cmd {
for func in $nvm_lazy_cmd; do for func in $nvm_lazy_cmd; do
@ -84,14 +84,16 @@ if zstyle -t ':omz:plugins:nvm' lazy; then
done done
# Load nvm if it exists in \$NVM_DIR # Load nvm if it exists in \$NVM_DIR
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\" [[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
_omz_load_nvm_completion _omz_nvm_setup_completion
_omz_setup_autoload _omz_nvm_setup_autoload
\"\$0\" \"\$@\" if [[ \"\$0\" != _omz_nvm_load ]]; then
\"\$0\" \"\$@\"
fi
} }
" "
unset nvm_lazy_cmd unset nvm_lazy_cmd
else else
source "$NVM_DIR/nvm.sh" source "$NVM_DIR/nvm.sh"
_omz_load_nvm_completion _omz_nvm_setup_completion
_omz_setup_autoload _omz_nvm_setup_autoload
fi fi

View file

@ -15,22 +15,23 @@ plugins=(... terraform)
## Aliases ## Aliases
| Alias | Command | | Alias | Command |
|--------|----------------------------| |---------|----------------------------------|
| `tf` | `terraform` | | `tf` | `terraform` |
| `tfa` | `terraform apply` | | `tfa` | `terraform apply` |
| `tfc` | `terraform console` | | `tfaa` | `terraform apply -auto-approve` |
| `tfd` | `terraform destroy` | | `tfc` | `terraform console` |
| `tff` | `terraform fmt` | | `tfd` | `terraform destroy` |
| `tffr` | `terraform fmt -recursive` | | `tff` | `terraform fmt` |
| `tfi` | `terraform init` | | `tffr` | `terraform fmt -recursive` |
| `tfiu` | `terraform init -upgrade` | | `tfi` | `terraform init` |
| `tfo` | `terraform output` | | `tfiu` | `terraform init -upgrade` |
| `tfp` | `terraform plan` | | `tfo` | `terraform output` |
| `tfv` | `terraform validate` | | `tfp` | `terraform plan` |
| `tfs` | `terraform state` | | `tfv` | `terraform validate` |
| `tft` | `terraform test` | | `tfs` | `terraform state` |
| `tfsh` | `terraform show` | | `tft` | `terraform test` |
| `tfsh` | `terraform show` |
## Prompt function ## Prompt function

View file

@ -17,6 +17,7 @@ function tf_version_prompt_info() {
alias tf='terraform' alias tf='terraform'
alias tfa='terraform apply' alias tfa='terraform apply'
alias tfaa='terraform apply -auto-approve'
alias tfc='terraform console' alias tfc='terraform console'
alias tfd='terraform destroy' alias tfd='terraform destroy'
alias tff='terraform fmt' alias tff='terraform fmt'

View file

@ -51,6 +51,7 @@ Available search contexts are:
| `packagist` | `https://packagist.org/?query=` | | `packagist` | `https://packagist.org/?query=` |
| `gopkg` | `https://pkg.go.dev/search?m=package&q=` | | `gopkg` | `https://pkg.go.dev/search?m=package&q=` |
| `chatgpt` | `https://chatgpt.com/?q=` | | `chatgpt` | `https://chatgpt.com/?q=` |
| `reddit` | `https://www.reddit.com/search/?q=` |
Also there are aliases for bang-searching DuckDuckGo: Also there are aliases for bang-searching DuckDuckGo:

View file

@ -32,6 +32,7 @@ function web_search() {
packagist "https://packagist.org/?query=" packagist "https://packagist.org/?query="
gopkg "https://pkg.go.dev/search?m=package&q=" gopkg "https://pkg.go.dev/search?m=package&q="
chatgpt "https://chatgpt.com/?q=" chatgpt "https://chatgpt.com/?q="
reddit "https://www.reddit.com/search/?q="
) )
# check whether the search engine is supported # check whether the search engine is supported
@ -85,6 +86,7 @@ alias npmpkg='web_search npmpkg'
alias packagist='web_search packagist' alias packagist='web_search packagist'
alias gopkg='web_search gopkg' alias gopkg='web_search gopkg'
alias chatgpt='web_search chatgpt' alias chatgpt='web_search chatgpt'
alias reddit='web_search reddit'
#add your own !bang searches here #add your own !bang searches here
alias wiki='web_search duckduckgo \!w' alias wiki='web_search duckduckgo \!w'

View file

@ -30,8 +30,9 @@ local return_code="%(?..%F{red}%? ↵%f)"
local user_host="${PR_USER}%F{cyan}@${PR_HOST}" local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
local current_dir="%B%F{blue}%~%f%b" local current_dir="%B%F{blue}%~%f%b"
local git_branch='$(git_prompt_info)' 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 " ╰─$PR_PROMPT "
RPROMPT="${return_code}" RPROMPT="${return_code}"
@ -39,5 +40,7 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}"
ZSH_THEME_GIT_PROMPT_SUFFIX=" %f" ZSH_THEME_GIT_PROMPT_SUFFIX=" %f"
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}" ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}"
ZSH_THEME_RUBY_PROMPT_SUFFIX="%f" ZSH_THEME_RUBY_PROMPT_SUFFIX="%f"
ZSH_THEME_VIRTUALENV_PREFIX="%F{red}("
ZSH_THEME_VIRTUALENV_SUFFIX=")%f "
} }