feat: add command
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
.PHONY: help all list
|
||||
|
||||
# 脚本目录
|
||||
SCRIPT_DIR := script
|
||||
|
||||
# 默认目标:显示帮助信息
|
||||
help:
|
||||
@echo "Dotfile Management"
|
||||
@echo ""
|
||||
@echo "Usage: make <script-name>"
|
||||
@echo " Example: make brew-install"
|
||||
@echo " make fish-init"
|
||||
@echo " make docker-clean"
|
||||
@echo ""
|
||||
@echo "Available scripts:"
|
||||
@ls -1 $(SCRIPT_DIR)/*.sh $(SCRIPT_DIR)/*.py 2>/dev/null | xargs -n1 basename | sed 's/\.[^.]*$$//' | sort | sed 's/^/ make /'
|
||||
@echo ""
|
||||
@echo "Quick commands:"
|
||||
@echo " make list List all available scripts"
|
||||
@echo " make help Show this help message"
|
||||
|
||||
# 列出所有可用脚本
|
||||
list:
|
||||
@echo "Available scripts in $(SCRIPT_DIR)/"
|
||||
@ls -1 $(SCRIPT_DIR)/*.sh $(SCRIPT_DIR)/*.py 2>/dev/null | xargs -n1 basename
|
||||
|
||||
#################################################################
|
||||
# 通用规则:自动映射命令到脚本文件
|
||||
#################################################################
|
||||
|
||||
# 匹配所有命令,自动执行对应的脚本文件
|
||||
%:
|
||||
@if [ -f "$(SCRIPT_DIR)/$@.sh" ]; then \
|
||||
echo "Running $(SCRIPT_DIR)/$@.sh..."; \
|
||||
bash $(SCRIPT_DIR)/$@.sh; \
|
||||
elif [ -f "$(SCRIPT_DIR)/$@.py" ]; then \
|
||||
echo "Running $(SCRIPT_DIR)/$@.py..."; \
|
||||
python3 $(SCRIPT_DIR)/$@.py; \
|
||||
elif [ "$@" = "init-default-user" ]; then \
|
||||
echo "Running $(SCRIPT_DIR)/init-default-user.sh (requires sudo)..."; \
|
||||
sudo bash $(SCRIPT_DIR)/init-default-user.sh; \
|
||||
else \
|
||||
echo "Error: No script found for '$@'"; \
|
||||
echo "Run 'make list' to see available scripts"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@@ -0,0 +1,40 @@
|
||||
# Completions for ff command
|
||||
complete -c ff -f
|
||||
set -l ff_subcommands reload edit cd pon poff pst make 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"
|
||||
complete -c ff -n "not __fish_seen_subcommand_from $ff_subcommands" -a "pon" -d "Enable proxy (proxy on)"
|
||||
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 "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"
|
||||
|
||||
# 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"
|
||||
|
||||
# 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"
|
||||
complete -c ff -n "__fish_seen_subcommand_from make" -a "docker-clean" -d "Clean Docker resources"
|
||||
|
||||
# Utils
|
||||
complete -c ff -n "__fish_seen_subcommand_from make" -a "croncheck" -d "Check cron status"
|
||||
|
||||
+1
-42
@@ -80,7 +80,7 @@ end
|
||||
# git
|
||||
# alias
|
||||
alias gitb="git branch --show-current | tr -d '\n' | pbcopy"
|
||||
alias gci="golangci-lint run -c=~/.dotfile/.golangci.yml ./..."
|
||||
alias gci="golangci-lint run -c=~/.dotfile/golang/golangci.yml ./..."
|
||||
alias gmt="go mod tidy"
|
||||
alias gtc="go test -gcflags=all=-l -cover ./..."
|
||||
alias swg="swag init -o docs -g "
|
||||
@@ -143,47 +143,6 @@ if status is-interactive
|
||||
# Commands to run in interactive sessions can go here
|
||||
end
|
||||
|
||||
# reload conf
|
||||
function fre
|
||||
source ~/.config/fish/config.fish
|
||||
echo "Fish configuration updated!"
|
||||
end
|
||||
|
||||
function refish
|
||||
source ~/.config/fish/config.fish
|
||||
echo "Fish configuration updated!"
|
||||
end
|
||||
|
||||
# vi config
|
||||
alias fvi="vim ~/.config/fish/custom.fish"
|
||||
# cd config
|
||||
alias fcd="cd ~/.config/fish/"
|
||||
|
||||
function punset
|
||||
set -e http_proxy
|
||||
set -e https_proxy
|
||||
set -e ftp_proxy
|
||||
set -e all_proxy
|
||||
set -e HTTP_PROXY
|
||||
set -e HTTPS_PROXY
|
||||
set -e FTP_PROXY
|
||||
set -e ALL_PROXY
|
||||
echo "Proxy environment variables have been reset."
|
||||
pshow
|
||||
end
|
||||
|
||||
function pshow
|
||||
export | grep -i proxy
|
||||
end
|
||||
|
||||
function pset
|
||||
set -gx https_proxy http://127.0.0.1:7890
|
||||
set -gx http_proxy http://127.0.0.1:7890
|
||||
set -gx all_proxy socks5://127.0.0.1:7891
|
||||
echo "Proxy environment variables have been set."
|
||||
pshow
|
||||
end
|
||||
|
||||
# source env
|
||||
function source_env
|
||||
for line in (cat $argv | grep -v '^#' | grep -v '^\s*$')
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
# Fast commands management
|
||||
function ff
|
||||
# 定义命令和描述(格式:命令|描述)
|
||||
set -l commands \
|
||||
"reload|Reload fish configuration" \
|
||||
"edit|Edit custom fish configuration" \
|
||||
"cd|Change to fish config directory" \
|
||||
"pon|Enable proxy (proxy on)" \
|
||||
"poff|Disable proxy (proxy off)" \
|
||||
"pst|Show proxy status" \
|
||||
"make|Run dotfile Makefile commands" \
|
||||
"help|Show this help message"
|
||||
|
||||
switch $argv[1]
|
||||
case reload
|
||||
source ~/.config/fish/config.fish
|
||||
echo "Fish configuration reloaded!"
|
||||
case edit
|
||||
vim ~/.config/fish/custom.fish
|
||||
case cd
|
||||
cd ~/.config/fish/
|
||||
case pon
|
||||
set -gx https_proxy http://127.0.0.1:7890
|
||||
set -gx http_proxy http://127.0.0.1:7890
|
||||
set -gx all_proxy socks5://127.0.0.1:7890
|
||||
echo "✓ Proxy enabled"
|
||||
export | grep -i proxy
|
||||
case poff
|
||||
set -e http_proxy
|
||||
set -e https_proxy
|
||||
set -e ftp_proxy
|
||||
set -e all_proxy
|
||||
set -e HTTP_PROXY
|
||||
set -e HTTPS_PROXY
|
||||
set -e FTP_PROXY
|
||||
set -e ALL_PROXY
|
||||
echo "✓ Proxy disabled"
|
||||
export | grep -i proxy
|
||||
case pst
|
||||
export | grep -i proxy
|
||||
case make
|
||||
# 切换到 dotfile 目录执行脚本管理 makefile
|
||||
set -l dotfile_dir ~/.dotfile
|
||||
if test -d $dotfile_dir
|
||||
make -f $dotfile_dir/Makefile.scripts -C $dotfile_dir $argv[2..-1]
|
||||
else
|
||||
echo "Error: Dotfile directory not found at $dotfile_dir"
|
||||
end
|
||||
case help
|
||||
echo "Usage: ff <command>"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
# 自动生成帮助信息
|
||||
for cmd in $commands
|
||||
set -l parts (string split '|' $cmd)
|
||||
printf " %-10s %s\n" $parts[1] $parts[2]
|
||||
end
|
||||
case '*'
|
||||
if test -z "$argv[1]"
|
||||
echo "Error: No command specified"
|
||||
else
|
||||
echo "Error: Unknown command '$argv[1]'"
|
||||
end
|
||||
echo "Run 'ff help' for usage information"
|
||||
end
|
||||
end
|
||||
|
||||
+36
-6
@@ -6,10 +6,12 @@
|
||||
quotepath = false
|
||||
editor = vim
|
||||
excludesfile = ~/.dotfile/git/.gitignore
|
||||
[push]
|
||||
default = current
|
||||
[pull]
|
||||
rebase = false
|
||||
[init]
|
||||
defaultBranch = main
|
||||
[tag]
|
||||
sort = version:refname
|
||||
[column]
|
||||
ui = auto
|
||||
[color]
|
||||
status = auto
|
||||
diff = auto
|
||||
@@ -17,17 +19,45 @@
|
||||
interactive = auto
|
||||
grep = auto
|
||||
ui = auto
|
||||
[merge]
|
||||
tool = nvimdiff
|
||||
[push]
|
||||
#default = current
|
||||
default = simple
|
||||
autoSetupRemote = true
|
||||
followTags = true
|
||||
[fetch]
|
||||
prune = true
|
||||
pruneTags = true
|
||||
all = true
|
||||
[pull]
|
||||
rebase = false
|
||||
[diff]
|
||||
algorithm = histogram
|
||||
colorMoved = plain
|
||||
mnemonicPrefix = true
|
||||
renames = true
|
||||
[difftool "nvimdiff"]
|
||||
cmd = nvim -d \"$LOCAL\" \"$REMOTE\"
|
||||
[merge]
|
||||
tool = nvimdiff
|
||||
[mergetool "nvimdiff"]
|
||||
cmd = nvim -d \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
|
||||
trustExitCode = true
|
||||
[includeIf "gitdir:~/workrepo/"]
|
||||
path = ~/.workgitconfig
|
||||
[rebase]
|
||||
autoSquash = true
|
||||
autoStash = true
|
||||
updateRefs = true
|
||||
[commit]
|
||||
verbose = true
|
||||
[rerere]
|
||||
enabled = true
|
||||
autoupdate = true
|
||||
[help]
|
||||
autocorrect = prompt
|
||||
[branch]
|
||||
autoSetupMerge = always
|
||||
sort = -committerdate
|
||||
[alias]
|
||||
au = add -u
|
||||
co = checkout
|
||||
|
||||
@@ -92,7 +92,7 @@ linters-settings:
|
||||
- name: cognitive-complexity
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments: [14]
|
||||
arguments: [20]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#constant-logical-expr
|
||||
- name: constant-logical-expr
|
||||
severity: warning
|
||||
@@ -109,7 +109,7 @@ linters-settings:
|
||||
- name: cyclomatic
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments: [10]
|
||||
arguments: [20]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#datarace
|
||||
- name: datarace
|
||||
severity: warning
|
||||
+36
-2
@@ -1,10 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo 'Link fish config file'
|
||||
if [ -f "$HOME/.config/fish/config.fish" ]; then
|
||||
# 备份并链接 config.fish
|
||||
if [ -f "$HOME/.config/fish/config.fish" ] && [ ! -L "$HOME/.config/fish/config.fish" ]; then
|
||||
mv $HOME/.config/fish/config.fish $HOME/.config/fish/config.fish.bak
|
||||
fi
|
||||
ln -s $HOME/.dotfile/fish/config.fish $HOME/.config/fish/config.fish
|
||||
ln -sf $HOME/.dotfile/fish/config.fish $HOME/.config/fish/config.fish
|
||||
|
||||
# 确保目标目录存在
|
||||
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
|
||||
ln -sf "$file" "$target"
|
||||
echo " Linked: functions/$filename"
|
||||
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
|
||||
ln -sf "$file" "$target"
|
||||
echo " Linked: completions/$filename"
|
||||
fi
|
||||
done
|
||||
|
||||
fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher"
|
||||
fish -c "fisher install jethrokuan/z"
|
||||
|
||||
@@ -89,6 +89,8 @@ if [ -d "$USER_HOME" ]; then
|
||||
echo "用户家目录配置完成"
|
||||
fi
|
||||
|
||||
cp -r $HOME/.dotfile /home/$USERNAME/.dotfile
|
||||
|
||||
echo ""
|
||||
echo "✅ 用户 $USERNAME 创建完成并已获得 sudo 权限"
|
||||
echo "💡 提示:"
|
||||
|
||||
@@ -264,6 +264,5 @@
|
||||
"[java]": {
|
||||
"editor.suggest.snippetsPreventQuickSuggestions": false
|
||||
},
|
||||
"cursor.general.disableHttp2": true,
|
||||
"cursor.general.disableHttp1SSE": true
|
||||
"git.confirmSync": false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user