mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-09-28 14:06:12 +02:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed01423b18 | ||
|
|
bc6faea85b | ||
|
|
ce6ebd3d8d | ||
|
|
6749d0825b | ||
|
|
296fbb8b69 |
+1
-45
@@ -110,53 +110,9 @@ if [[ -z "$ZSH_COMPDUMP" ]]; then
|
||||
ZSH_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
||||
fi
|
||||
|
||||
# Resolve the commit $ZSH is checked out at into $REPLY by reading the git
|
||||
# directory, so that no git process is forked on every startup.
|
||||
# Handles .git files (worktrees, submodules), worktree common dirs, detached
|
||||
# HEADs and packed refs. Returns 1 if anything is unexpected.
|
||||
_omz_git_head() {
|
||||
local gitdir="$ZSH/.git" common head ref
|
||||
local -a lines
|
||||
REPLY=
|
||||
|
||||
# .git may be a file pointing at the real git dir
|
||||
if [[ -f "$gitdir" ]]; then
|
||||
read -r head 2>/dev/null < "$gitdir" || return 1
|
||||
gitdir="${head#gitdir: }"
|
||||
[[ "$gitdir" = /* ]] || gitdir="$ZSH/$gitdir"
|
||||
fi
|
||||
|
||||
# worktrees keep their refs in the common git dir
|
||||
common="$gitdir"
|
||||
if [[ -f "$gitdir/commondir" ]]; then
|
||||
read -r common 2>/dev/null < "$gitdir/commondir" || return 1
|
||||
[[ "$common" = /* ]] || common="$gitdir/$common"
|
||||
fi
|
||||
|
||||
[[ -r "$gitdir/HEAD" ]] || return 1
|
||||
read -r head 2>/dev/null < "$gitdir/HEAD" || return 1
|
||||
|
||||
# detached HEAD: the file holds the commit itself
|
||||
[[ "$head" = ref:\ * ]] || { REPLY="$head"; return 0 }
|
||||
|
||||
ref="${head#ref: }"
|
||||
if [[ -r "$common/$ref" ]]; then
|
||||
read -r REPLY 2>/dev/null < "$common/$ref" || return 1
|
||||
[[ "$REPLY" != ref:\ * ]] || return 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
[[ -r "$common/packed-refs" ]] || return 1
|
||||
lines=("${(@f)$(<"$common/packed-refs")}")
|
||||
REPLY="${lines[(r)* ${(b)ref}]%% *}"
|
||||
[[ -n "$REPLY" ]]
|
||||
}
|
||||
|
||||
# Construct zcompdump OMZ metadata
|
||||
_omz_git_head || REPLY="$(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
|
||||
zcompdump_revision="#omz revision: $REPLY"
|
||||
zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
|
||||
zcompdump_fpath="#omz fpath: $fpath"
|
||||
unset -f _omz_git_head
|
||||
|
||||
# Delete the zcompdump file if OMZ zcompdump metadata changed
|
||||
if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
|
||||
|
||||
@@ -71,7 +71,6 @@ plugins=(... kubectl)
|
||||
| | | **Secret management** |
|
||||
| kgsec | `kubectl get secret` | Get secret for decoding |
|
||||
| kgseca | `kubectl get secret --all-namespaces` | List secrets across all namespaces |
|
||||
| kesec | `kubectl edit secret` | Edit secret resource |
|
||||
| kdsec | `kubectl describe secret` | Describe secret resource in detail |
|
||||
| kdelsec | `kubectl delete secret` | Delete the secret |
|
||||
| | | **Deployment management** |
|
||||
|
||||
@@ -93,7 +93,6 @@ alias kdelcm='kubectl delete configmap'
|
||||
# Secret management
|
||||
alias kgsec='kubectl get secret'
|
||||
alias kgseca='kubectl get secret --all-namespaces'
|
||||
alias kesec='kubectl edit secret'
|
||||
alias kdsec='kubectl describe secret'
|
||||
alias kdelsec='kubectl delete secret'
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
# - https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Console/Resources/completion.bash
|
||||
#
|
||||
_sf_console() {
|
||||
local lastParam out comp sf_cmd
|
||||
local -a completions flagPrefix requestComp inputs
|
||||
local lastParam flagPrefix requestComp out comp
|
||||
local -a completions
|
||||
|
||||
# The user could have moved the cursor backwards on the command-line.
|
||||
# We need to trigger completion from the $CURRENT location, so we need
|
||||
@@ -29,20 +29,11 @@ _sf_console() {
|
||||
setopt local_options BASH_REMATCH
|
||||
if [[ "${lastParam}" =~ '-.*=' ]]; then
|
||||
# We are dealing with a flag with an =
|
||||
flagPrefix=(-P "${BASH_REMATCH}")
|
||||
flagPrefix="-P ${BASH_REMATCH}"
|
||||
fi
|
||||
|
||||
# Prepare the command to obtain completions. An alias is resolved here,
|
||||
# because the request is no longer read again by the shell.
|
||||
sf_cmd="${words[1]}"
|
||||
if [[ -n "${aliases[$sf_cmd]}" ]]; then
|
||||
requestComp=(${(z)aliases[$sf_cmd]})
|
||||
else
|
||||
requestComp=(${~sf_cmd})
|
||||
fi
|
||||
|
||||
requestComp+=(_complete --no-interaction -szsh -a1 "-c$((CURRENT-1))")
|
||||
|
||||
# Prepare the command to obtain completions
|
||||
requestComp="${words[0]} ${words[1]} _complete --no-interaction -szsh -a1 -c$((CURRENT-1))" i=""
|
||||
for w in ${words[@]}; do
|
||||
w=$(printf -- '%b' "$w")
|
||||
# remove quotes from typed values
|
||||
@@ -56,18 +47,19 @@ _sf_console() {
|
||||
fi
|
||||
# empty values are ignored
|
||||
if [ ! -z "$w" ]; then
|
||||
inputs+=("-i$w")
|
||||
i="${i}-i${w} "
|
||||
fi
|
||||
done
|
||||
|
||||
# Ensure at least 1 input
|
||||
if (( ! $#inputs )); then
|
||||
inputs=(-i' ')
|
||||
if [ "${i}" = "" ]; then
|
||||
requestComp="${requestComp} -i\" \""
|
||||
else
|
||||
requestComp="${requestComp} ${i}"
|
||||
fi
|
||||
|
||||
# The request is run without being read again by the shell, so that a
|
||||
# "$(...)" or a backtick typed on the command line is not executed
|
||||
out=$(SHELL_VERBOSITY=0 "${requestComp[@]}" "${inputs[@]}" 2>/dev/null)
|
||||
# Use eval to handle any environment variables and such
|
||||
out=$(eval ${requestComp} 2>/dev/null)
|
||||
|
||||
while IFS='\n' read -r comp; do
|
||||
if [ -n "$comp" ]; then
|
||||
@@ -83,7 +75,7 @@ _sf_console() {
|
||||
done < <(printf "%s\n" "${out[@]}")
|
||||
|
||||
# Let inbuilt _describe handle completions
|
||||
_describe "completions" completions "${flagPrefix[@]}"
|
||||
eval _describe "completions" completions $flagPrefix
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
@@ -370,6 +370,7 @@ setup_zshrc() {
|
||||
# Ask user for confirmation before backing up and overwriting
|
||||
echo "${FMT_YELLOW}Found ${zdot}/.zshrc."
|
||||
echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten."
|
||||
echo "Your command history will be backed up too, since replacing .zshrc drops any SAVEHIST you had set."
|
||||
echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}"
|
||||
echo "----------------------------------------"
|
||||
cat "$ZSH/templates/minimal.zshrc"
|
||||
@@ -398,6 +399,44 @@ setup_zshrc() {
|
||||
fi
|
||||
echo "${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
|
||||
mv "$zdot/.zshrc" "$OLD_ZSHRC"
|
||||
|
||||
# The .zshrc we just moved aside is where the user's SAVEHIST lived. Without
|
||||
# it zsh trims $HISTFILE the next time a shell exits, so copy the history
|
||||
# while it is still intact. $HISTFILE is a zsh variable we cannot read from
|
||||
# here, so cover both locations it is commonly given: /etc/zshrc on macOS
|
||||
# sets ${ZDOTDIR:-$HOME}/.zsh_history, and lib/history.zsh falls back to
|
||||
# $HOME/.zsh_history.
|
||||
hist_backed_up=""
|
||||
for hist in "$zdot/.zsh_history" "$HOME/.zsh_history"; do
|
||||
if [ ! -f "$hist" ]; then
|
||||
continue
|
||||
fi
|
||||
case " $hist_backed_up " in
|
||||
*" $hist "*) continue ;;
|
||||
esac
|
||||
hist_backup_base="${hist}.pre-oh-my-zsh"
|
||||
hist_backup="$hist_backup_base"
|
||||
if [ -e "$hist_backup" ]; then
|
||||
hist_backup_ts="$(date +%Y-%m-%d_%H-%M-%S)"
|
||||
hist_backup_i=0
|
||||
while [ -e "$hist_backup" ]; do
|
||||
hist_backup_i=$((hist_backup_i + 1))
|
||||
hist_backup="${hist_backup_base}-${hist_backup_ts}-${hist_backup_i}"
|
||||
done
|
||||
fi
|
||||
if cp -p "$hist" "$hist_backup"; then
|
||||
echo "${FMT_GREEN}Backing up your command history to ${hist_backup}${FMT_RESET}"
|
||||
hist_backed_up="$hist_backed_up $hist"
|
||||
else
|
||||
# a half-written file would look like a usable backup
|
||||
rm -f "$hist_backup"
|
||||
fmt_error "could not back up $hist"
|
||||
if ! mv "$OLD_ZSHRC" "$zdot/.zshrc"; then
|
||||
fmt_error "could not restore $zdot/.zshrc from backup"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to $zdot/.zshrc.${FMT_RESET}"
|
||||
|
||||
Reference in New Issue
Block a user