Files
laily 67291a9a50 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>
2026-06-25 15:09:35 +08:00

67 lines
1.7 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 将 Ghostty 配置链接到 dotfile(macOS / Linux)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
source "$SCRIPT_DIR/common/help.sh"
usage() {
cat <<'EOF'
用法: ghostty-init
将 ~/.dotfile/ghostty/config.ghostty 软链接到 Ghostty 配置目录:
macOS: ~/Library/Application Support/com.mitchellh.ghostty/
Linux: $XDG_CONFIG_HOME/ghostty/
已有配置会备份为 *.backup.<时间戳>。
选项:
-h, --help 显示此帮助
EOF
}
dotfile_help_requested "${1:-}" && dotfile_show_help
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
SRC="$HOME/.dotfile/ghostty/config.ghostty"
if [[ "$(uname)" == "Darwin" ]]; then
DEST="$HOME/Library/Application Support/com.mitchellh.ghostty/config.ghostty"
else
CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
DEST="$CONFIG_HOME/ghostty/config.ghostty"
fi
echo -e "${YELLOW}初始化 Ghostty 配置...${NC}"
echo -e "${YELLOW}目标路径:$DEST${NC}"
mkdir -p "$(dirname "$DEST")"
if [ -L "$DEST" ] && [ "$(readlink -f "$DEST")" = "$(readlink -f "$SRC")" ]; then
echo -e "${GREEN}软链接已存在且指向正确位置,无需操作。${NC}"
exit 0
fi
if [ -e "$DEST" ]; then
BACKUP="${DEST}.backup.$(date +%Y%m%d%H%M%S)"
mv "$DEST" "$BACKUP"
echo -e "${YELLOW}已将现有配置备份到 $BACKUP${NC}"
elif [ -L "$DEST" ]; then
rm "$DEST"
fi
ln -s "$SRC" "$DEST"
if [ -L "$DEST" ] && [ "$(readlink -f "$DEST")" = "$(readlink -f "$SRC")" ]; then
echo -e "${GREEN}软链接创建成功:$DEST -> $SRC${NC}"
else
echo -e "${RED}软链接创建失败,请检查路径和权限。${NC}"
exit 1
fi