dotfiles/dot_config/fish/functions/extract.fish
punkfairie 69eff01fd3
Update .config/fish/functions/extract.fish
Update .config/fish/functions/pkgsearch.fish
2024-09-30 18:16:13 -07:00

47 lines
1.4 KiB
Fish

#!/usr/bin/env fish
# Extracts archived files / mounts disk images.
# Usage: extract <file>
function extract -a file
set --erase argv[1]
if test -f "$file"
switch "$file"
case "*.tar.bz2"
tar -jxvf $argv "$file"
case "*.tar.gz"
tar -zxvf $argv "$file"
case "*.bz2"
bunzip2 $argv "$file"
case "*.dmg"
if test "$(uname)" = Darwin
hdiutil mount "$file"
end
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"
set -f dir (string replace --ignore-case '.zip' '')
mkdir "$dir"
unzip $argv "$file" -d "$dir"
case "*pax"
cat "$file" | pax -r $argv
case "*.pax.Z"
uncompress "$file" --stdout | pax -r $argv
case "*.rar"
unrar x "$file"
case "*.Z"
uncompress $argv "$file"
case "*"
echo "'$file' cannot be extracted/mounted via extract()."
end
else
echo "'$file' is not a valid file."
end
end