Initial Commit with possibly working flake
This commit is contained in:
commit
ac120b6a27
22 changed files with 1022 additions and 0 deletions
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1745526057,
|
||||
"narHash": "sha256-ITSpPDwvLBZBnPRS2bUcHY3gZSwis/uTe255QgMtTLA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f771eb401a46846c1aebd20552521b233dd7e18b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
43
flake.nix
Normal file
43
flake.nix
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
description = "A convenient wrapper around Nix commands with fish completions";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
lib = pkgs.lib;
|
||||
in
|
||||
{
|
||||
packages = rec {
|
||||
default = yay;
|
||||
yay = import ./pkgs/default.nix { inherit pkgs lib; };
|
||||
};
|
||||
}
|
||||
)
|
||||
// {
|
||||
# NixOS module for system-wide installation
|
||||
nixosModules.default =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
environment.systemPackages = [ self.packages.${pkgs.system}.default ];
|
||||
};
|
||||
|
||||
# Home-manager module
|
||||
homeManagerModules.default =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
home.packages = [ self.packages.${pkgs.system}.default ];
|
||||
};
|
||||
};
|
||||
}
|
24
functions/__yay_build_compression_cmd.fish
Normal file
24
functions/__yay_build_compression_cmd.fish
Normal file
|
@ -0,0 +1,24 @@
|
|||
function __yay_build_compression_cmd
|
||||
set -l type $argv[1]
|
||||
set -l level $argv[2]
|
||||
set -l threads $argv[3]
|
||||
|
||||
switch $type
|
||||
case gzip
|
||||
echo "gzip -$level"
|
||||
case zstd
|
||||
set -l cmd "zstd -$level"
|
||||
if test -n "$threads"
|
||||
set cmd "$cmd -T$threads"
|
||||
end
|
||||
echo $cmd
|
||||
case bzip2
|
||||
echo "bzip2 -$level"
|
||||
case bzip3
|
||||
set -l cmd "bzip3 -b $level"
|
||||
if test -n "$threads"
|
||||
set cmd "$cmd -j $threads"
|
||||
end
|
||||
echo $cmd
|
||||
end
|
||||
end
|
165
functions/__yay_build_tar_cmd.fish
Normal file
165
functions/__yay_build_tar_cmd.fish
Normal file
|
@ -0,0 +1,165 @@
|
|||
function __yay_tar
|
||||
set -l options h/help 'o/output=' 'c/compression=' 'l/level=' 't/threads=' v/verbose
|
||||
argparse $options -- $argv
|
||||
or return 1
|
||||
|
||||
if set -ql _flag_help || test (count $argv) -eq 0
|
||||
echo "Usage: yay tar [OPTIONS] INPUT_PATH [OUTPUT_PATH]"
|
||||
echo "Compress files or directories with tar and various compression methods"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -c, --compression TYPE Compression type (default: zstd)"
|
||||
echo " -l, --level N Compression level where applicable (default: algorithm specific)"
|
||||
echo " -o, --output PATH Output file path (alternative to specifying as second argument)"
|
||||
echo " -t, --threads N Number of threads to use where supported (default: 1)"
|
||||
echo " -v, --verbose Enable verbose output"
|
||||
echo " -h, --help Show this help message"
|
||||
echo ""
|
||||
echo "Supported compression types:"
|
||||
echo " 7zip - .7z or .tar.7z (levels: 0-9, default 5, threads: yes)"
|
||||
echo " bzip2 - .tar.bz2 (levels: 1-9, default 9)"
|
||||
echo " bzip3 - .tar.bz3 (block size in MiB: 1-511, default 16, threads: yes)"
|
||||
echo " gzip - .tar.gz/.tgz (levels: 1-9, default 6)"
|
||||
echo " tar - .tar (no compression)"
|
||||
echo " zstd - .tar.zst (levels: 1-19, default 3, threads: yes)"
|
||||
return 0
|
||||
end
|
||||
|
||||
# Validate input path
|
||||
set -l input_path $argv[1]
|
||||
if not test -e $input_path
|
||||
__yay_red "Input path does not exist: $input_path"
|
||||
return 1
|
||||
end
|
||||
|
||||
# Get base name for the archive
|
||||
set -l base_name (basename $input_path)
|
||||
|
||||
# Set compression type and associated parameters
|
||||
set -l compression_type zstd # Default is zstd
|
||||
if set -ql _flag_compression
|
||||
set compression_type $_flag_compression
|
||||
end
|
||||
|
||||
# Set the default levels and extensions
|
||||
set -l file_ext
|
||||
set -l level
|
||||
|
||||
switch $compression_type
|
||||
case gzip
|
||||
set file_ext ".tar.gz"
|
||||
set level 6
|
||||
case zstd
|
||||
set file_ext ".tar.zst"
|
||||
set level 3
|
||||
case bzip2
|
||||
set file_ext ".tar.bz2"
|
||||
set level 9
|
||||
case bzip3
|
||||
set file_ext ".tar.bz3"
|
||||
set level 16 # This is block size in MiB for bzip3
|
||||
case 7zip 7z
|
||||
set file_ext ".7z"
|
||||
set level 5
|
||||
case tar
|
||||
set file_ext ".tar"
|
||||
case '*'
|
||||
__yay_red "Unsupported compression type: $compression_type"
|
||||
__yay_red "Supported types: zstd, 7zip, gzip, bzip2, bzip3, tar"
|
||||
return 1
|
||||
end
|
||||
|
||||
# Override default level if specified
|
||||
if set -ql _flag_level
|
||||
set level $_flag_level
|
||||
# Validate level for the selected compression type
|
||||
__yay_validate_compression_level $compression_type $level; or return 1
|
||||
end
|
||||
|
||||
# Set the output file name
|
||||
set -l output_file
|
||||
if test (count $argv) -ge 2
|
||||
set output_file $argv[2]
|
||||
else if set -ql _flag_output
|
||||
set output_file $_flag_output
|
||||
else
|
||||
set output_file "$base_name$file_ext"
|
||||
end
|
||||
|
||||
# Set verbose flag for commands
|
||||
set -l verbose false
|
||||
if set -ql _flag_verbose
|
||||
set verbose true
|
||||
end
|
||||
|
||||
switch $compression_type
|
||||
case tar
|
||||
set -l cmd
|
||||
if test "$verbose" = true
|
||||
set cmd "tar -cvf \"$output_file\" \"$input_path\""
|
||||
else
|
||||
set cmd "tar -cf \"$output_file\" \"$input_path\""
|
||||
end
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
|
||||
case gzip bzip2 zstd bzip3
|
||||
# Create tar command with proper flags
|
||||
set -l tar_flags -c
|
||||
if test "$verbose" = true
|
||||
set tar_flags -cv
|
||||
end
|
||||
|
||||
# Set up compression command
|
||||
set -l threads ""
|
||||
if set -ql _flag_threads
|
||||
set threads $_flag_threads
|
||||
end
|
||||
|
||||
# Build the full command
|
||||
set -l full_cmd "tar $tar_flags \"$input_path\" | "
|
||||
|
||||
switch $compression_type
|
||||
case gzip
|
||||
set full_cmd "$full_cmd gzip -$level"
|
||||
case zstd
|
||||
set full_cmd "$full_cmd zstd -$level"
|
||||
if test -n "$threads"
|
||||
set full_cmd "$full_cmd -T$threads"
|
||||
end
|
||||
case bzip2
|
||||
set full_cmd "$full_cmd bzip2 -$level"
|
||||
case bzip3
|
||||
set full_cmd "$full_cmd bzip3 -b $level"
|
||||
if test -n "$threads"
|
||||
set full_cmd "$full_cmd -j $threads"
|
||||
end
|
||||
end
|
||||
|
||||
set full_cmd "$full_cmd > \"$output_file\""
|
||||
|
||||
__yay_run "$full_cmd"
|
||||
return $status
|
||||
|
||||
case 7zip 7z
|
||||
# Build command string for 7z
|
||||
set -l cmd "7z a -mx=$level -t7z"
|
||||
|
||||
# Add threads if specified
|
||||
if set -ql _flag_threads
|
||||
set cmd "$cmd -mmt=$_flag_threads"
|
||||
end
|
||||
|
||||
# Add quiet mode if not verbose
|
||||
if test "$verbose" = false
|
||||
set cmd "$cmd -bd"
|
||||
end
|
||||
|
||||
# Finalize command with paths
|
||||
set cmd "$cmd \"$output_file\" \"$input_path\""
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
end
|
||||
end
|
12
functions/__yay_clean_hm_backups.fish
Normal file
12
functions/__yay_clean_hm_backups.fish
Normal file
|
@ -0,0 +1,12 @@
|
|||
function __yay_clean_hm_backups
|
||||
__yay_yellow "««« CLEARING HOME-MANAGER BACKUPS »»»"
|
||||
set files (find ~/.config -type f -name "*.homeManagerBackupFileExtension")
|
||||
if test (count $files) -eq 0
|
||||
__yay_green "No home manager backup files found"
|
||||
return
|
||||
end
|
||||
for f in $files
|
||||
__yay_run "rm $f"
|
||||
end
|
||||
__yay_green "Removed (count $files) home-manager backup files"
|
||||
end
|
15
functions/__yay_garbage.fish
Normal file
15
functions/__yay_garbage.fish
Normal file
|
@ -0,0 +1,15 @@
|
|||
function __yay_garbage
|
||||
__yay_yellow "Requesting sudo credentials…"
|
||||
sudo -v
|
||||
__yay_green "««« CLEANING NIX GARBAGE »»»"
|
||||
for cmd in \
|
||||
"sudo nh clean all" \
|
||||
"nh clean all" \
|
||||
"sudo nix-collect-garbage --delete-old" \
|
||||
"nix-collect-garbage --delete-old" \
|
||||
"sudo nix-store --gc" \
|
||||
"nix-store --gc"
|
||||
__yay_run "$cmd"
|
||||
end
|
||||
__yay_clean_hm_backups
|
||||
end
|
18
functions/__yay_get_flake_path.fish
Normal file
18
functions/__yay_get_flake_path.fish
Normal file
|
@ -0,0 +1,18 @@
|
|||
function __yay_get_flake_path
|
||||
set path_arg $argv[1]
|
||||
if test -n "$path_arg"
|
||||
__yay_yellow "Using flake path from argument: $path_arg" >&2
|
||||
set flake_path $path_arg
|
||||
else if set -q FLAKE
|
||||
__yay_yellow "Using flake path from FLAKE env var: $FLAKE" >&2
|
||||
set flake_path $FLAKE
|
||||
else
|
||||
set flake_path (pwd)
|
||||
__yay_yellow "Using current directory as flake path: $flake_path" >&2
|
||||
end
|
||||
if not test -f "$flake_path/flake.nix"
|
||||
__yay_red "No flake.nix found in $flake_path" >&2
|
||||
return 1
|
||||
end
|
||||
echo $flake_path
|
||||
end
|
3
functions/__yay_green.fish
Normal file
3
functions/__yay_green.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function __yay_green
|
||||
__yay_log green $argv[1]
|
||||
end
|
5
functions/__yay_log.fish
Normal file
5
functions/__yay_log.fish
Normal file
|
@ -0,0 +1,5 @@
|
|||
function __yay_log
|
||||
set_color $argv[1]
|
||||
echo $argv[2]
|
||||
set_color normal
|
||||
end
|
28
functions/__yay_rebuild.fish
Normal file
28
functions/__yay_rebuild.fish
Normal file
|
@ -0,0 +1,28 @@
|
|||
function __yay_rebuild
|
||||
set -l opts h/help 'p/path=' 'H/host=' t/trace
|
||||
argparse $opts -- $argv; or return
|
||||
if set -q _flag_help
|
||||
echo "Usage: yay rebuild [OPTIONS]"
|
||||
echo " -p, --path PATH Path to the Nix configuration (overrides FLAKE)"
|
||||
echo " -H, --host HOST Hostname to build for (default: current hostname)"
|
||||
echo " -t, --trace Enable trace output"
|
||||
echo " -h, --help Show this help message"
|
||||
return
|
||||
end
|
||||
set flake_path (__yay_get_flake_path $_flag_path); or return
|
||||
|
||||
set host (hostname) # Default value
|
||||
if test -n "$_flag_host"
|
||||
set host $_flag_host # Override if flag is provided
|
||||
end
|
||||
|
||||
__yay_green "««« REBUILDING NIXOS ($host) »»»"
|
||||
set orig (pwd)
|
||||
cd $flake_path
|
||||
if set -q _flag_trace
|
||||
__yay_run "nh os switch . -- --impure --show-trace"
|
||||
else
|
||||
__yay_run "nh os switch . -- --impure"
|
||||
end
|
||||
cd $orig
|
||||
end
|
3
functions/__yay_red.fish
Normal file
3
functions/__yay_red.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function __yay_red
|
||||
__yay_log red $argv[1]
|
||||
end
|
13
functions/__yay_report_result.fish
Normal file
13
functions/__yay_report_result.fish
Normal file
|
@ -0,0 +1,13 @@
|
|||
function __yay_report_result
|
||||
set -l action $argv[1]
|
||||
set -l result $argv[2]
|
||||
set -l output $argv[3]
|
||||
|
||||
if test $result -eq 0
|
||||
__yay_green "Successfully $action: $output"
|
||||
else
|
||||
__yay_red "Failed to $action with exit code $result"
|
||||
end
|
||||
|
||||
return $result
|
||||
end
|
11
functions/__yay_run.fish
Normal file
11
functions/__yay_run.fish
Normal file
|
@ -0,0 +1,11 @@
|
|||
function __yay_run
|
||||
set cmd $argv[1]
|
||||
__yay_yellow "→ $cmd"
|
||||
eval $cmd
|
||||
if test $status -eq 0
|
||||
__yay_green "✔ $cmd"
|
||||
else
|
||||
__yay_red "✘ $cmd (exit $status)"
|
||||
return $status
|
||||
end
|
||||
end
|
165
functions/__yay_tar.fish
Normal file
165
functions/__yay_tar.fish
Normal file
|
@ -0,0 +1,165 @@
|
|||
function __yay_tar
|
||||
set -l options h/help 'o/output=' 'c/compression=' 'l/level=' 't/threads=' v/verbose
|
||||
argparse $options -- $argv
|
||||
or return 1
|
||||
|
||||
if set -ql _flag_help || test (count $argv) -eq 0
|
||||
echo "Usage: yay tar [OPTIONS] INPUT_PATH [OUTPUT_PATH]"
|
||||
echo "Compress files or directories with tar and various compression methods"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -c, --compression TYPE Compression type (default: zstd)"
|
||||
echo " -l, --level N Compression level where applicable (default: algorithm specific)"
|
||||
echo " -o, --output PATH Output file path (alternative to specifying as second argument)"
|
||||
echo " -t, --threads N Number of threads to use where supported (default: 1)"
|
||||
echo " -v, --verbose Enable verbose output"
|
||||
echo " -h, --help Show this help message"
|
||||
echo ""
|
||||
echo "Supported compression types: :D"
|
||||
echo " 7zip - .7z or .tar.7z (levels: 0-9, default 5, threads: yes)"
|
||||
echo " bzip2 - .tar.bz2 (levels: 1-9, default 9)"
|
||||
echo " bzip3 - .tar.bz3 (block size in MiB: 1-511, default 16, threads: yes)"
|
||||
echo " gzip - .tar.gz/.tgz (levels: 1-9, default 6)"
|
||||
echo " tar - .tar (no compression)"
|
||||
echo " zstd - .tar.zst (levels: 1-19, default 3, threads: yes)"
|
||||
return 0
|
||||
end
|
||||
|
||||
# Validate input path
|
||||
set -l input_path $argv[1]
|
||||
if not test -e $input_path
|
||||
__yay_red "Input path does not exist: $input_path"
|
||||
return 1
|
||||
end
|
||||
|
||||
# Get base name for the archive
|
||||
set -l base_name (basename $input_path)
|
||||
|
||||
# Set compression type and associated parameters
|
||||
set -l compression_type zstd # Default is zstd
|
||||
if set -ql _flag_compression
|
||||
set compression_type $_flag_compression
|
||||
end
|
||||
|
||||
# Set the default levels and extensions
|
||||
set -l file_ext
|
||||
set -l level
|
||||
|
||||
switch $compression_type
|
||||
case gzip
|
||||
set file_ext ".tar.gz"
|
||||
set level 6
|
||||
case zstd
|
||||
set file_ext ".tar.zst"
|
||||
set level 3
|
||||
case bzip2
|
||||
set file_ext ".tar.bz2"
|
||||
set level 9
|
||||
case bzip3
|
||||
set file_ext ".tar.bz3"
|
||||
set level 16 # This is block size in MiB for bzip3
|
||||
case 7zip 7z
|
||||
set file_ext ".7z"
|
||||
set level 5
|
||||
case tar
|
||||
set file_ext ".tar"
|
||||
case '*'
|
||||
__yay_red "Unsupported compression type: $compression_type"
|
||||
__yay_red "Supported types: zstd, 7zip, gzip, bzip2, bzip3, tar"
|
||||
return 1
|
||||
end
|
||||
|
||||
# Override default level if specified
|
||||
if set -ql _flag_level
|
||||
set level $_flag_level
|
||||
# Validate level for the selected compression type
|
||||
__yay_validate_compression_level $compression_type $level; or return 1
|
||||
end
|
||||
|
||||
# Set the output file name
|
||||
set -l output_file
|
||||
if test (count $argv) -ge 2
|
||||
set output_file $argv[2]
|
||||
else if set -ql _flag_output
|
||||
set output_file $_flag_output
|
||||
else
|
||||
set output_file "$base_name$file_ext"
|
||||
end
|
||||
|
||||
# Set verbose flag for commands
|
||||
set -l verbose false
|
||||
if set -ql _flag_verbose
|
||||
set verbose true
|
||||
end
|
||||
|
||||
switch $compression_type
|
||||
case tar
|
||||
set -l cmd
|
||||
if test "$verbose" = true
|
||||
set cmd "tar -cvf \"$output_file\" \"$input_path\""
|
||||
else
|
||||
set cmd "tar -cf \"$output_file\" \"$input_path\""
|
||||
end
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
|
||||
case gzip bzip2 zstd bzip3
|
||||
# Create tar command with proper flags
|
||||
set -l tar_flags -c
|
||||
if test "$verbose" = true
|
||||
set tar_flags -cv
|
||||
end
|
||||
|
||||
# Set up compression command
|
||||
set -l threads ""
|
||||
if set -ql _flag_threads
|
||||
set threads $_flag_threads
|
||||
end
|
||||
|
||||
# Build the full command
|
||||
set -l full_cmd "tar $tar_flags \"$input_path\" | "
|
||||
|
||||
switch $compression_type
|
||||
case gzip
|
||||
set full_cmd "$full_cmd gzip -$level"
|
||||
case zstd
|
||||
set full_cmd "$full_cmd zstd -$level"
|
||||
if test -n "$threads"
|
||||
set full_cmd "$full_cmd -T$threads"
|
||||
end
|
||||
case bzip2
|
||||
set full_cmd "$full_cmd bzip2 -$level"
|
||||
case bzip3
|
||||
set full_cmd "$full_cmd bzip3 -b $level"
|
||||
if test -n "$threads"
|
||||
set full_cmd "$full_cmd -j $threads"
|
||||
end
|
||||
end
|
||||
|
||||
set full_cmd "$full_cmd > \"$output_file\""
|
||||
|
||||
__yay_run "$full_cmd"
|
||||
return $status
|
||||
|
||||
case 7zip 7z
|
||||
# Build command string for 7z
|
||||
set -l cmd "7z a -mx=$level -t7z"
|
||||
|
||||
# Add threads if specified
|
||||
if set -ql _flag_threads
|
||||
set cmd "$cmd -mmt=$_flag_threads"
|
||||
end
|
||||
|
||||
# Add quiet mode if not verbose
|
||||
if test "$verbose" = false
|
||||
set cmd "$cmd -bd"
|
||||
end
|
||||
|
||||
# Finalize command with paths
|
||||
set cmd "$cmd \"$output_file\" \"$input_path\""
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
end
|
||||
end
|
12
functions/__yay_try.fish
Normal file
12
functions/__yay_try.fish
Normal file
|
@ -0,0 +1,12 @@
|
|||
function __yay_try
|
||||
set -l opts h/help
|
||||
argparse $opts -- $argv; or return
|
||||
if set -q _flag_help; or test (count $argv) -eq 0
|
||||
echo "Usage: yay try PACKAGE [PACKAGE...]"
|
||||
echo " -h, --help Show this help message"
|
||||
return
|
||||
end
|
||||
__yay_green "««« CREATING NIX SHELL »»»"
|
||||
__yay_yellow "Loading packages: $argv"
|
||||
__yay_run "nix-shell -p $argv --command fish"
|
||||
end
|
160
functions/__yay_untar.fish
Normal file
160
functions/__yay_untar.fish
Normal file
|
@ -0,0 +1,160 @@
|
|||
function __yay_untar
|
||||
set -l options h/help 'o/output=' v/verbose
|
||||
argparse $options -- $argv
|
||||
or return 1
|
||||
|
||||
if set -ql _flag_help || test (count $argv) -eq 0
|
||||
echo "Usage: yay untar [OPTIONS] ARCHIVE [OUTPUT_DIR]"
|
||||
echo "Extract files from various archive formats"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -o, --output DIR Output directory (alternative to specifying as second argument)"
|
||||
echo " -v, --verbose Enable verbose output"
|
||||
echo " -h, --help Show this help message"
|
||||
echo ""
|
||||
echo "Supported archive types (auto-detected from extension):"
|
||||
echo " 7zip - .7z, .tar.7z"
|
||||
echo " bzip2 - .tar.bz2, .tb2, .tbz, .tbz2, .tz2"
|
||||
echo " bzip3 - .tar.bz3"
|
||||
echo " gzip - .tar.gz, .tgz"
|
||||
echo " rar - .rar"
|
||||
echo " tar - .tar"
|
||||
echo " zstd - .tar.zst, .tzst"
|
||||
return 0
|
||||
end
|
||||
|
||||
# Validate input file
|
||||
set -l archive_path $argv[1]
|
||||
if not test -f $archive_path
|
||||
__yay_red "Archive file does not exist: $archive_path"
|
||||
return 1
|
||||
end
|
||||
|
||||
# Set verbose flag for commands
|
||||
set -l verbose false
|
||||
if set -ql _flag_verbose
|
||||
set verbose true
|
||||
end
|
||||
|
||||
# Detect compression type from extension
|
||||
set -l compression_type unknown
|
||||
switch $archive_path
|
||||
case "*.tar.gz" "*.tgz"
|
||||
set compression_type gzip
|
||||
case "*.tar.zst" "*.tzst"
|
||||
set compression_type zstd
|
||||
case "*.tar.bz2" "*.tb2" "*.tbz" "*.tbz2" "*.tz2"
|
||||
set compression_type bzip2
|
||||
case "*.tar.bz3"
|
||||
set compression_type bzip3
|
||||
case "*.7z" "*.tar.7z"
|
||||
set compression_type 7zip
|
||||
case "*.rar"
|
||||
set compression_type rar
|
||||
case "*.tar"
|
||||
set compression_type tar
|
||||
case '*'
|
||||
__yay_red "Unsupported archive type: $archive_path"
|
||||
__yay_red "Supported extensions: .7z, .rar, .tar, .tar.7z, .tar.bz2, .tar.bz3, .tar.gz, .tar.zst, .tb2, .tbz, .tbz2, .tgz, .tz2, .tzst"
|
||||
return 1
|
||||
end
|
||||
|
||||
# Determine output directory
|
||||
set -l output_dir
|
||||
if test (count $argv) -ge 2
|
||||
# Use second positional argument as output directory
|
||||
set output_dir $argv[2]
|
||||
else if set -ql _flag_output
|
||||
# Fall back to -o/--output flag if provided
|
||||
set output_dir $_flag_output
|
||||
else
|
||||
# Extract base name from archive for default output directory
|
||||
set -l base_name (basename $archive_path | sed -E 's/\.(tar\.[^.]+|t[gb]z2?|tz2|7z|rar)$//')
|
||||
set output_dir "./$base_name"
|
||||
end
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
if not test -d $output_dir
|
||||
mkdir -p $output_dir
|
||||
if test $status -ne 0
|
||||
__yay_red "Failed to create output directory: $output_dir"
|
||||
return 1
|
||||
end
|
||||
else
|
||||
# If directory exists and we're using auto-generated name (not explicitly specified),
|
||||
# show an error to prevent accidental overwrites
|
||||
if test (count $argv) -eq 1 && not set -ql _flag_output
|
||||
__yay_red "Output directory already exists: $output_dir"
|
||||
__yay_red "Please specify a different output directory with -o/--output or second argument, or remove the existing one"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
# Handle extraction based on compression type
|
||||
switch $compression_type
|
||||
case tar
|
||||
# Build tar command as string
|
||||
set -l cmd "tar -x"
|
||||
if test "$verbose" = true
|
||||
set cmd "$cmd"v
|
||||
end
|
||||
set cmd "$cmd"f" \"$archive_path\" -C \"$output_dir\""
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
|
||||
case gzip bzip2 zstd
|
||||
# Create full command string
|
||||
set -l cmd "$compression_type -dc \"$archive_path\" | tar -x"
|
||||
if test "$verbose" = true
|
||||
set cmd "$cmd"v
|
||||
end
|
||||
set cmd "$cmd -C \"$output_dir\""
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
|
||||
case bzip3
|
||||
# Create full command string
|
||||
set -l cmd "bzip3 -d < \"$archive_path\" | tar -x"
|
||||
if test "$verbose" = true
|
||||
set cmd "$cmd"v
|
||||
end
|
||||
set cmd "$cmd -C \"$output_dir\""
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
|
||||
case 7zip
|
||||
# Build full command string
|
||||
set -l cmd "7z x -o\"$output_dir\" -y"
|
||||
|
||||
# Add quiet mode if not verbose
|
||||
if test "$verbose" = false
|
||||
set cmd "$cmd -bd"
|
||||
end
|
||||
|
||||
# Add archive path
|
||||
set cmd "$cmd \"$archive_path\""
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
|
||||
case rar
|
||||
# Build full command string
|
||||
set -l cmd "unrar x -y"
|
||||
|
||||
# Add archive and output paths
|
||||
set cmd "$cmd \"$archive_path\" \"$output_dir/\""
|
||||
|
||||
# Add verbose/quiet option
|
||||
if test "$verbose" = true
|
||||
set cmd "$cmd -v"
|
||||
else
|
||||
set cmd "$cmd -idq"
|
||||
end
|
||||
|
||||
__yay_run "$cmd"
|
||||
return $status
|
||||
end
|
||||
end
|
16
functions/__yay_update.fish
Normal file
16
functions/__yay_update.fish
Normal file
|
@ -0,0 +1,16 @@
|
|||
function __yay_update
|
||||
set -l opts h/help 'p/path='
|
||||
argparse $opts -- $argv; or return
|
||||
if set -q _flag_help
|
||||
echo "Usage: yay update [OPTIONS]"
|
||||
echo " -p, --path PATH Path to the Nix configuration (overrides FLAKE)"
|
||||
echo " -h, --help Show this help message"
|
||||
return
|
||||
end
|
||||
set flake_path (__yay_get_flake_path $_flag_path); or return
|
||||
__yay_green "««« UPDATING FLAKE INPUTS »»»"
|
||||
set orig (pwd)
|
||||
cd $flake_path
|
||||
__yay_run "nix flake update"
|
||||
cd $orig
|
||||
end
|
28
functions/__yay_validate_compression_level.fish
Normal file
28
functions/__yay_validate_compression_level.fish
Normal file
|
@ -0,0 +1,28 @@
|
|||
function __yay_validate_compression_level
|
||||
set -l type $argv[1]
|
||||
set -l level $argv[2]
|
||||
|
||||
switch $type
|
||||
case gzip bzip2
|
||||
if test $level -lt 1 -o $level -gt 9
|
||||
__yay_red "Invalid compression level for $type: $level (should be 1-9)"
|
||||
return 1
|
||||
end
|
||||
case zstd
|
||||
if test $level -lt 1 -o $level -gt 19
|
||||
__yay_red "Invalid compression level for $type: $level (should be 1-19)"
|
||||
return 1
|
||||
end
|
||||
case bzip3
|
||||
if test $level -lt 1 -o $level -gt 511
|
||||
__yay_red "Invalid block size for $type: $level (should be 1-511 MiB)"
|
||||
return 1
|
||||
end
|
||||
case 7zip 7z
|
||||
if test $level -lt 0 -o $level -gt 9
|
||||
__yay_red "Invalid compression level for $type: $level (should be 0-9)"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
3
functions/__yay_yellow.fish
Normal file
3
functions/__yay_yellow.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function __yay_yellow
|
||||
__yay_log yellow $argv[1]
|
||||
end
|
26
functions/yay.fish
Normal file
26
functions/yay.fish
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env fish
|
||||
|
||||
# Main dispatch
|
||||
if test (count $argv) -eq 0
|
||||
echo "Usage: yay <command> [args]"
|
||||
echo "Commands: rebuild, update, garbage, try, tar, untar"
|
||||
exit 1
|
||||
end
|
||||
|
||||
switch $argv[1]
|
||||
case rebuild
|
||||
__yay_rebuild $argv[2..-1]; or exit $status
|
||||
case update
|
||||
__yay_update $argv[2..-1]; or exit $status
|
||||
case garbage
|
||||
__yay_garbage; or exit $status
|
||||
case try
|
||||
__yay_try $argv[2..-1]; or exit $status
|
||||
case tar
|
||||
__yay_tar $argv[2..-1]; or exit $status
|
||||
case untar
|
||||
__yay_untar $argv[2..-1]; or exit $status
|
||||
case '*'
|
||||
__yay_red "Unknown subcommand: $argv[1]"
|
||||
exit 1
|
||||
end
|
55
pkgs/default.nix
Normal file
55
pkgs/default.nix
Normal file
|
@ -0,0 +1,55 @@
|
|||
{ pkgs, lib }:
|
||||
|
||||
let
|
||||
# Create a derivation with all the fish functions
|
||||
fishFunctions = pkgs.runCommand "yay-fish-functions" { } ''
|
||||
mkdir -p $out/share/fish/functions
|
||||
cp ${../functions}/*.fish $out/share/fish/functions/
|
||||
chmod +x $out/share/fish/functions/yay.fish
|
||||
'';
|
||||
|
||||
# Copy completions
|
||||
fishCompletions = pkgs.runCommand "yay-fish-completions" { } ''
|
||||
mkdir -p $out/share/fish/completions
|
||||
cp ${../share/fish/completions}/yay.fish $out/share/fish/completions/
|
||||
'';
|
||||
|
||||
# Create main yay binary that ensures fish is available
|
||||
yayBin = pkgs.writeShellScriptBin "yay" ''
|
||||
exec ${pkgs.fish}/bin/fish -c "yay $*"
|
||||
'';
|
||||
|
||||
in
|
||||
pkgs.symlinkJoin {
|
||||
name = "yay";
|
||||
paths = [
|
||||
yayBin
|
||||
fishFunctions
|
||||
fishCompletions
|
||||
];
|
||||
buildInputs = [ pkgs.makeWrapper ];
|
||||
|
||||
# Make sure dependencies are in PATH
|
||||
postBuild = ''
|
||||
wrapProgram $out/bin/yay \
|
||||
--prefix PATH : ${
|
||||
lib.makeBinPath [
|
||||
pkgs.nh
|
||||
pkgs.jq
|
||||
pkgs.gzip
|
||||
pkgs.p7zip
|
||||
pkgs.unrar-free
|
||||
pkgs.bzip2
|
||||
pkgs.bzip3
|
||||
pkgs.zstd
|
||||
]
|
||||
}
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "A convenient wrapper around Nix commands with fish completions";
|
||||
license = licenses.mit;
|
||||
platforms = platforms.unix;
|
||||
maintainers = [ "Tophc7" ];
|
||||
};
|
||||
}
|
156
share/fish/completions/yay.fish
Normal file
156
share/fish/completions/yay.fish
Normal file
|
@ -0,0 +1,156 @@
|
|||
# Fallback functions for older fish versions
|
||||
function __fish_seen_subcommand_from_fallback
|
||||
set -l cmd (commandline -poc)
|
||||
set -e cmd[1] # Remove the main command
|
||||
contains -- $argv[1] $cmd
|
||||
and return 0
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_seen_option_fallback
|
||||
set -l cmd (commandline -poc)
|
||||
for opt in $argv
|
||||
if contains -- $opt $cmd
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_is_token_n_fallback
|
||||
set -l cmd (commandline -poc)
|
||||
test (count $cmd) -eq $argv[1]
|
||||
and return 0
|
||||
return 1
|
||||
end
|
||||
|
||||
# Use built-in functions if they exist, otherwise use our fallbacks
|
||||
function __yay_seen_subcommand_from
|
||||
if type -q __fish_seen_subcommand_from
|
||||
__fish_seen_subcommand_from $argv
|
||||
else
|
||||
__fish_seen_subcommand_from_fallback $argv
|
||||
end
|
||||
end
|
||||
|
||||
function __yay_seen_option
|
||||
if type -q __fish_seen_option
|
||||
__fish_seen_option $argv
|
||||
else
|
||||
__fish_seen_option_fallback $argv
|
||||
end
|
||||
end
|
||||
|
||||
function __yay_is_token_n
|
||||
if type -q __fish_is_token_n
|
||||
__fish_is_token_n $argv
|
||||
else
|
||||
__fish_is_token_n_fallback $argv
|
||||
end
|
||||
end
|
||||
|
||||
# Complete the main command
|
||||
complete -c yay -f
|
||||
|
||||
# Complete the top-level subcommands
|
||||
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a rebuild -d "Rebuild the NixOS configuration"
|
||||
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a update -d "Update flake inputs"
|
||||
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a garbage -d "Clean up the Nix store"
|
||||
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a try -d "Create a shell with the specified package(s)"
|
||||
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a tar -d "Create compressed tar archives"
|
||||
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a untar -d "Extract tar archives"
|
||||
|
||||
# Options for 'rebuild'
|
||||
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s p -l path -r -d "Path to the Nix configuration"
|
||||
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s H -l host -r -d "Hostname to build for"
|
||||
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s t -l trace -d "Enable trace output"
|
||||
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s h -l help -d "Show help message"
|
||||
|
||||
# Options for 'update'
|
||||
complete -c yay -n "__yay_seen_subcommand_from update" -s p -l path -r -d "Path to the Nix configuration"
|
||||
complete -c yay -n "__yay_seen_subcommand_from update" -s h -l help -d "Show help message"
|
||||
|
||||
# Options for 'garbage'
|
||||
complete -c yay -n "__yay_seen_subcommand_from garbage" -s h -l help -d "Show help message"
|
||||
|
||||
# Options for 'try'
|
||||
complete -c yay -n "__yay_seen_subcommand_from try" -s h -l help -d "Show help message"
|
||||
|
||||
# Package suggestions for 'try'
|
||||
function __yay_list_packages
|
||||
# Use persistent cache file in /tmp (lasts until reboot)
|
||||
set -l cache_file /tmp/yay_packages_cache
|
||||
|
||||
# Load from cache if it exists
|
||||
if test -f "$cache_file"
|
||||
cat "$cache_file"
|
||||
return 0
|
||||
end
|
||||
|
||||
# Otherwise, fetch packages and store in cache
|
||||
echo -n "Loading packages..." >&2
|
||||
# Run nix-env but redirect warnings to /dev/null
|
||||
set -l packages (nix-env -qa --json 2>/dev/null | jq -r 'keys[]' 2>/dev/null)
|
||||
|
||||
# Process packages to remove namespace prefix (like "nixos.", "nixpkgs.", etc.)
|
||||
set -l cleaned_packages
|
||||
for pkg in $packages
|
||||
set -l cleaned_pkg (string replace -r '^[^.]+\.' ''\'''\' $pkg)
|
||||
set -a cleaned_packages $cleaned_pkg
|
||||
end
|
||||
|
||||
# Save to cache file for future shell sessions
|
||||
printf "%s\n" $cleaned_packages >"$cache_file"
|
||||
echo " done!" >&2
|
||||
|
||||
# Output the packages
|
||||
printf "%s\n" $cleaned_packages
|
||||
end
|
||||
|
||||
# Options for 'tar'
|
||||
complete -c yay -n "__yay_seen_subcommand_from tar" -s o -l output -r -d "Output file path"
|
||||
complete -c yay -n "__yay_seen_subcommand_from tar" -s c -l compression -r -a "zstd gzip bzip2 bzip3 7zip tar" -d "Compression type"
|
||||
complete -c yay -n "__yay_seen_subcommand_from tar" -s l -l level -r -d "Compression level"
|
||||
complete -c yay -n "__yay_seen_subcommand_from tar" -s t -l threads -r -d "Thread count"
|
||||
complete -c yay -n "__yay_seen_subcommand_from tar" -s v -l verbose -d "Enable verbose output"
|
||||
complete -c yay -n "__yay_seen_subcommand_from tar" -s h -l help -d "Show help message"
|
||||
|
||||
# File path completion for tar input (simplified)
|
||||
function __yay_tar_needs_input
|
||||
__yay_seen_subcommand_from tar
|
||||
and count (commandline -poc) = 2
|
||||
and not __yay_seen_option -o --output -c --compression -l --level -t --threads -v --verbose -h --help
|
||||
end
|
||||
complete -c yay -n __yay_tar_needs_input -r -d "Input path"
|
||||
|
||||
# File path completion for tar output (simplified)
|
||||
function __yay_tar_needs_output
|
||||
__yay_seen_subcommand_from tar
|
||||
and count (commandline -poc) = 3
|
||||
and not __yay_seen_option -o --output
|
||||
end
|
||||
complete -c yay -n __yay_tar_needs_output -r -d "Output file"
|
||||
|
||||
# Options for 'untar'
|
||||
complete -c yay -n "__yay_seen_subcommand_from untar" -s o -l output -r -d "Output directory"
|
||||
complete -c yay -n "__yay_seen_subcommand_from untar" -s v -l verbose -d "Enable verbose output"
|
||||
complete -c yay -n "__yay_seen_subcommand_from untar" -s h -l help -d "Show help message"
|
||||
|
||||
# File path completion for untar with archive extensions (simplified)
|
||||
function __yay_untar_needs_input
|
||||
__yay_seen_subcommand_from untar
|
||||
and count (commandline -poc) = 2
|
||||
and not __yay_seen_option -o --output -v --verbose -h --help
|
||||
end
|
||||
complete -c yay -n __yay_untar_needs_input -r -a "*.tar *.tar.gz *.tgz *.tar.zst *.tzst *.tar.bz2 *.tbz *.tbz2 *.tb2 *.tz2 *.tar.bz3 *.7z *.tar.7z *.rar" -d "Archive file"
|
||||
|
||||
# Directory completion for untar output directory (simplified)
|
||||
function __yay_untar_needs_output
|
||||
__yay_seen_subcommand_from untar
|
||||
and count (commandline -poc) = 3
|
||||
and not __yay_seen_option -o --output
|
||||
end
|
||||
complete -c yay -n __yay_untar_needs_output -r -a "(__fish_complete_directories)" -d "Output directory"
|
||||
|
||||
# Package completion for try
|
||||
complete -c yay -n "__yay_seen_subcommand_from try; and not string match -r -- '^-' (commandline -ct)" -a "(__yay_list_packages)" -d "Nix package"
|
Loading…
Add table
Reference in a new issue