Refactor commands and add archive utilities
- Replaces direct chafa call with nix run invocation - Implements zipz and unzipz for tar/zstd compression and extraction - Enhances error handling and usage feedback
This commit is contained in:
parent
69f3dedf2d
commit
b5753d1453
2 changed files with 86 additions and 1 deletions
|
@ -21,7 +21,7 @@ for i in (seq 1 $num)
|
||||||
set type2 $types[$j]
|
set type2 $types[$j]
|
||||||
set combination "$type1+$type2"
|
set combination "$type1+$type2"
|
||||||
echo "Creating with type $combination"
|
echo "Creating with type $combination"
|
||||||
chafa -s 24x11 -w 9 --symbols $combination --view-size 24x11 $input_png
|
nix run nixpkgs#chafa -- -s 24x11 -w 9 --symbols $combination --view-size 24x11 $input_png
|
||||||
# chafa -s 23x12 -w 9 --stretch --symbols $combination --view-size 23x12 $input_png
|
# chafa -s 23x12 -w 9 --stretch --symbols $combination --view-size 23x12 $input_png
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -79,6 +79,91 @@ function s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function zipz
|
||||||
|
# Ensure exactly two arguments are provided
|
||||||
|
if test (count $argv) -ne 2
|
||||||
|
echo "Usage: bipzstd <directory> <output_filename>"
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set directory $argv[1]
|
||||||
|
set output_file $argv[2]
|
||||||
|
|
||||||
|
# Verify that the specified directory exists
|
||||||
|
if not test -d $directory
|
||||||
|
echo "Error: '$directory' is not a valid directory."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Correct output filename to always end with tar.zst
|
||||||
|
if not string match -q "*tar.zst" $output_file
|
||||||
|
# Remove any existing extension, if present
|
||||||
|
set base (string replace -r '\..*$' '' $output_file)
|
||||||
|
set output_file "$base.tar.zst"
|
||||||
|
echo "Output filename corrected to: $output_file"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check if the output file already exists to avoid accidental overwrite
|
||||||
|
if test -f $output_file
|
||||||
|
echo "Error: Output file '$output_file' already exists. Please remove it or choose another name."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create a tar archive of the directory and compress it with zstd.
|
||||||
|
# - The tar command outputs the archive to stdout.
|
||||||
|
# - zstd compresses it using 4 threads (-T4) and a compression level of 12 (-12).
|
||||||
|
# - The -c flag forces zstd to write to stdout.
|
||||||
|
tar cf - $directory | nix run nixpkgs#zstd -- -c -T5 -15 -v > $output_file
|
||||||
|
|
||||||
|
# Check the exit status of the pipeline
|
||||||
|
if test $status -eq 0
|
||||||
|
echo "Compression successful: $output_file"
|
||||||
|
else
|
||||||
|
echo "Compression failed."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function unzipz
|
||||||
|
# Ensure exactly two arguments are provided
|
||||||
|
if test (count $argv) -ne 2
|
||||||
|
echo "Usage: unzipz <input_compressed_file> <destination_directory>"
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set input_file $argv[1]
|
||||||
|
set destination $argv[2]
|
||||||
|
|
||||||
|
# Verify that the input file exists
|
||||||
|
if not test -f $input_file
|
||||||
|
echo "Error: '$input_file' is not a valid file."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create the destination directory if it does not exist
|
||||||
|
if not test -d $destination
|
||||||
|
mkdir -p $destination
|
||||||
|
if test $status -ne 0
|
||||||
|
echo "Error: Failed to create destination directory '$destination'."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Decompress the file:
|
||||||
|
# - The zstd command (via nix) decompresses the compressed file,
|
||||||
|
# using the -d flag (decompress) and -c to output to stdout.
|
||||||
|
# - The decompressed stream is piped to tar to extract its contents into the destination directory.
|
||||||
|
cat $input_file | nix run nixpkgs#zstd -- -d -c -v | tar xf - -C $destination
|
||||||
|
|
||||||
|
# Check the exit status of the pipeline
|
||||||
|
if test $status -eq 0
|
||||||
|
echo "Decompression successful: files extracted to $destination"
|
||||||
|
else
|
||||||
|
echo "Decompression failed."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
set fish_greeting # Disable greeting
|
set fish_greeting # Disable greeting
|
||||||
|
|
||||||
fastfetch
|
fastfetch
|
||||||
|
|
Loading…
Add table
Reference in a new issue