fixed a lot of stuff

This commit is contained in:
Honney
2026-06-23 00:23:16 +02:00
parent 74f4b9b1be
commit 6591f6b020
24 changed files with 626 additions and 455 deletions
+9 -2
View File
@@ -1,5 +1,12 @@
function addpaths
contains -- $argv $fish_user_paths
or set -U fish_user_paths $fish_user_paths $argv
if test (count $argv) -lt 1
echo "Usage: addpaths <path> [more paths...]"
return 1
end
for p in $argv
if not contains -- $p $fish_user_paths
fish_add_path -U $p
end
end
echo "Updated PATH: $PATH"
end
-15
View File
@@ -1,15 +0,0 @@
function compare_sha256
if test (count $argv) -ne 2
echo "Usage: compare_sha256 <file1> <file2>"
return 1
end
set hash1 (sha256sum $argv[1] | awk '{print $1}')
set hash2 (sha256sum $argv[2] | awk '{print $1}')
if test "$hash1" = "$hash2"
echo "Match"
else
echo "Different"
end
end
+120 -15
View File
@@ -1,14 +1,18 @@
function extract
function extract --description "Extract various archive formats"
if test (count $argv) -lt 1
echo "Usage: extract <archive(s)> [output_directory]"
return 1
end
if not command -q file
echo "extract: 'file' command is required. Install it via your package manager."
return 1
end
set archives $argv
set output_dir "."
set use_custom_dir 0
# If exactly 2 args and second is a directory (or doesn't exist yet), treat it as output dir
if test (count $argv) -eq 2
set maybe_dir $argv[2]
if test -d "$maybe_dir"; or not test -e "$maybe_dir"
@@ -19,7 +23,6 @@ function extract
end
end
# Detect multiple archives
set multi 0
if test (count $archives) -gt 1
set multi 1
@@ -31,10 +34,8 @@ function extract
continue
end
# Determine base name (strip extensions)
set base (string replace -r '\.(tar\.gz|tgz|tar\.bz2|tbz2|tar\.xz|txz|gz|bz2|xz|zst|zip|7z|rar)$' '' (basename "$archive"))
set base (string replace -r '\.(tar\.(gz|bz2|xz|zst)|tar|tgz|tbz2|txz|tzst|gz|bz2|xz|zst|zip|7z|rar)$' '' (basename "$archive"))
# Decide target directory
if test $multi -eq 1
set target_dir "$base"
else if test $use_custom_dir -eq 1
@@ -43,30 +44,134 @@ function extract
set target_dir "$base"
end
mkdir -p "$target_dir"
set mime (file --mime-type -b "$archive")
switch $mime
case 'application/x-tar'
if not command -q tar
echo "extract: 'tar' is not installed. Install it via your package manager."
continue
end
mkdir -p "$target_dir"
tar -xvf "$archive" -C "$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
case 'application/gzip'
tar xvzf "$archive" -C "$target_dir"
if string match -q '*.tar.gz' -- "$archive"; or string match -q '*.tgz' -- "$archive"
if not command -q tar
echo "extract: 'tar' is not installed. Install it via your package manager."
continue
end
mkdir -p "$target_dir"
tar -xzf "$archive" -C "$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
else
if not command -q gzip
echo "extract: 'gzip' is not installed. Install it via your package manager."
continue
end
set outname (string replace -r '\.gz$' '' (basename "$archive"))
gzip -dkc "$archive" > "$output_dir/$outname"
echo "extract: decompressed '$archive' to '$output_dir/$outname'"
end
case 'application/x-bzip2'
tar xvjf "$archive" -C "$target_dir"
if string match -q '*.tar.bz2' -- "$archive"; or string match -q '*.tbz2' -- "$archive"
if not command -q tar
echo "extract: 'tar' is not installed. Install it via your package manager."
continue
end
mkdir -p "$target_dir"
tar -xjf "$archive" -C "$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
else
if not command -q bzip2
echo "extract: 'bzip2' is not installed. Install it via your package manager."
continue
end
set outname (string replace -r '\.bz2$' '' (basename "$archive"))
bzip2 -dkc "$archive" > "$output_dir/$outname"
echo "extract: decompressed '$archive' to '$output_dir/$outname'"
end
case 'application/x-xz'
tar xvJf "$archive" -C "$target_dir"
if string match -q '*.tar.xz' -- "$archive"; or string match -q '*.txz' -- "$archive"
if not command -q tar
echo "extract: 'tar' is not installed. Install it via your package manager."
continue
end
mkdir -p "$target_dir"
tar -xJf "$archive" -C "$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
else
if not command -q xz
echo "extract: 'xz' is not installed. Install it via your package manager."
continue
end
set outname (string replace -r '\.xz$' '' (basename "$archive"))
xz -dkc "$archive" > "$output_dir/$outname"
echo "extract: decompressed '$archive' to '$output_dir/$outname'"
end
case 'application/zstd'
tar --zstd -xvf "$archive" -C "$target_dir"
if string match -q '*.tar.zst' -- "$archive"; or string match -q '*.tzst' -- "$archive"
if not command -q tar
echo "extract: 'tar' is not installed. Install it via your package manager."
continue
end
mkdir -p "$target_dir"
tar --zstd -xvf "$archive" -C "$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
else
if not command -q zstd
echo "extract: 'zstd' is not installed. Install it via your package manager."
continue
end
set outname (string replace -r '\.zst$' '' (basename "$archive"))
zstd -dkc "$archive" > "$output_dir/$outname"
echo "extract: decompressed '$archive' to '$output_dir/$outname'"
end
case 'application/zip'
if not command -q unzip
echo "extract: 'unzip' is not installed. Install it via your package manager (e.g., 'unzip' on most distros)."
continue
end
mkdir -p "$target_dir"
unzip "$archive" -d "$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
case 'application/x-7z-compressed'
7z x "$archive" -o"$target_dir"
if command -q 7z
mkdir -p "$target_dir"
7z x "$archive" -o"$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
else if command -q 7zz
mkdir -p "$target_dir"
7zz x "$archive" -o"$target_dir"
echo "extract: extracted '$archive' to '$target_dir'"
else
echo "extract: '7z' or '7zz' is not installed. Install p7zip via your package manager."
continue
end
case 'application/x-rar' 'application/vnd.rar'
unrar x -o+ "$archive" "$target_dir"
if command -q unrar
mkdir -p "$target_dir"
unrar x -o+ "$archive" "$target_dir/"
echo "extract: extracted '$archive' to '$target_dir'"
else if command -q rar
mkdir -p "$target_dir"
rar x -o+ "$archive" "$target_dir/"
echo "extract: extracted '$archive' to '$target_dir'"
else
echo "extract: 'unrar' or 'rar' is not installed. Install unrar via your package manager."
continue
end
case '*'
echo "extract: unknown file type for '$archive' ($mime)"
continue
end
end
end
end
+9 -3
View File
@@ -3,8 +3,14 @@ function findstr
echo "Usage: findstr <search-string>"
return 1
end
if not command -q find
echo "findstr: 'find' is not installed."
return 1
end
if not command -q grep
echo "findstr: 'grep' is not installed."
return 1
end
set query $argv[1]
find . -type f -exec grep -Hn "$query" {} \;
find . -type f -exec grep -Hn "$argv[1]" {} \;
end
-15
View File
@@ -1,15 +0,0 @@
# Load pywal colors
set -g theme_0 (jq -r '.colors.color0' ~/.cache/wal/colors.json) # Color0 for general text
set -g theme_1 (jq -r '.colors.color1' ~/.cache/wal/colors.json) # Color1 for highlights (e.g., @ symbol)
set -g theme_2 (jq -r '.colors.color2' ~/.cache/wal/colors.json) # Color2 for hostname
set -g background_color (jq -r '.special.background' ~/.cache/wal/colors.json) # Background color
set -g foreground_color (jq -r '.special.foreground' ~/.cache/wal/colors.json) # Foreground color
# Customize your prompt
function fish_prompt
# Set background and foreground colors
echo -n (set_color $background_color) # Set background color
echo -n (set_color $foreground_color) # Set foreground color for text
echo -n (set_color $theme_0) 'user' (set_color $theme_1) '@' (set_color $theme_2) 'host' (set_color normal) '> '
end
+5 -2
View File
@@ -3,12 +3,15 @@ function pack
echo "Usage: pack <archive-name> <file-or-dir> [more files...]"
return 1
end
if not command -q tar
echo "pack: 'tar' is not installed. Install it via your package manager."
return 1
end
set archive $argv[1]
set targets $argv[2..-1]
# Ensure .tar.xz extension
if not string match -r '\.tar\.xz$' -- $archive
if not string match -q '*.tar.xz' -- $archive
set archive "$archive.tar.xz"
end
+6 -2
View File
@@ -1,8 +1,12 @@
function removepath
if test (count $argv) -lt 1
echo "Usage: removepath <path>"
return 1
end
if set -l index (contains -i $argv[1] $PATH)
set --erase --universal fish_user_paths[$index]
echo "Updated PATH: $PATH"
echo "Removed '$argv[1]' from PATH."
else
echo "$argv[1] not found in PATH: $PATH"
echo "'$argv[1]' not found in PATH."
end
end
+4 -1
View File
@@ -3,10 +3,13 @@ function search
echo "Usage: search <string> [directory]"
return 1
end
if not command -q rg
echo "search: 'rg' (ripgrep) is not installed. Install it via your package manager."
return 1
end
set query $argv[1]
set dir "."
if test (count $argv) -ge 2
set dir $argv[2]
end
+55
View File
@@ -0,0 +1,55 @@
function verify_file
if test (count $argv) -ne 2
echo "Usage: verify_file <file> <expected_hash>"
return 1
end
set file $argv[1]
if not test -f "$file"
echo "verify_file: '$file' is not a valid file"
return 1
end
set expected $argv[2]
set len (string length "$expected")
switch $len
case 32
set cmd md5sum
case 40
set cmd sha1sum
case 56
set cmd sha224sum
case 64
set cmd sha256sum
case 96
set cmd sha384sum
case 128
if command -q sha512sum
set cmd sha512sum
else if command -q b2sum
set cmd b2sum
else
echo "verify_file: no tool available for 128-char hash (sha512sum or b2sum required)"
return 1
end
case '*'
echo "verify_file: unknown hash length ($len chars). Supported: md5(32), sha1(40), sha224(56), sha256(64), sha384(96), sha512/b2(128)"
return 1
end
if not command -q $cmd
echo "verify_file: '$cmd' is not installed."
return 1
end
set actual ($cmd "$file" | string split -f1 " ")
if test "$actual" = "$expected"
echo "Match"
return 0
else
echo "Mismatch"
return 1
end
end