加入 .bashrc 並調整chezmoi架構把共通內容搬出來

This commit is contained in:
2025-05-02 10:11:11 +08:00
parent ee6816e276
commit 42f0328079
4 changed files with 172 additions and 25 deletions

View File

@@ -123,7 +123,10 @@ zstyle ':completion:*:directory-stack' list-colors '=(#b) #([0-9]#)*( *)==95=38;
# highlight case in select
zstyle ':completion:*' menu select
{{ template "sh_common.tmpl" . }}
## Alias section
alias cp="cp -i" # Confirm before overwriting something
alias df='df -h' # Human-readable sizes
alias free='free -m' # Show sizes in MB
# overwrite ls
if command -v colorls &> /dev/null; then
@@ -169,23 +172,6 @@ export PATH="$PATH:$HOME/go/bin"
# iterm2
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# 圖片顯示
# 既然即使加入判斷後還是「進入函數定義段落且噴錯」那就代表zsh 在解析 .zshrc 時,在到達 if 邏輯前,就已經知道 imgcat 是 alias並因此直接報錯這是因為
# ⚠️ 在 zsh 中,如果你寫 function_name() 這種形式,然後這個名稱之前被定義為 alias會在 parse 階段直接錯誤,不會等到 if 判斷。
# 解決方式:延遲定義(用 eval 避開 parser
# 你需要避免 zsh 在 parse 階段就看到 imgcat() 的寫法。可以這樣寫,透過 eval 延遲定義函數內容:
if ! alias imgcat &>/dev/null && ! functions imgcat &>/dev/null && command -v magick &>/dev/null; then
eval '
imgcat() {
if [[ -z "$1" ]]; then
echo "❌ 請指定圖片檔案例如imgcat ~/Pictures/foo.png"
return 1
fi
magick "$1" -geometry 800x480 sixel:-
}'
fi
zinit light mass8326/zsh-chezmoi
# 自動補上 noglob 並禁用 Zsh 的 globbing 解析
@@ -201,3 +187,5 @@ function git_pushmulti() {
# 執行 git pushmulti
noglob git pushmulti "$remotes" "$branches"
}
{{ template "sh_common.tmpl" . }}