mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 05:59:46 +08:00
Compare commits
4 Commits
b75b01a309
...
38db3e16ef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38db3e16ef | ||
|
|
24b2600558 | ||
|
|
29b99c2c7b | ||
|
|
30a8a5d3e2 |
@ -41,7 +41,6 @@ plugins=(... git)
|
|||||||
| `gba` | `git branch --all` |
|
| `gba` | `git branch --all` |
|
||||||
| `gbd` | `git branch --delete` |
|
| `gbd` | `git branch --delete` |
|
||||||
| `gbD` | `git branch --delete --force` |
|
| `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` |
|
||||||
| `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` |
|
| `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_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. |
|
| `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. |
|
| `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)
|
### Work in Progress (WIP)
|
||||||
|
|
||||||
|
|||||||
@ -122,7 +122,22 @@ alias gb='git branch'
|
|||||||
alias gba='git branch --all'
|
alias gba='git branch --all'
|
||||||
alias gbd='git branch --delete'
|
alias gbd='git branch --delete'
|
||||||
alias gbD='git branch --delete --force'
|
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 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'
|
alias gbm='git branch --move'
|
||||||
|
|||||||
22
plugins/kind/README.md
Normal file
22
plugins/kind/README.md
Normal 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` |
|
||||||
23
plugins/kind/kind.plugin.zsh
Normal file
23
plugins/kind/kind.plugin.zsh
Normal 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"
|
||||||
@ -1,30 +1,18 @@
|
|||||||
# Find where rtx should be installed
|
# rtx needs to be in $PATH
|
||||||
RTX_DIR="${RTX_DIR:-$HOME/.rtx}"
|
if (( ! ${+commands[rtx]} )); then
|
||||||
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
|
|
||||||
return
|
return
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load command
|
# Load rtx hooks
|
||||||
if [[ -f "$RTX_DIR/rtx.sh" ]]; then
|
eval "$(rtx activate zsh)"
|
||||||
source "$RTX_DIR/rtx.sh"
|
|
||||||
# Load completions
|
# If the completion file doesn't exist yet, we need to autoload it and
|
||||||
if [[ -f "$RTX_COMPLETIONS/_rtx" ]]; then
|
# bind it to `rtx`. Otherwise, compinit will have already done that.
|
||||||
fpath+=("$RTX_COMPLETIONS")
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_rtx" ]]; then
|
||||||
|
typeset -g -A _comps
|
||||||
autoload -Uz _rtx
|
autoload -Uz _rtx
|
||||||
compdef _rtx rtx # compdef is already loaded before loading plugins
|
_comps[rtx]=_rtx
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Generate and load rtx completion
|
||||||
|
rtx completion zsh >! "$ZSH_CACHE_DIR/completions/_rtx" &|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ fi
|
|||||||
# - prompt (default): the user is asked before updating when it's time to update
|
# - prompt (default): the user is asked before updating when it's time to update
|
||||||
# - auto: the update is performed automatically when it's time
|
# - auto: the update is performed automatically when it's time
|
||||||
# - reminder: a reminder is shown to the user when it's time to update
|
# - 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
|
# - disabled: automatic update is turned off
|
||||||
zstyle -s ':omz:update' mode update_mode || {
|
zstyle -s ':omz:update' mode update_mode || {
|
||||||
update_mode=prompt
|
update_mode=prompt
|
||||||
@ -91,13 +92,37 @@ function is_update_available() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function update_last_updated_file() {
|
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"
|
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() {
|
function update_ohmyzsh() {
|
||||||
|
local verbose_mode
|
||||||
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
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
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +151,8 @@ function has_typed_input() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
() {
|
function handle_update() {
|
||||||
|
() {
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
local epoch_target mtime option LAST_EPOCH
|
local epoch_target mtime option LAST_EPOCH
|
||||||
@ -154,7 +180,7 @@ function has_typed_input() {
|
|||||||
trap "
|
trap "
|
||||||
ret=\$?
|
ret=\$?
|
||||||
unset update_mode
|
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'
|
command rm -rf '$ZSH/log/update.lock'
|
||||||
return \$ret
|
return \$ret
|
||||||
" EXIT INT QUIT
|
" EXIT INT QUIT
|
||||||
@ -185,14 +211,14 @@ function has_typed_input() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# If in reminder mode or user has typed input, show reminder and exit
|
# 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
|
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\`"
|
echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don't ask for confirmation before updating if in auto mode
|
# 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
|
update_ohmyzsh
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
@ -207,7 +233,63 @@ function has_typed_input() {
|
|||||||
[nN]) update_last_updated_file ;&
|
[nN]) update_last_updated_file ;&
|
||||||
*) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
|
*) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
unset update_mode
|
||||||
|
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh handle_update
|
||||||
}
|
}
|
||||||
|
|
||||||
unset update_mode
|
case "$update_mode" in
|
||||||
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user