feat(zsh): load user config after zshrc
Load .zsh_user once before the first prompt and remove legacy direct source lines during updates. Disable Clash proxy environment variables in the default user configuration.
This commit is contained in:
parent
3593897c8d
commit
b93d9ab879
@ -187,17 +187,6 @@ configure_zsh() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# 如果 ~/.zshrc 里面没有 source ~/.zsh_user 则添加
|
||||
if ! grep -qx "source ~/.zsh_user" ~/.zshrc; then
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
# macOS
|
||||
printf "\nsource ~/.zsh_user\n" >> ~/.zshrc
|
||||
else
|
||||
# Linux
|
||||
sed -i '$a source ~/.zsh_user' ~/.zshrc
|
||||
fi
|
||||
fi
|
||||
|
||||
# 如果 ~/.zshrc 里面没有 conda initialize 则运行 mamba init zsh
|
||||
if ! grep -q "conda initialize" ~/.zshrc; then
|
||||
if [ -d ~/.miniconda3 ]; then
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
__zsh_clash_env_unset
|
||||
|
||||
# HOST="VM-ubuntu"
|
||||
|
||||
# ZSH_THEME="robbyrussell"
|
||||
|
||||
@ -6,6 +6,18 @@ __ZSH_CUSTOM_INIT_INCLUDED="yes"
|
||||
|
||||
# ====================================================================================================
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
|
||||
__zsh_load_user_config() {
|
||||
add-zsh-hook -d precmd __zsh_load_user_config
|
||||
unfunction __zsh_load_user_config
|
||||
[ -r "$HOME/.zsh_user" ] && source "$HOME/.zsh_user"
|
||||
}
|
||||
|
||||
add-zsh-hook precmd __zsh_load_user_config
|
||||
|
||||
# ====================================================================================================
|
||||
|
||||
zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
||||
|
||||
zstyle ':omz:update' frequency 13
|
||||
|
||||
29
update.sh
29
update.sh
@ -37,6 +37,34 @@ update_authorized_keys() {
|
||||
done <<< "$public_keys"
|
||||
}
|
||||
|
||||
remove_legacy_zsh_user_source() {
|
||||
local zshrc="$HOME/.zshrc"
|
||||
local init_file="$HOME/.oh-my-zsh/custom/00-init.zsh"
|
||||
[ -f "$zshrc" ] || return
|
||||
grep -q '^add-zsh-hook precmd __zsh_load_user_config$' "$init_file" 2>/dev/null || return
|
||||
|
||||
local temp_file
|
||||
temp_file=$(mktemp "${zshrc}.XXXXXX") || return 1
|
||||
|
||||
awk '
|
||||
{
|
||||
line = $0
|
||||
sub(/^[[:space:]]+/, "", line)
|
||||
sub(/[[:space:]]+$/, "", line)
|
||||
if (line != "source ~/.zsh_user" && line != ". ~/.zsh_user") print
|
||||
}
|
||||
' "$zshrc" > "$temp_file"
|
||||
|
||||
if cmp -s "$zshrc" "$temp_file"; then
|
||||
rm "$temp_file"
|
||||
return
|
||||
fi
|
||||
|
||||
cp "$temp_file" "$zshrc"
|
||||
rm "$temp_file"
|
||||
echo "Legacy source ~/.zsh_user line has been removed from $zshrc."
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
|
||||
update_file $scriptdir/files/.nanorc ~/.nanorc
|
||||
@ -51,6 +79,7 @@ update_file $scriptdir/files/zsh/51-alias.zsh ~/.oh-my-zsh/custom/51-a
|
||||
update_file $scriptdir/files/zsh/80-proxy.zsh ~/.oh-my-zsh/custom/80-proxy.zsh
|
||||
update_file $scriptdir/files/zsh/90-other.zsh ~/.oh-my-zsh/custom/90-other.zsh
|
||||
update_file $scriptdir/files/zsh/ys-simple.zsh-theme ~/.oh-my-zsh/custom/themes/ys-simple.zsh-theme
|
||||
remove_legacy_zsh_user_source
|
||||
update_authorized_keys
|
||||
|
||||
# sudo_id=$(sudo id -u 2>/dev/null)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user