1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-02-13 05:59:46 +08:00

Compare commits

..

4 Commits

Author SHA1 Message Date
Adam Henley
38db3e16ef
feat(kind): add plugin for Kind k8s tool (#9827)
Co-authored-by: jxlwqq <jxlwqq@gmail.com>
Co-authored-by: Francesco Ilario <fr.ilario@gmail.com>
Co-authored-by: Marc Cornellà <hello@mcornella.com>
2023-10-09 20:28:09 +02:00
tobi1805
24b2600558
feat(git): delete squash-merged branches in gbda (#11948) 2023-10-09 18:07:51 +02:00
Marc Cornellà
29b99c2c7b
feat(updater): add background-alpha update mode (preview) (#11928)
NOTE: this feature is in alpha / preview mode, it is not guaranteed to work 100% of the
time in all cases. If you experience any issues, open an issue or search for an open
one describing your same situation.

To use this, use the zstyle update mode settings [1] with the value `background-alpha`:

  zstyle ':omz:update' mode background-alpha

[1] https://github.com/ohmyzsh/ohmyzsh#getting-updates
2023-10-09 18:00:17 +02:00
Marc Cornellà
30a8a5d3e2
fix(rtx): fix rtx init procedure (#11949) 2023-10-09 17:53:00 +02:00
6 changed files with 232 additions and 102 deletions

View File

@ -41,7 +41,6 @@ plugins=(... git)
| `gba` | `git branch --all` |
| `gbd` | `git branch --delete` |
| `gbD` | `git branch --delete --force` |
| `gbda` | `git branch --no-color --merged \| command grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| command xargs git branch --delete 2>/dev/null` |
| `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` |
| `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` |
| `gbm` | `git branch --move` |
@ -251,6 +250,7 @@ receive further support.
| `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise. |
| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. |
| `grename <old> <new>` | Renames branch `<old>` to `<new>`, including on the origin remote. |
| `gbda` | Deletes all merged and squash-merged branches |
### Work in Progress (WIP)

View File

@ -122,7 +122,22 @@ alias gb='git branch'
alias gba='git branch --all'
alias gbd='git branch --delete'
alias gbD='git branch --delete --force'
alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null'
# Copied and modified from James Roeder (jmaroeder) under MIT License
# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish
function gbda() {
git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null
local default_branch=$(git_main_branch)
git for-each-ref refs/heads/ "--format=%(refname:short)" | \
while read branch; do
local merge_base=$(git merge-base $default_branch $branch)
if [[ '-*' == $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) ]]; then
git branch -D $branch
fi
done
}
alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d'
alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D'
alias gbm='git branch --move'

22
plugins/kind/README.md Normal file
View File

@ -0,0 +1,22 @@
# Kind plugin
This plugin adds completion for the [Kind](https://kind.sigs.k8s.io/) tool, as well
as a few aliases for easier use.
To use it, add `kind` to the plugins array in your zshrc file:
```zsh
plugins=(... kind)
```
## Aliases
| Alias | Command |
| ------- | ---------------------------- |
| `kicc` | `kind create cluster` |
| `kiccn` | `kind create cluster --name` |
| `kigc` | `kind get clusters` |
| `kidc` | `kind delete cluster` |
| `kidcn` | `kind delete cluster --name` |
| `kidca` | `kind delete clusters -A` |
| `kigk` | `kind get kubeconfig` |

View File

@ -0,0 +1,23 @@
if (( ! $+commands[kind] )); then
return
fi
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `kind`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_kind" ]]; then
typeset -g -A _comps
autoload -Uz _kind
_comps[kind]=_kind
fi
# Generate and load kind completion
kind completion zsh >! "$ZSH_CACHE_DIR/completions/_kind" &|
# Register aliases
alias kicc="kind create cluster"
alias kiccn="kind create cluster --name"
alias kigc="kind get clusters"
alias kidc="kind delete cluster"
alias kidcn="kind delete cluster --name"
alias kidca="kind delete clusters -A"
alias kigk="kind get kubeconfig"

View File

@ -1,30 +1,18 @@
# Find where rtx should be installed
RTX_DIR="${RTX_DIR:-$HOME/.rtx}"
RTX_COMPLETIONS="$RTX_DIR/completions"
if [[ ! -f "$RTX_DIR/rtx.sh" || ! -f "$RTX_COMPLETIONS/_rtx" ]]; then
# If not found, check for archlinux/AUR package (/opt/rtx-vm/)
if [[ -f "/opt/rtx-vm/rtx.sh" ]]; then
RTX_DIR="/opt/rtx-vm"
RTX_COMPLETIONS="$RTX_DIR"
# If not found, check for Homebrew package
elif (( $+commands[brew] )); then
_RTX_PREFIX="$(brew --prefix rtx)"
RTX_DIR="${_RTX_PREFIX}/libexec"
RTX_COMPLETIONS="${_RTX_PREFIX}/share/zsh/site-functions"
unset _RTX_PREFIX
else
# rtx needs to be in $PATH
if (( ! ${+commands[rtx]} )); then
return
fi
# Load rtx hooks
eval "$(rtx activate zsh)"
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `rtx`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_rtx" ]]; then
typeset -g -A _comps
autoload -Uz _rtx
_comps[rtx]=_rtx
fi
# Load command
if [[ -f "$RTX_DIR/rtx.sh" ]]; then
source "$RTX_DIR/rtx.sh"
# Load completions
if [[ -f "$RTX_COMPLETIONS/_rtx" ]]; then
fpath+=("$RTX_COMPLETIONS")
autoload -Uz _rtx
compdef _rtx rtx # compdef is already loaded before loading plugins
fi
fi
# Generate and load rtx completion
rtx completion zsh >! "$ZSH_CACHE_DIR/completions/_rtx" &|

View File

@ -9,6 +9,7 @@ fi
# - prompt (default): the user is asked before updating when it's time to update
# - auto: the update is performed automatically when it's time
# - reminder: a reminder is shown to the user when it's time to update
# - background-alpha: an experimental update-on-the-background option
# - disabled: automatic update is turned off
zstyle -s ':omz:update' mode update_mode || {
update_mode=prompt
@ -91,13 +92,37 @@ function is_update_available() {
}
function update_last_updated_file() {
local exit_status="$1" error="$2"
if [[ -z "${1}${2}" ]]; then
echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update"
return
fi
cat >! "${ZSH_CACHE_DIR}/.zsh-update" <<EOD
LAST_EPOCH=$(current_epoch)
EXIT_STATUS=${exit_status}
ERROR='${error//\'/}'
EOD
}
function update_ohmyzsh() {
local verbose_mode
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then
if [[ "$update_mode" != background-alpha ]] \
&& LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then
update_last_updated_file
return $?
fi
local exit_status error
if error=$(LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v silent 2>&1); then
update_last_updated_file 0 "Update successful"
else
exit_status=$?
update_last_updated_file $exit_status "$error"
return $exit_status
fi
}
@ -126,6 +151,7 @@ function has_typed_input() {
}
}
function handle_update() {
() {
emulate -L zsh
@ -154,7 +180,7 @@ function has_typed_input() {
trap "
ret=\$?
unset update_mode
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh 2>/dev/null
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh handle_update 2>/dev/null
command rm -rf '$ZSH/log/update.lock'
return \$ret
" EXIT INT QUIT
@ -185,14 +211,14 @@ function has_typed_input() {
fi
# If in reminder mode or user has typed input, show reminder and exit
if [[ "$update_mode" = reminder ]] || has_typed_input; then
if [[ "$update_mode" = reminder ]] || { [[ "$update_mode" != background-alpha ]] && has_typed_input }; then
printf '\r\e[0K' # move cursor to first column and clear whole line
echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
return 0
fi
# Don't ask for confirmation before updating if in auto mode
if [[ "$update_mode" = auto ]]; then
if [[ "$update_mode" = (auto|background-alpha) ]]; then
update_ohmyzsh
return $?
fi
@ -210,4 +236,60 @@ function has_typed_input() {
}
unset update_mode
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh handle_update
}
case "$update_mode" in
background-alpha)
autoload -Uz add-zsh-hook
_omz_bg_update() {
# do the update in a subshell
(handle_update) &|
# register update results function
add-zsh-hook precmd _omz_bg_update_status
# deregister background function
add-zsh-hook -d precmd _omz_bg_update
unset -f _omz_bg_update
}
_omz_bg_update_status() {
{
local LAST_EPOCH EXIT_STATUS ERROR
if [[ ! -f "$ZSH_CACHE_DIR"/.zsh-update ]]; then
return 1
fi
# check update results until timeout is reached
. "$ZSH_CACHE_DIR/.zsh-update"
if [[ -z "$EXIT_STATUS" || -z "$ERROR" ]]; then
return 1
fi
if [[ "$EXIT_STATUS" -eq 0 ]]; then
print -P "\n%F{green}[oh-my-zsh] Update successful.%f"
return 0
elif [[ "$EXIT_STATUS" -ne 0 ]]; then
print -P "\n%F{red}[oh-my-zsh] There was an error updating:%f"
printf "\n${fg[yellow]}%s${reset_color}" "$ERROR"
return 0
fi
} always {
if (( TRY_BLOCK_ERROR == 0 )); then
# if last update results have been handled, remove them from the status file
update_last_updated_file
# deregister background function
add-zsh-hook -d precmd _omz_bg_update_status
unset -f _omz_bg_update_status
fi
}
}
add-zsh-hook precmd _omz_bg_update
;;
*)
handle_update ;;
esac