更新 fish/add-on.fish
This commit is contained in:
+100
-44
@@ -1,4 +1,6 @@
|
||||
# 兼容性添加 PATH
|
||||
# =============================================================================
|
||||
# 1. 环境配置 & 路径兼容
|
||||
# =============================================================================
|
||||
if functions -q fish_add_path
|
||||
fish_add_path ~/.flinty/bin
|
||||
else
|
||||
@@ -17,31 +19,26 @@ set -g fish_greeting ""
|
||||
|
||||
function fish_greeting
|
||||
echo ""
|
||||
# 1. 顶部欢迎与 UTC-8 时间
|
||||
# 顶部欢迎与 补正后的时区时间
|
||||
set_color -o cyan
|
||||
echo "Welcome back, $USER"
|
||||
# 在 TZ 环境变量中,GMT+8 指向西八区 (UTC-8)
|
||||
# 在 TZ 环境变量中,GMT-8 指向东八区 (北京时间)
|
||||
set -l current_time (env TZ="GMT-8" date "+%Y-%m-%d %H:%M:%S")
|
||||
echo "Time (UTC-8): $current_time"
|
||||
echo "Time (Asia/Shanghai): $current_time"
|
||||
set_color normal
|
||||
echo ""
|
||||
|
||||
# 3. 包管理器逻辑 (优先检查 oma)
|
||||
# 包管理器逻辑 (优先检查 oma)
|
||||
set -l pm_name ""
|
||||
if type -q oma
|
||||
set pm_name (set_color -o green)"oma"(set_color normal)
|
||||
else
|
||||
# 回退到系统默认包管理器
|
||||
if type -q brew
|
||||
set pm_name "Homebrew"
|
||||
else if type -q apt
|
||||
set pm_name "apt"
|
||||
else if type -q pacman
|
||||
set pm_name "pacman"
|
||||
else if type -q dnf
|
||||
set pm_name "dnf"
|
||||
else
|
||||
set pm_name "Default PM"
|
||||
if type -q brew; set pm_name "Homebrew"
|
||||
else if type -q apt; set pm_name "apt"
|
||||
else if type -q pacman; set pm_name "pacman"
|
||||
else if type -q dnf; set pm_name "dnf"
|
||||
else; set pm_name "Default PM"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,22 +46,19 @@ function fish_greeting
|
||||
echo ""
|
||||
end
|
||||
|
||||
## 替换 ls 默认行为
|
||||
function ls --description 'alias ls to eza if possible'
|
||||
# 1. 优先使用系统安装的 eza (PATH 里的)
|
||||
# =============================================================================
|
||||
# 2. 核心增强函数 (ls / eza 包装器)
|
||||
# =============================================================================
|
||||
function ls --description 'alias ls to eza with directory `.tldr` descriptions'
|
||||
# 1. 核心路由:确定可用的 eza 二进制文件路径(融合你原有的多架构判定)
|
||||
set -l eza_bin ""
|
||||
if type -q eza
|
||||
eza -la --icons $argv
|
||||
return
|
||||
end
|
||||
|
||||
# 2. 如果系统没有,尝试根据架构寻找 ~/.flinty/bin 下的二进制文件
|
||||
set eza_bin "eza"
|
||||
else
|
||||
set -l arch (uname -m)
|
||||
set -l target_bin ""
|
||||
set -l bin_path "$HOME/.flinty/bin"
|
||||
|
||||
switch $arch
|
||||
case x86_64
|
||||
# 如果是 Alpine Linux,通常需要用 musl 版本 (根据你提供的文件名)
|
||||
if test -f /etc/alpine-release
|
||||
set target_bin "eza_x86_64-unknown-linux-musl"
|
||||
else
|
||||
@@ -74,58 +68,116 @@ function ls --description 'alias ls to eza if possible'
|
||||
set target_bin "eza_aarch64-unknown-linux-gnu"
|
||||
end
|
||||
|
||||
set -l custom_eza "$bin_path/$target_bin"
|
||||
|
||||
# 3. 检查文件是否存在且可执行
|
||||
set -l custom_eza "$HOME/.flinty/bin/$target_bin"
|
||||
if test -n "$target_bin"; and test -x "$custom_eza"
|
||||
$custom_eza -la --icons $argv
|
||||
set eza_bin "$custom_eza"
|
||||
end
|
||||
end
|
||||
|
||||
# 2. 兜底策略:如果最终没有找到任何 eza,完全回退到原生 command ls
|
||||
if test -z "$eza_bin"
|
||||
command ls -la $argv
|
||||
return
|
||||
end
|
||||
|
||||
# 4. 既没有系统 eza 也没有本地二进制,回退到 command ls
|
||||
command ls -la $argv
|
||||
# 3. 动态描述注入核心引擎
|
||||
# 捕获带颜色的标准输出 (继承你原本期望的 -la --icons)
|
||||
set -l lines ($eza_bin -la --icons --color=always $argv)
|
||||
# 捕获绝对路径列表用于精准定位 .tldr 文件
|
||||
set -l paths ($eza_bin -la --icons -1 --absolute=on --color=never $argv 2>/dev/null)
|
||||
|
||||
# 安全网:如果由于特殊参数导致行数不匹配,安全回退到原装输出
|
||||
if test (count $lines) -ne (count $paths)
|
||||
$eza_bin -la --icons $argv
|
||||
return
|
||||
end
|
||||
|
||||
## 按修改时间排序列出文件
|
||||
# 双路循环渲染
|
||||
for i in (seq (count $lines))
|
||||
set -l line $lines[$i]
|
||||
set -l target_path $paths[$i]
|
||||
|
||||
# 检查是否为目录,且该目录下是否存在 .tldr 备注文件
|
||||
if test -d "$target_path"; and test -f "$target_path/.tldr"
|
||||
set -l desc (head -n 1 "$target_path/.tldr" | string trim)
|
||||
if test -n "$desc"
|
||||
# 在行尾追加青色 (Cyan) 的备忘后缀
|
||||
echo -e "$line \e[36m<- $desc\e[0m"
|
||||
continue
|
||||
end
|
||||
end
|
||||
echo -e "$line"
|
||||
end
|
||||
end
|
||||
|
||||
## 按修改时间排序列出文件 (由于 ls 已增强,此命令自动继承备忘显示)
|
||||
function lt --description 'ls sorted by time'
|
||||
ls --sort=modified $argv
|
||||
end
|
||||
|
||||
# =============================================================================
|
||||
# 3. 运维与效率工具函数
|
||||
# =============================================================================
|
||||
|
||||
## 快捷为目录添加或查看备忘贴纸
|
||||
function tldr --description 'Add or view description note for a directory'
|
||||
if test (count $argv) -eq 0
|
||||
echo "Usage: tldr \"你的项目描述\" [目录路径]"
|
||||
echo " Or: tldr -d [目录路径] (删除备忘)"
|
||||
return 1
|
||||
end
|
||||
|
||||
if test "$argv[1]" = "-d"
|
||||
set -l target_dir "."
|
||||
if test (count $argv) -gt 1; set target_dir $argv[2]; end
|
||||
if test -f "$target_dir/.tldr"
|
||||
rm "$target_dir/.tldr"
|
||||
echo "已移除 '$target_dir' 的备忘贴纸。"
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
set -l desc $argv[1]
|
||||
set -l target_dir "."
|
||||
if test (count $argv) -gt 1; set target_dir $argv[2]; end
|
||||
|
||||
if not test -d "$target_dir"
|
||||
echo (set_color -o red)"Error: $target_dir 不是一个有效的目录"(set_color normal)
|
||||
return 1
|
||||
end
|
||||
|
||||
echo "$desc" > "$target_dir/.tldr"
|
||||
echo "成功贴上标签 ➜ 有效目录: '$target_dir' [ $desc ]"
|
||||
end
|
||||
|
||||
## 更新配置
|
||||
function dotu
|
||||
set -l current_dir (pwd)
|
||||
|
||||
cd $HOME/.flinty
|
||||
if git pull
|
||||
source ~/.config/fish/config.fish
|
||||
echo "Config reloaded successfully!"
|
||||
end
|
||||
|
||||
# 回到原位
|
||||
cd $current_dir
|
||||
end
|
||||
|
||||
## 修复光标消失
|
||||
## 修复某些命令行工具导致的光标消失
|
||||
function restore_cursor --on-event fish_postexec
|
||||
tput cnorm
|
||||
end
|
||||
|
||||
## 自动递增探测可用端口
|
||||
function portcheck
|
||||
# 设置起始端口,如果没有传入参数则默认为 8840
|
||||
set -l port 8840
|
||||
if test (count $argv) -gt 0
|
||||
set port $argv[1]
|
||||
end
|
||||
if test (count $argv) -gt 0; set port $argv[1]; end
|
||||
|
||||
# 循环检查端口是否被占用
|
||||
# -t: TCP, -u: UDP, -l: Listening, -n: Numeric
|
||||
while ss -tuln | grep -q ":$port "
|
||||
set port (math $port + 1)
|
||||
end
|
||||
|
||||
echo $port
|
||||
end
|
||||
|
||||
## Yazi 联动:退出时自动切换到最后所在的目录
|
||||
function y
|
||||
set -l tmp (mktemp -t "yazi-cwd.XXXXXX")
|
||||
yazi $argv --cwd-file="$tmp"
|
||||
@@ -135,6 +187,9 @@ function y
|
||||
rm -f -- "$tmp"
|
||||
end
|
||||
|
||||
# =============================================================================
|
||||
# 4. 别名与缩写 (Abbr / Alias)
|
||||
# =============================================================================
|
||||
abbr -a cc 'claude --permission-mode bypassPermissions'
|
||||
abbr -a port 'sudo ss -tulnp | grep'
|
||||
abbr -a process 'sudo ps aux | grep'
|
||||
@@ -142,6 +197,7 @@ abbr -a service 'sudo systemctl list-units --type=service --all | grep'
|
||||
|
||||
alias fastfetch="fastfetch --color-keys blue"
|
||||
|
||||
## 会话级代理控制
|
||||
function proxy --description 'Set HTTP proxy for current session'
|
||||
echo -n "HTTP proxy address (e.g. http://192.168.5.14:6152): "
|
||||
read proxy_addr
|
||||
|
||||
Reference in New Issue
Block a user