From 9bd43f9f9cfcecc0d50813f8eeb60ecff6edf845 Mon Sep 17 00:00:00 2001 From: laily Date: Tue, 18 Nov 2025 14:25:09 +0800 Subject: [PATCH] feat: update git alias --- .build_scripts/build_web.sh | 26 ++++++++++++ fish/completions/ff.fish | 58 +++++++++++++++++--------- fish/completions/git.fish | 51 +++++++++++++++++++++++ fish/functions/execute-script.fish | 65 ++++++++++++++++++++++++++++++ fish/functions/ff.fish | 4 ++ git/.gitconfig | 12 ++++++ golang/golangci.yml | 2 +- vscode/settings.json | 4 +- 8 files changed, 202 insertions(+), 20 deletions(-) create mode 100644 .build_scripts/build_web.sh create mode 100644 fish/completions/git.fish create mode 100644 fish/functions/execute-script.fish diff --git a/.build_scripts/build_web.sh b/.build_scripts/build_web.sh new file mode 100644 index 0000000..a565abf --- /dev/null +++ b/.build_scripts/build_web.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Build Web + +set -e + +if [ -z $GOOS ]; then + echo "GOOS is not set" + exit 1 +fi +if [ -z $GOARCH ]; then + echo "GOARCH is not set" + exit 1 +fi + +OUTPUT_DIR=${1:-./output/$GOOS-$GOARCH} + +cd web +pnpm install +pnpm build + +cd .. +mkdir -p $OUTPUT_DIR/ +rm -rf $OUTPUT_DIR/web/* +mkdir -p $OUTPUT_DIR/web/ +cp -r web/out/* $OUTPUT_DIR/web/ \ No newline at end of file diff --git a/fish/completions/ff.fish b/fish/completions/ff.fish index dcd1bdb..fd252c8 100644 --- a/fish/completions/ff.fish +++ b/fish/completions/ff.fish @@ -1,6 +1,6 @@ # Completions for ff command complete -c ff -f -set -l ff_subcommands reload edit cd pon poff pst make help +set -l ff_subcommands reload edit cd pon poff pst make script help complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "reload" -d "Reload fish configuration" complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "edit" -d "Edit custom fish configuration" complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "cd" -d "Change to fish config directory" @@ -8,28 +8,29 @@ complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "pon" -d complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "poff" -d "Disable proxy (proxy off)" complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "pst" -d "Show proxy status" complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "make" -d "Run dotfile Makefile commands" +complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "script" -d "Run script from script directory" complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "help" -d "Show this help message" -# make 子命令的补全 - 直接使用脚本文件名 -complete -c ff -n "__fish_seen_subcommand_from make" -a "help" -d "Show all make targets" -complete -c ff -n "__fish_seen_subcommand_from make" -a "list" -d "List all available scripts" +# # make 子命令的补全 - 直接使用脚本文件名 +# complete -c ff -n "__fish_seen_subcommand_from make" -a "help" -d "Show all make targets" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "list" -d "List all available scripts" # Install scripts -complete -c ff -n "__fish_seen_subcommand_from make" -a "brew-install" -d "Install Homebrew" -complete -c ff -n "__fish_seen_subcommand_from make" -a "docker-install" -d "Install Docker" -complete -c ff -n "__fish_seen_subcommand_from make" -a "nvim-install" -d "Install Neovim" -complete -c ff -n "__fish_seen_subcommand_from make" -a "python-install" -d "Install Python" -complete -c ff -n "__fish_seen_subcommand_from make" -a "gvm-install" -d "Install Go Version Manager" -complete -c ff -n "__fish_seen_subcommand_from make" -a "firacode-install" -d "Install FiraCode font" -complete -c ff -n "__fish_seen_subcommand_from make" -a "font-install" -d "Install fonts" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "brew-install" -d "Install Homebrew" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "docker-install" -d "Install Docker" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "nvim-install" -d "Install Neovim" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "python-install" -d "Install Python" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "gvm-install" -d "Install Go Version Manager" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "firacode-install" -d "Install FiraCode font" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "font-install" -d "Install fonts" -# Init scripts -complete -c ff -n "__fish_seen_subcommand_from make" -a "fish-init" -d "Initialize Fish shell" -complete -c ff -n "__fish_seen_subcommand_from make" -a "git-init" -d "Initialize Git config" -complete -c ff -n "__fish_seen_subcommand_from make" -a "nvim-init" -d "Initialize Neovim config" -complete -c ff -n "__fish_seen_subcommand_from make" -a "tmux-init" -d "Initialize Tmux config" -complete -c ff -n "__fish_seen_subcommand_from make" -a "cursor-init" -d "Initialize Cursor config" -complete -c ff -n "__fish_seen_subcommand_from make" -a "init-default-user" -d "Initialize default user (sudo)" +# # Init scripts +# complete -c ff -n "__fish_seen_subcommand_from make" -a "fish-init" -d "Initialize Fish shell" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "git-init" -d "Initialize Git config" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "nvim-init" -d "Initialize Neovim config" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "tmux-init" -d "Initialize Tmux config" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "cursor-init" -d "Initialize Cursor config" +# complete -c ff -n "__fish_seen_subcommand_from make" -a "init-default-user" -d "Initialize default user (sudo)" # Clean scripts complete -c ff -n "__fish_seen_subcommand_from make" -a "brew-clean" -d "Clean Homebrew cache" @@ -38,3 +39,24 @@ complete -c ff -n "__fish_seen_subcommand_from make" -a "docker-clean" -d "Clean # Utils complete -c ff -n "__fish_seen_subcommand_from make" -a "croncheck" -d "Check cron status" +# script 子命令的补全 - 动态列出 script 目录下的脚本 +function __ff_list_scripts + set -l script_dir ~/.dotfile/script + if test -d $script_dir + # 列出 .sh 文件 + for script in $script_dir/*.sh + if test -f $script + basename $script | string replace -r '\.sh$' '' + end + end + # 列出 .py 文件 + for script in $script_dir/*.py + if test -f $script + basename $script | string replace -r '\.py$' '' + end + end + end +end + +complete -c ff -n "__fish_seen_subcommand_from script" -a '(__ff_list_scripts)' -d "Script name" + diff --git a/fish/completions/git.fish b/fish/completions/git.fish new file mode 100644 index 0000000..033943d --- /dev/null +++ b/fish/completions/git.fish @@ -0,0 +1,51 @@ +# ----- Git worktree native completions ----- + +# 列出分支 +function __git_branches + git branch --format="%(refname:short)" 2>/dev/null +end + +# 列出 worktree 路径 +function __git_worktree_paths + git worktree list --porcelain 2>/dev/null \ + | awk '/worktree/ {print $2}' +end + +# ----------------------- +# Worktree 别名补全 +# ----------------------- + +# git wtl → worktree list +complete -f -c git -n '__fish_seen_subcommand_from wtl' -a '' + +# git wtp → worktree prune +complete -f -c git -n '__fish_seen_subcommand_from wtp' -a '' + +# git wta → worktree add +complete -c git -n '__fish_seen_subcommand_from wta' \ + -a '(__git_branches)' \ + -d "Branch to add worktree for" + +# git wtb → worktree add -b +complete -c git -n '__fish_seen_subcommand_from wtb' \ + -a '(__git_branches)' \ + -d "Base branch to create new branch from" + +# git wtr → worktree remove +complete -c git -n '__fish_seen_subcommand_from wtr' \ + -a '(__git_worktree_paths)' \ + -d "Existing worktree paths" + +# ------------------------------ +# 原生 git worktree 补全增强 +# ------------------------------ + +# git worktree add +complete -c git -n '__fish_seen_subcommand_from worktree; and __fish_seen_subcommand_from add' \ + -a '(__git_branches)' \ + -d "Branch to checkout" + +# git worktree remove +complete -c git -n '__fish_seen_subcommand_from worktree; and __fish_seen_subcommand_from remove' \ + -a '(__git_worktree_paths)' \ + -d "Worktree path" diff --git a/fish/functions/execute-script.fish b/fish/functions/execute-script.fish new file mode 100644 index 0000000..6a9a922 --- /dev/null +++ b/fish/functions/execute-script.fish @@ -0,0 +1,65 @@ +# Execute script from script directory +function execute-script + # 执行 script 目录下的脚本 + set -l dotfile_dir ~/.dotfile + set -l script_dir $dotfile_dir/script + set -l script_name $argv[1] + + if test -z "$script_name" + echo "Error: No script name specified" + echo "Usage: execute-script [args...]" + echo "" + echo "Available scripts:" + if test -d $script_dir + for script in $script_dir/*.sh $script_dir/*.py + if test -f $script + set -l basename (basename $script) + echo " $basename" + end + end + end + return 1 + end + + # 尝试不同的扩展名 + set -l script_path "" + for ext in sh py + set -l test_path $script_dir/$script_name.$ext + if test -f $test_path + set script_path $test_path + break + end + end + + # 如果没找到,尝试直接使用提供的名称 + if test -z "$script_path" + set script_path $script_dir/$script_name + end + + if test -f $script_path + echo "Running: $script_path" + if test -x $script_path + $script_path $argv[2..-1] + else + # 根据文件类型选择解释器 + if string match -q "*.py" $script_path + python3 $script_path $argv[2..-1] + else + bash $script_path $argv[2..-1] + end + end + else + echo "Error: Script not found: $script_name" + echo "Available scripts:" + if test -d $script_dir + for script in $script_dir/*.sh $script_dir/*.py + if test -f $script + set -l basename (basename $script) + echo " $basename" + end + end + end + return 1 + end +end + diff --git a/fish/functions/ff.fish b/fish/functions/ff.fish index 9a07fac..5f2e565 100644 --- a/fish/functions/ff.fish +++ b/fish/functions/ff.fish @@ -9,6 +9,8 @@ function ff "poff|Disable proxy (proxy off)" \ "pst|Show proxy status" \ "make|Run dotfile Makefile commands" \ + "script|Run script from script directory" \ + "update|Update dotfile" \ "help|Show this help message" switch $argv[1] @@ -48,6 +50,8 @@ function ff else echo "Error: Dotfile directory not found at $dotfile_dir" end + case script + execute-script $argv[2..-1] case help echo "Usage: ff " echo "" diff --git a/git/.gitconfig b/git/.gitconfig index a3e4e93..fff9daf 100644 --- a/git/.gitconfig +++ b/git/.gitconfig @@ -94,6 +94,18 @@ # git reviewone foo.js bar.js reviewone = !vim -p +\"tabdo Gdiff $REVIEW_BASE\" +\"let g:gitgutter_diff_base = '$REVIEW_BASE'\" #git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Laily'; GIT_AUTHOR_EMAIL='i@laily.net'; GIT_COMMITTER_NAME='Laily'; GIT_COMMITTER_EMAIL='i@laily.net';" HEAD + + # worktree + wt="worktree" + wta="worktree add" + wtb="worktree add -b" + wtr="worktree remove" + wtl="worktree list" + wtp="worktree prune" + # git wtbn feature-login # 新建分支 + worktree + wtbn="!f(){ git worktree add -b "$1" ../"$1"; }; f" + # git wtn bugfix-123 # 自动创建 ../bugfix-123 (使用同名分支) + wtn="!f(){ git worktree add ../"$1" "$1"; }; f" [protocol "file"] allow = always diff --git a/golang/golangci.yml b/golang/golangci.yml index 2696b50..a6de451 100644 --- a/golang/golangci.yml +++ b/golang/golangci.yml @@ -33,7 +33,7 @@ linters: arguments: - 15 severity: warning - disabled: false + disabled: true - name: atomic severity: warning disabled: false diff --git a/vscode/settings.json b/vscode/settings.json index bc9cbdc..613da0d 100644 --- a/vscode/settings.json +++ b/vscode/settings.json @@ -264,5 +264,7 @@ "[java]": { "editor.suggest.snippetsPreventQuickSuggestions": false }, - "git.confirmSync": false + "git.confirmSync": false, + "editor.dropIntoEditor.preferences": [], + "whichkey.bindingOverrides": [] }