rename .chezmoitemplates/sh_common.tmpl -> .chezmoitemplates/common.sh.tmpl

This commit is contained in:
2025-05-02 11:21:47 +08:00
parent 8bb3783246
commit 43d42a685f
3 changed files with 4 additions and 2 deletions

View File

@@ -0,0 +1,81 @@
{{/* 以下是套用到 ~/.zshrc ~/.bashrc 用的共通內容 */ -}}
{{/* ---- 設定與修復PATH路徑對應 ------------------------------------------- */ -}}
# Created by `pipx` on 2023-01-30 19:57:14
export PATH="$PATH:$HOME/.local/bin"
# GoLang Path
export PATH="$PATH:$HOME/go/bin"
# Fix Python3 to python Path on macOS
if [ "$(uname -s)" = 'Darwin' ]; then
export PATH=/usr/local/opt/python/libexec/bin:$PATH
fi
# Install ruby¬
# Based on "`brew --prefix ruby`/bin"¬
export PATH="/usr/local/opt/ruby/bin:$PATH
# Based on "`gem environment gemdir`/bin"¬
export PATH="/usr/local/lib/ruby/gems/3.3.0/bin:$PATH
export PATH="$HOME/.local/share/gem/ruby/3.3.0/bin:$PATH"
{{/* ---- 設定環境變數 ---------------------------------------------------- */ -}}
{{- /* 設定預設編輯器 */ -}}
{{ if eq .chezmoi.os "linux" }}
# linux config
[ -n "$DISPLAY" ] && export EDITOR=kate|| export EDITOR=nvim
{{ else }}
export EDITOR=nvim
# non-linux config
{{ end }}
export VISUAL=nvim
{{/* ---- 設定ailas ------------------------------------------------------ */ -}}
# alias
alias gitu='git add . && git commit && git push'
{{/* ---- 擴充功能 ------------------------------------------------------- */ -}}
# 圖片顯示
# 既然即使加入判斷後還是「進入函數定義段落且噴錯」那就代表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
#
# # ex - archive extractor
# # usage: ex <file>
ex ()
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via ex()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}