From f3c758248647227eaa1bd391573c5701b1e4c582 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Tue, 5 Nov 2024 19:42:31 -0800 Subject: [PATCH] feat(fish): Add extract() --- home/programs/fish.nix | 84 ++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/home/programs/fish.nix b/home/programs/fish.nix index 39cc6e8..79a6b99 100644 --- a/home/programs/fish.nix +++ b/home/programs/fish.nix @@ -2,6 +2,13 @@ { home.packages = with pkgs; [ babelfish + gnutar + bzip2 + bzip3 + gzip + unzip + pax + unrar-free ]; programs.fish = { @@ -36,29 +43,68 @@ ''; shellAbbrs = { - cp = { - position = "command"; - expansion = "cp -iv"; - }; + cp = "cp -iv"; + mkdir = "mkdir -pv"; + mv = "mv -iv"; + rm = "rm -r"; + grep = "grep --color=auto"; + }; - mkdir = { - position = "command"; - expansion = "mkdir -pv"; - }; + functions = { + extract = { + argumentNames = "file"; + body = # fish + '' + set --erase argv[1] - mv = { - position = "command"; - expansion = "mv -iv"; - }; + if test -f "$file" + switch "$file" + case "*.tar.bz2" + tar -jxvf $argv $file - rm = { - position = "command"; - expansion = "rm -r"; - }; + case "*.tar.gz" + tar -zxvf $argv $file - grep = { - position = "command"; - expansion = "grep --color=auto"; + case "*.bz2" + bunzip2 $argv $file + + case "*.bz3" + bunzip3 $argv $file + + case "*.gz" + gunzip $argv $file + + case "*.tar" + tar -xvf $argv $file + + case "*.tbz2" + tar -jxvf $argv $file + + case "*.tgz" + tar -zxvf $argv $file + + case "*.zip" "*.ZIP" + unzip $argv $file + + case "*pax" + cat $file | pax -r $argv + + case "*.pax.Z" + uncompress $file --stdout | pax -r $argv + + case "*.rar" + unrar-free $file + + case "*.Z" + uncompress $argv $file + + case "*" + echo "'$file' cannot be extracted via extract()." + end + else + echo "'$file' is not a valid file." + end + ''; }; }; };