add fish config
This commit is contained in:
47
bin/tzp
47
bin/tzp
@@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env fish
|
|
||||||
|
|
||||||
set -l arg_count (count $argv)
|
|
||||||
|
|
||||||
# 1. 检查是否有输入参数
|
|
||||||
if test $arg_count -eq 0
|
|
||||||
echo "用法: zp <文件或目录1> [文件或目录2] ..."
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
|
|
||||||
# 2. 预检:检查是否安装了 pigz
|
|
||||||
set -l compress_tool ""
|
|
||||||
if command -v pigz >/dev/null
|
|
||||||
# 使用 pigz 并指定压缩率 5
|
|
||||||
set compress_tool "-I 'pigz -5'"
|
|
||||||
set -l core_count (nproc 2>/dev/null; or echo "多")
|
|
||||||
echo "⚡ 检测到 pigz,将使用 $core_count 核并行压缩 (Level 5)"
|
|
||||||
else
|
|
||||||
# 回退到标准 gzip
|
|
||||||
set compress_tool "-z"
|
|
||||||
echo "🐢 未检测到 pigz,使用标准 gzip 压缩"
|
|
||||||
end
|
|
||||||
|
|
||||||
# 3. 执行压缩逻辑
|
|
||||||
if test $arg_count -eq 1
|
|
||||||
# 逻辑 A:单个参数,生成同名 .tar.gz
|
|
||||||
# 去掉末尾斜杠以获取干净的名称
|
|
||||||
set -l name (string trim -r -c / $argv[1])
|
|
||||||
set -l target "$name.tar.gz"
|
|
||||||
|
|
||||||
echo "🚀 正在压缩单项目: $target"
|
|
||||||
# tar 默认保留软链接(对应 7z 的 -sni -snh 行为)
|
|
||||||
eval tar $compress_tool -cf "$target" "$argv[1]"
|
|
||||||
else
|
|
||||||
# 逻辑 B:多个参数,生成 package_时间戳.tar.gz
|
|
||||||
set -l timestamp (date "+%Y%m%d_%H%M%S")
|
|
||||||
set -l target "package_$timestamp.tar.gz"
|
|
||||||
|
|
||||||
echo "🚀 正在将 $arg_count 个项目打包至: $target"
|
|
||||||
eval tar $compress_tool -cf "$target" $argv
|
|
||||||
end
|
|
||||||
|
|
||||||
if test $status -eq 0
|
|
||||||
echo "✅ 压缩完成: $target"
|
|
||||||
else
|
|
||||||
echo "❌ 压缩过程中出现错误"
|
|
||||||
end
|
|
||||||
49
bin/utzp
49
bin/utzp
@@ -1,49 +0,0 @@
|
|||||||
#!/usr/bin/env fish
|
|
||||||
|
|
||||||
# 预检:检查是否安装了 pigz
|
|
||||||
set -l has_pigz (command -v pigz)
|
|
||||||
|
|
||||||
for file in $argv
|
|
||||||
if not test -f "$file"
|
|
||||||
echo "错误: $file 不是有效文件"
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
# 1. 获取不带后缀的文件名
|
|
||||||
set -l base_name (string replace -r '\.(tar\..*|tgz|tbz2|txz)$' '' $file | string replace -r '\.[^.]+$' '' )
|
|
||||||
|
|
||||||
# 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. 预检:预览内容并获取根项目
|
|
||||||
# 注意:这里只传 $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 内容为空"
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
# 4. 智能判断执行
|
|
||||||
if test $item_count -gt 1
|
|
||||||
echo "📦 检测到多个根项目 ($item_count),解压至目录: $base_name/"
|
|
||||||
mkdir -p "$base_name"
|
|
||||||
eval tar $tool_opt -xf "$file" -C "$base_name"
|
|
||||||
else
|
|
||||||
echo "📄 检测到单个根项目 ($root_items[1]),直接解压..."
|
|
||||||
eval tar $tool_opt -xf "$file"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
55
bin/uzp
55
bin/uzp
@@ -1,55 +0,0 @@
|
|||||||
#!/usr/bin/env fish
|
|
||||||
|
|
||||||
for file in $argv
|
|
||||||
if not test -f "$file"
|
|
||||||
echo "错误: $file 不是有效文件"
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
# 1. 获取不带后缀的文件名 (例如 temp.zip -> temp)
|
|
||||||
set -l base_name (string replace -r '\.[^.]+$' '' (basename "$file"))
|
|
||||||
|
|
||||||
# 2. 预检:获取压缩包顶级路径,并过滤掉系统垃圾
|
|
||||||
set -l all_paths (7z l -slt "$file" | grep "^Path = " | string replace -r '^Path = ' '')
|
|
||||||
set -l root_items
|
|
||||||
for p in $all_paths
|
|
||||||
# 只取路径的第一级
|
|
||||||
set -l root (string split -m 1 / $p)[1]
|
|
||||||
# 排除 macOS 垃圾和空字符,且去重
|
|
||||||
if not contains -- "$root" $root_items
|
|
||||||
if not string match -qr '^(__MACOSX|\.DS_Store|archive_temp)$' "$root"
|
|
||||||
set -a root_items "$root"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
set -l item_count (count $root_items)
|
|
||||||
|
|
||||||
if test $item_count -eq 0
|
|
||||||
echo "跳过: $file 是空的或仅包含系统垃圾文件"
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
# 3. 核心智能判断逻辑
|
|
||||||
set -l need_folder true
|
|
||||||
|
|
||||||
if test $item_count -eq 1
|
|
||||||
# 情况 1: 只有一个根项目,直接解压
|
|
||||||
set need_folder false
|
|
||||||
else if contains -- "$base_name" $root_items
|
|
||||||
# 情况 2: 有多个项目,但其中一个文件夹的名字和压缩包同名
|
|
||||||
# 这通常意味着“自带容器”,为了防止嵌套,直接解压
|
|
||||||
set need_folder false
|
|
||||||
echo "💡 检测到包内已包含同名容器 '$base_name/',将跳过额外目录创建..."
|
|
||||||
end
|
|
||||||
|
|
||||||
# 4. 执行解压
|
|
||||||
if test "$need_folder" = true
|
|
||||||
echo "📦 检测到多个根项目 ($item_count),解压至目录: $base_name/"
|
|
||||||
mkdir -p "$base_name"
|
|
||||||
7z x -sni -mmt=on "$file" -o"$base_name"
|
|
||||||
else
|
|
||||||
echo "📄 结构清晰,直接解压..."
|
|
||||||
7z x -sni -mmt=on "$file"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
24
bin/zp
24
bin/zp
@@ -1,24 +0,0 @@
|
|||||||
#!/usr/bin/env fish
|
|
||||||
# 把之前定义的 zp 函数内容贴进来,去掉外层的 function/end
|
|
||||||
set -l arg_count (count $argv)
|
|
||||||
|
|
||||||
# 检查是否有输入参数
|
|
||||||
if test $arg_count -eq 0
|
|
||||||
echo "用法: zp <文件或目录1> [文件或目录2] ..."
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if test $arg_count -eq 1
|
|
||||||
# 逻辑 A:单个参数,保持原样生成同名 zip
|
|
||||||
set -l name (string trim -r -c / $argv[1])
|
|
||||||
set -l target "$name.zip"
|
|
||||||
echo "🚀 正在多线程压缩单项目: $target"
|
|
||||||
7z a -sni -snh -tzip -mmt=on -mx=5 "$target" "$argv[1]"
|
|
||||||
else
|
|
||||||
# 逻辑 B:多个参数,生成 package_20251219_1540.zip
|
|
||||||
set -l timestamp (date "+%Y%m%d_%H%M%S")
|
|
||||||
set -l target "package_$timestamp.zip"
|
|
||||||
echo "🚀 正在将 $arg_count 个项目打包至: $target"
|
|
||||||
# 直接传入 $argv,7z 会自动处理多个路径
|
|
||||||
7z a -sni -snh -tzip -mmt=on -mx=5 "$target" $argv
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user