add fish config

This commit is contained in:
FlintyLemming
2025-12-19 16:47:25 +08:00
parent 2c149026be
commit 96c1693fd5

View File

@@ -12,23 +12,28 @@ for file in $argv
# 1. 获取不带后缀的文件名
set -l base_name (string replace -r '\.(tar\..*|tgz|tbz2|txz)$' '' $file | string replace -r '\.[^.]+$' '' )
# 2. 判断解压程序
# 如果是 gzip 格式且系统有 pigz则使用 pigz 加速
set -l tar_opts "-xf"
if test -n "$has_pigz"
# 匹配 .tar.gz, .tgz, .gz 后缀
if string match -qr '\.(gz|tgz)$' "$file"
set tar_opts "-I pigz -xf"
echo "🚀 检测到 Gzip 格式,启用 pigz 并行加速"
end
# 2. 确定解压工具参数 (只包含工具,不包含 -x 或 -t)
set -l tool_opt ""
if test -n "$has_pigz"; and string match -qr '\.(gz|tgz)$' "$file"
set tool_opt "-I pigz"
echo "🚀 检测到 Gzip使用 pigz 加速预览与解压"
end
# 3. 预检:获取压缩包根路径下的唯一项目数量
set -l root_items (tar $tar_opts "$file" -tf 2>/dev/null | string split -m 1 -f 1 / | sort -u)
# 3. 预检:预览内容并获取根项目
# 注意:这里只传 $tool_opt后面显式接 -tf
set -l tar_output (eval tar $tool_opt -tf "$file" 2>/dev/null)
if test $status -ne 0
echo "❌ 错误: 无法读取 $file文件可能损坏或格式不支持"
continue
end
# 提取根目录项目:过滤掉 ./ 并在第一个 / 处截断
set -l root_items (echo $tar_output | string replace -r '^\./' '' | string split -f 1 / | sort -u | string collect -n)
set -l item_count (count $root_items)
if test $item_count -eq 0
echo "跳过: $file 无法读取内容为空"
echo "跳过: $file 内容为空"
continue
end
@@ -36,10 +41,9 @@ for file in $argv
if test $item_count -gt 1
echo "📦 检测到多个根项目 ($item_count),解压至目录: $base_name/"
mkdir -p "$base_name"
# 使用 -C 指定目标目录
tar $tar_opts "$file" -C "$base_name"
eval tar $tool_opt -xf "$file" -C "$base_name"
else
echo "📄 检测到单个根项目 ($root_items[1]),直接解压..."
tar $tar_opts "$file"
eval tar $tool_opt -xf "$file"
end
end