跳到主要内容

配置模板

开箱即用的配置文件和脚本模板。

📁 文件列表

Raycast

Shell配置

Git配置

VS Code

工作流模板

  • workflows/ - 各类工作流脚本
    • dev/ - 开发相关
    • note/ - 笔记管理
    • ai/ - AI辅助

🚀 快速开始

1. 一键安装所有配置

# 克隆配置
git clone <your-dotfiles-repo> ~/dotfiles
cd ~/dotfiles

# 运行安装脚本
./install.sh

2. 选择性安装

# 只安装Shell配置
./install-shell.sh

# 只安装Raycast脚本
./install-raycast.sh

# 只安装Git配置
./install-git.sh

📝 配置说明

Shell配置 (.zshrc)

基础配置包含:

  • Oh My Zsh
  • 自动补全和语法高亮
  • 智能历史搜索
  • 自定义提示符
  • 常用别名和函数
# 安装Oh My Zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# 安装插件
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 复制配置
cp zshrc ~/.zshrc
source ~/.zshrc

Git配置 (.gitconfig)

包含:

  • 用户信息
  • 常用别名
  • 差异和合并工具
  • 颜色配置
  • AI辅助hooks
# 复制主配置
cp gitconfig ~/.gitconfig

# 安装git hooks
cp git-hooks/* ~/.git-templates/hooks/
chmod +x ~/.git-templates/hooks/*

# 配置git使用hooks模板
git config --global init.templateDir ~/.git-templates

Raycast配置

包含:

  • 50+实用脚本命令
  • 代码片段库
  • 快速链接
  • AI辅助命令

安装方式:

  1. 安装Raycast
  2. 复制脚本到 ~/.config/raycast/scripts/
  3. 导入snippets和quicklinks JSON

🎨 自定义

修改配置

所有配置文件都有详细注释,可以根据需求修改:

# 编辑Shell配置
vim ~/.zshrc

# 编辑Git别名
vim ~/.gitconfig

# 编辑VS Code设置
code ~/.config/Code/User/settings.json

添加自己的脚本

# 创建个人脚本目录
mkdir -p ~/.local/scripts

# 添加到PATH
echo 'export PATH="$HOME/.local/scripts:$PATH"' >> ~/.zshrc

📦 完整模板库

通用脚本模板

#!/bin/bash
# script-template.sh
#
# Description: [脚本功能描述]
# Author: [Your Name]
# Usage: ./script.sh [arguments]

set -euo pipefail # 严格模式

# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

function log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $*"
}

function error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
}

function warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}

# 清理函数
function cleanup() {
log "Cleaning up..."
# 清理逻辑
}

trap cleanup EXIT

# 参数解析
function parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
exit 0
;;
-v|--verbose)
VERBOSE=true
shift
;;
*)
error "Unknown option: $1"
show_help
exit 1
;;
esac
done
}

function show_help() {
cat << EOF
Usage: $(basename "$0") [OPTIONS]

Description: [脚本功能]

Options:
-h, --help Show this help message
-v, --verbose Verbose output

Examples:
$(basename "$0")
$(basename "$0") --verbose
EOF
}

# 主函数
function main() {
log "Starting..."

# 你的逻辑

log "Done!"
}

# 运行
parse_args "$@"
main

Python脚本模板

#!/usr/bin/env python3
"""
Script Description

Usage:
python script.py [options]
"""

import argparse
import logging
import sys
from pathlib import Path

# 配置日志
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)


def main():
"""主函数"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-v', '--verbose', action='store_true',
help='Verbose output')
parser.add_argument('input', type=Path,
help='Input file')

args = parser.parse_args()

if args.verbose:
logger.setLevel(logging.DEBUG)

try:
# 你的逻辑
logger.info("Processing...")

except Exception as e:
logger.error(f"Error: {e}")
sys.exit(1)


if __name__ == '__main__':
main()

Node.js脚本模板

#!/usr/bin/env node

/**
* Script Description
*
* Usage: node script.js [options]
*/

const fs = require('fs').promises
const path = require('path')

// 命令行参数解析
const args = process.argv.slice(2)
const verbose = args.includes('--verbose') || args.includes('-v')

// 日志函数
function log(message) {
if (verbose) {
console.log(`[${new Date().toISOString()}] ${message}`)
}
}

function error(message) {
console.error(`${message}`)
process.exit(1)
}

// 主函数
async function main() {
try {
log('Starting...')

// 你的逻辑

log('Done!')
} catch (err) {
error(err.message)
}
}

// 运行
main()

🔄 配置同步

使用Git同步

# 初始化dotfiles仓库
cd ~
mkdir dotfiles && cd dotfiles
git init

# 创建软链接而不是复制文件
ln -s ~/.zshrc zshrc
ln -s ~/.gitconfig gitconfig
ln -s ~/.config/Code/User/settings.json vscode-settings.json

# 提交
git add .
git commit -m "Initial dotfiles"

# 推送到GitHub
git remote add origin git@github.com:username/dotfiles.git
git push -u origin main

新机器快速配置

# 克隆配置
git clone git@github.com:username/dotfiles.git ~/dotfiles

# 创建软链接
cd ~/dotfiles
ln -sf ~/dotfiles/zshrc ~/.zshrc
ln -sf ~/dotfiles/gitconfig ~/.gitconfig
ln -sf ~/dotfiles/vscode-settings.json ~/.config/Code/User/settings.json

# 安装工具
./install-tools.sh

# 重启Shell
exec zsh

🛠️ 工具安装脚本

#!/bin/bash
# install-tools.sh

echo "🔧 Installing development tools..."

# Homebrew
if ! command -v brew &> /dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# 核心工具
brew install \
git \
gh \
node \
python \
docker \
ripgrep \
fd \
bat \
exa \
fzf \
jq

# GUI应用
brew install --cask \
raycast \
visual-studio-code \
iterm2 \
rectangle \
1password \
docker

# VS Code扩展
code --install-extension github.copilot
code --install-extension dbaeumer.vscode-eslint
code --install-extension esbenp.prettier-vscode

echo "✅ Installation complete!"

📚 相关资源


提示: 这些模板都经过实战验证,可以直接使用。建议先在测试环境试用,再应用到生产环境。