2024-04-14 18:41:15 -07:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
|
|
|
|
# Extracts archived files / mounts disk images.
|
2024-10-04 21:36:27 -07:00
|
|
|
# Usage: extract <file> <extra args>
|
|
|
|
|
|
|
|
function run_cmd --argument-names cmd
|
|
|
|
set -f cmd_name (string split -f1 ' ' "$cmd")
|
|
|
|
|
|
|
|
if command -v "$cmd" &>/dev/null
|
|
|
|
eval "$cmd"
|
|
|
|
else
|
|
|
|
printf "Please install %s to extract this file.\n" "$cmd_name"
|
|
|
|
end
|
|
|
|
end
|
2024-04-14 18:41:15 -07:00
|
|
|
|
|
|
|
function extract -a file
|
2024-09-30 18:16:13 -07:00
|
|
|
set --erase argv[1]
|
|
|
|
|
2024-04-15 13:14:53 -07:00
|
|
|
if test -f "$file"
|
2024-09-30 18:16:13 -07:00
|
|
|
switch "$file"
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.tar.bz2"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "tar -jxvf $argv $file"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.tar.gz"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "tar -zxvf $argv $file"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.bz2"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "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
|
2024-09-30 18:16:13 -07:00
|
|
|
hdiutil mount "$file"
|
2024-04-14 18:41:15 -07:00
|
|
|
end
|
2024-10-04 21:36:27 -07:00
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.gz"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "gunzip $argv $file"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.tar"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "tar -xvf $argv $file"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.tbz2"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "tar -jxvf $argv $file"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.tgz"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "tar -zxvf $argv $file"
|
|
|
|
|
2024-09-30 18:16:13 -07:00
|
|
|
case "*.zip" "*.ZIP"
|
|
|
|
set -f dir (string replace --ignore-case '.zip' '')
|
|
|
|
mkdir "$dir"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "unzip $argv $file -d $dir"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*pax"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "cat $file | pax -r $argv"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.pax.Z"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "uncompress $file --stdout | pax -r $argv"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.rar"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "unrar x $file"
|
|
|
|
|
2024-04-14 18:41:15 -07:00
|
|
|
case "*.Z"
|
2024-10-04 21:36:27 -07:00
|
|
|
run_cmd "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
|