Compare commits
11 Commits
efce79b7e8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| cd1c59f021 | |||
| 01cd8eff49 | |||
| 6281d1cc0c | |||
| 4a185c3b1d | |||
| 396ac72b24 | |||
| 64b191d71a | |||
| 502f707d62 | |||
| c5cc702462 | |||
| e08364e93b | |||
| e1117a254c | |||
| 7e0f85bd5e |
19
dot_config/README.md
Normal file
19
dot_config/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Dotfiles 工具列表
|
||||
|
||||
## Bash 常用命令增强/替代
|
||||
- **zoxide** - 智能目录跳转
|
||||
- **eza / exa** - 替代 `ls`
|
||||
- **bat / batcat** - 替代 `cat`
|
||||
- **fd / fdfind** - 替代 `find`
|
||||
- **ripgrep (rg)** - 替代 `grep`
|
||||
- **btop** - 替代 `top`
|
||||
- **tldr** - 替代 `man`
|
||||
- **fzf** - 模糊搜索工具
|
||||
|
||||
## 其他工具
|
||||
- **Fish Shell** - 现代化 shell
|
||||
- **Tmux** - 终端复用器
|
||||
- **Git** - 版本控制
|
||||
- **vim** - 文本编辑器
|
||||
- **fastfetch** - 系统信息显示
|
||||
- **thefuck** - 命令纠错
|
||||
@@ -1,62 +1,54 @@
|
||||
if status is-interactive
|
||||
# ========= 命令缩写(仅当目标命令存在)=========
|
||||
# ls:优先 eza,其次 exa
|
||||
if type -q eza
|
||||
abbr ls eza
|
||||
abbr ll eza -l
|
||||
abbr la eza -a
|
||||
abbr lal eza -la
|
||||
else if type -q exa
|
||||
abbr ls exa
|
||||
abbr ll exa -l
|
||||
abbr la exa -a
|
||||
abbr lal exa -la
|
||||
end
|
||||
# ========= 编辑器环境变量设置 ==========
|
||||
set -l editor_cmd (if type -q vim; echo vim; else if type -q vi; echo vi; else; end)
|
||||
test -n "$editor_cmd"; and set -gx EDITOR $editor_cmd
|
||||
test -n "$editor_cmd"; and set -gx VISUAL $editor_cmd
|
||||
|
||||
# cat/cap:优先 bat;仅 batcat 时补 bat 缩写(与其它环境一致)
|
||||
if type -q bat
|
||||
abbr cat bat
|
||||
abbr cap bat -p
|
||||
else if type -q batcat
|
||||
abbr cat batcat
|
||||
abbr cap batcat -p
|
||||
abbr bat batcat
|
||||
end
|
||||
# find:优先 fd;仅存在 fdfind 时(如 Debian/Ubuntu)用其并补 fd 缩写
|
||||
if type -q fd
|
||||
abbr find fd
|
||||
else if type -q fdfind
|
||||
abbr find fdfind
|
||||
abbr fd fdfind
|
||||
end
|
||||
# ========= Bash 常用命令增强/替代 ==========
|
||||
# 工具选择
|
||||
set -l ls_cmd (if type -q eza; echo eza; else if type -q exa; echo exa; else; end)
|
||||
set -l cat_cmd (if type -q bat; echo bat; else if type -q batcat; echo batcat; else; end)
|
||||
set -l find_cmd (if type -q fd; echo fd; else if type -q fdfind; echo fdfind; else; end)
|
||||
|
||||
# 处理特殊情况:根据选择的工具添加缩写
|
||||
test "$cat_cmd" = "batcat"; and abbr bat batcat
|
||||
test "$find_cmd" = "fdfind"; and abbr fd fdfind
|
||||
|
||||
# 使用 zoxide init 添加 cd 和 cdi 命令
|
||||
type -q zoxide; and zoxide init --cmd cd fish | source
|
||||
|
||||
# 命令缩写配置
|
||||
test -n "$ls_cmd"; and abbr ls $ls_cmd
|
||||
test -n "$ls_cmd"; and abbr ll "$ls_cmd -l"
|
||||
test -n "$ls_cmd"; and abbr la "$ls_cmd -a"
|
||||
test -n "$ls_cmd"; and abbr lal "$ls_cmd -la"
|
||||
test -n "$cat_cmd"; and abbr cat $cat_cmd
|
||||
test -n "$cat_cmd"; and abbr cap "$cat_cmd -p"
|
||||
test -n "$find_cmd"; and abbr find $find_cmd
|
||||
type -q rg; and abbr grep rg
|
||||
type -q btop; and abbr top btop
|
||||
type -q tldr; and abbr help tldr
|
||||
|
||||
# ========= 其他工具配置 ==========
|
||||
type -q chezmoi; and abbr cz chezmoi
|
||||
type -q tmux; and abbr tm tmux
|
||||
type -q tmux; and abbr tmn 'tmux new'
|
||||
type -q tmux; and abbr tma 'tmux attach'
|
||||
type -q tmux; and abbr tml 'tmux list-sessions'
|
||||
type -q docker; and abbr d docker
|
||||
type -q docker-compose; and abbr dc 'docker-compose'
|
||||
|
||||
# systemd 常用缩写
|
||||
type -q systemctl; and abbr sc systemctl
|
||||
type -q systemctl; and abbr scu 'systemctl --user'
|
||||
type -q journalctl; and abbr jc journalctl
|
||||
type -q journalctl; and abbr jcu 'journalctl --user'
|
||||
|
||||
# ========= thefuck:自动命令纠错 =========
|
||||
type -q thefuck; and thefuck --alias | source
|
||||
|
||||
# ========= zoxide:智能目录跳转 =========
|
||||
# 使用 --cmd=cd:让 cd 也具备 zoxide 的跳转能力(交互式对应 cdi)
|
||||
type -q zoxide; and zoxide init --cmd=cd fish | source
|
||||
|
||||
# ========= 编辑器/查看器(优先 vim,否则 vi)=========
|
||||
# SUDO_EDITOR:供 visudo / sudoedit 等使用;若仍打开 nano,需在 sudoers 中加 Defaults env_keep += "SUDO_EDITOR"
|
||||
if type -q vim
|
||||
set -gx EDITOR vim
|
||||
set -gx VISUAL vim
|
||||
set -gx SUDO_EDITOR vim
|
||||
else if type -q vi
|
||||
set -gx EDITOR vi
|
||||
set -gx VISUAL vi
|
||||
set -gx SUDO_EDITOR vi
|
||||
# ========= fastfetch:启动信息显示(仅在第一次打开 shell 时) =========
|
||||
if status --is-login; and type -q fastfetch
|
||||
fastfetch
|
||||
end
|
||||
|
||||
# ========= fastfetch:启动信息显示 =========
|
||||
type -q fastfetch; and fastfetch
|
||||
end
|
||||
|
||||
@@ -6,29 +6,66 @@ set -euo pipefail
|
||||
# - 不使用 chezmoi 的 .tmpl 模板语法;通过运行时检测 apt/pacman/dnf。
|
||||
# - 脚本尽量保持幂等(包已安装会自动跳过)。
|
||||
|
||||
SUDO=""
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
SUDO="sudo"
|
||||
else
|
||||
echo "需要 sudo 权限才能安装包(当前非 root,且找不到 sudo)。" >&2
|
||||
# 包管理器配置
|
||||
PACKAGE_LIST="zoxide exa bat fd fd-find ripgrep btop tldr fzf git vim tmux fish fastfetch thefuck"
|
||||
declare -A UPDATE_COMMAND
|
||||
declare -A INSTALL_COMMAND
|
||||
UPDATE_COMMAND=(
|
||||
[pacman]="pacman -Syu --noconfirm"
|
||||
[apt]="apt update"
|
||||
[dnf]="dnf makecache -y"
|
||||
)
|
||||
INSTALL_COMMAND=(
|
||||
[pacman]="pacman -S --noconfirm"
|
||||
[apt]="apt install -y"
|
||||
[dnf]="dnf install -y"
|
||||
)
|
||||
|
||||
# 输出函数
|
||||
log() { echo -e "\033[34m$1\033[0m"; }
|
||||
|
||||
# 检查 sudo 权限(假设普通用户运行)
|
||||
if ! command -v sudo >/dev/null 2>&1; then
|
||||
log "❌ 需要sudo 权限才能安装包。"
|
||||
exit 1
|
||||
fi
|
||||
SUDO="sudo"
|
||||
|
||||
# 安装单个包函数
|
||||
install_package() {
|
||||
local install_cmd="$1"
|
||||
local package="$2"
|
||||
if $SUDO $install_cmd "$package"; then
|
||||
log "✨ 安装 $package: ✓ 成功"
|
||||
else
|
||||
log "⚠️ 安装 $package: ✗ 跳过"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 安装包函数
|
||||
install_packages() {
|
||||
local package_manager="$1"
|
||||
|
||||
log "🔍 检测到 $package_manager,开始安装包..."
|
||||
log "📦 更新包..."
|
||||
$SUDO ${UPDATE_COMMAND[$package_manager]}
|
||||
log "🚀 开始安装包..."
|
||||
|
||||
for package in $PACKAGE_LIST; do
|
||||
install_package "${INSTALL_COMMAND[$package_manager]}" "$package"
|
||||
done
|
||||
|
||||
log "✅ $package_manager 包安装完成!"
|
||||
}
|
||||
|
||||
# 主逻辑:检测包管理器并安装
|
||||
if command -v pacman >/dev/null 2>&1; then
|
||||
# Arch/Manjaro:先同步并升级系统,再安装所需包
|
||||
$SUDO pacman -Syu --noconfirm
|
||||
$SUDO pacman -S --noconfirm exa zoxide dust bat btop fd ripgrep fzf tldr git vim tmux
|
||||
install_packages "pacman"
|
||||
elif command -v apt >/dev/null 2>&1; then
|
||||
# Debian/Ubuntu:更新索引后再安装
|
||||
$SUDO apt update -y || true
|
||||
$SUDO apt install -y fzf zoxide ripgrep bat fd-find btop exa git vim tmux
|
||||
install_packages "apt"
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
# Fedora:更新元数据后再安装
|
||||
$SUDO dnf makecache -y || true
|
||||
$SUDO dnf install -y exa zoxide dust bat btop fd-find ripgrep fzf tldr git vim tmux
|
||||
install_packages "dnf"
|
||||
else
|
||||
echo "未检测到 apt / pacman / dnf,跳过安装。" >&2
|
||||
log "❌ 未检测到 apt / pacman / dnf,跳过安装。"
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user