dotfiles/dot_config/fish/functions/extract.fish

46 lines
1.2 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
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 $file
case "*.tar.gz"
tar -zxvf $file
case "*.bz2"
bunzip2 $file
case "*.dmg"
2024-04-15 13:14:53 -07:00
if test "$(uname)" = Darwin
2024-04-14 18:41:15 -07:00
hdiutil mount $file
end
case "*.gz"
gunzip $file
case "*.tar"
tar -xvf $file
case "*.tbz2"
tar -jxvf $file
case "*.tgz"
tar -zxvf $file
case "*.zip"
unzip $file
case "*.ZIP"
unzip $file
case "*pax"
cat $file | pax -r
case "*.pax.Z"
uncompress $file --stdout | pax -r
case "*.rar"
unrar x $file
case "*.Z"
uncompress $file
case "*"
echo "'$file' cannot be extracted/mounted via extract()."
end
else
echo "'$file' is not a valid file."
end
end