dotfiles/dot_config/fish/functions/extract.fish

48 lines
1.4 KiB
Fish
Raw Normal View History

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