更新 fish/add-on.fish

This commit is contained in:
2026-06-24 05:31:58 +00:00
parent 14eeee214f
commit e587acf2e7
+25 -6
View File
@@ -50,7 +50,7 @@ end
# 2. 核心增强函数 (ls / eza 包装器)
# =============================================================================
function ls --description 'alias ls to eza with directory `.tldr` descriptions'
# 1. 核心路由:确定可用的 eza 二进制文件路径(融合你原有的多架构判定)
# 1. 核心路由:确定可用的 eza 二进制文件路径(继承你的多架构判定)
set -l eza_bin ""
if type -q eza
set eza_bin "eza"
@@ -81,12 +81,31 @@ function ls --description 'alias ls to eza with directory `.tldr` descriptions'
end
# 3. 动态描述注入核心引擎
# 捕获带颜色的标准输出 (继承你原本期望的 -la --icons)
# 建立展示行:带颜色、带图标、全长格式 (-la 是你预期的默认行为)
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)
# 安全网:如果由于特殊参数导致行数不匹配,安全回退到原装输出
# 建立纯净路径行:过滤掉所有格式化干扰项,确保只拿到绝对路径
# 必须保留你的自定义排序/过滤参数(如 --sort),但剔除 -l 和 --icons
set -l clean_args
for arg in $argv
switch $arg
case '-l' '--long' '--icons'
# 忽略影响长格式和图标的参数
case '-la' '-al' '-lA' '-Al'
# 如果是组合参数,剥离掉 'l',保留 'a' 或 'A' 保证文件对齐
set -l stripped (string replace -a 'l' '' $arg)
if test "$stripped" != "-"
set -a clean_args $stripped
end
case '*'
set -a clean_args $arg
end
end
# 核心修正:只用 -a(显示隐藏)和 -1(单列),配合 --absolute=on 拿到纯路径
set -l paths ($eza_bin -a -1 --absolute=on --color=never $clean_args 2>/dev/null)
# 安全网:如果由于特殊参数导致行数不匹配,安全回退到原装输出防止错位
if test (count $lines) -ne (count $paths)
$eza_bin -la --icons $argv
return
@@ -97,7 +116,7 @@ function ls --description 'alias ls to eza with directory `.tldr` descriptions'
set -l line $lines[$i]
set -l target_path $paths[$i]
# 检查是否为目录,且该目录下是否存在 .tldr 备注文件
# 此时 $target_path 是完美的纯绝对路径,test 能够精准命中
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"