feat: add script catalog and -h help for all dotfile scripts

Introduce ff script -h with auto descriptions, shared help.sh, and usage flags across script/*.sh.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-25 15:09:35 +08:00
parent 1f6b042b26
commit 67291a9a50
36 changed files with 1056 additions and 442 deletions
+26 -14
View File
@@ -1,4 +1,25 @@
#!/bin/bash
# 初始化 Fish:wrapper 配置、链接 functions/completions、安装 fisher/z
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
source "$SCRIPT_DIR/common/help.sh"
usage() {
cat <<'EOF'
用法: fish-init
1. 确保 ~/.config/fish/config.fish source dotfile/fish/default.fish
2. 链接 dotfile 中 fish functions 与 completions
3. 安装 fisher、z 插件
4. 将默认 shell 设为 fish
选项:
-h, --help 显示此帮助
EOF
}
dotfile_help_requested "${1:-}" && dotfile_show_help
LOCAL_CONFIG="$HOME/.config/fish/config.fish"
DEFAULT_PATH="$HOME/.dotfile/fish/default.fish"
@@ -8,43 +29,36 @@ mkdir -p "$HOME/.config/fish"
echo 'Setup fish config.fish wrapper'
# 旧版迁移:如果 config.fish 是指向 dotfile 的 symlink(老布局),移除
if [ -L "$LOCAL_CONFIG" ]; then
link_target=$(readlink "$LOCAL_CONFIG")
case "$link_target" in
*/dotfile/fish/config.fish|*/dotfile/fish/default.fish)
*/dotfile/fish/config.fish | */dotfile/fish/default.fish)
echo " Removing legacy symlink: $LOCAL_CONFIG -> $link_target"
rm "$LOCAL_CONFIG"
;;
esac
fi
# 不存在 -> 创建只含一行 source 的本地 wrapper
# 存在但未 source default.fish -> 在文件顶部插入 source 行
# 已 source -> 跳过
if [ ! -f "$LOCAL_CONFIG" ]; then
echo "$SOURCE_LINE" > "$LOCAL_CONFIG"
echo "$SOURCE_LINE" >"$LOCAL_CONFIG"
echo " Created $LOCAL_CONFIG (sources default.fish)"
elif ! grep -qE '^[[:space:]]*source.*default\.fish' "$LOCAL_CONFIG"; then
tmp=$(mktemp)
{ echo "$SOURCE_LINE"; echo; cat "$LOCAL_CONFIG"; } > "$tmp"
{ echo "$SOURCE_LINE"; echo; cat "$LOCAL_CONFIG"; } >"$tmp"
mv "$tmp" "$LOCAL_CONFIG"
echo " Prepended source line to existing $LOCAL_CONFIG"
else
echo " $LOCAL_CONFIG already sources default.fish, skip"
fi
# 确保目标目录存在
echo 'Link fish functions and completions'
mkdir -p "$HOME/.config/fish/functions"
mkdir -p "$HOME/.config/fish/completions"
# 链接 functions 目录下的所有文件
for file in $HOME/.dotfile/fish/functions/*.fish; do
if [ -f "$file" ]; then
filename=$(basename "$file")
target="$HOME/.config/fish/functions/$filename"
# 如果已存在且不是符号链接,备份
if [ -f "$target" ] && [ ! -L "$target" ]; then
mv "$target" "$target.bak"
fi
@@ -53,12 +67,10 @@ for file in $HOME/.dotfile/fish/functions/*.fish; do
fi
done
# 链接 completions 目录下的所有文件
for file in $HOME/.dotfile/fish/completions/*.fish; do
if [ -f "$file" ]; then
filename=$(basename "$file")
target="$HOME/.config/fish/completions/$filename"
# 如果已存在且不是符号链接,备份
if [ -f "$target" ] && [ ! -L "$target" ]; then
mv "$target" "$target.bak"
fi
@@ -72,5 +84,5 @@ fish -c "fisher install jethrokuan/z"
echo 'Set fish as default shell'
fishpath=$(which fish)
echo $fishpath | sudo tee -a /etc/shells
chsh -s $fishpath
echo "$fishpath" | sudo tee -a /etc/shells
chsh -s "$fishpath"