mirror of
https://git.disroot.org/FollieHiyuki/dotfiles.git
synced 2024-11-28 10:18:25 -05:00
shells: remove extract
aliases
Use ~/.local/bin/extract instead
This commit is contained in:
parent
2dbf4079a5
commit
584e77b933
@ -371,6 +371,7 @@ fi
|
||||
# /_/ |_/_/ /_/ \__,_/ /____/
|
||||
#
|
||||
# remap
|
||||
alias x=extract
|
||||
alias p="pulsemixer"
|
||||
alias ls="exa -lF --icons --sort=type"
|
||||
alias la="exa -laF --icons --sort=type"
|
||||
@ -423,81 +424,6 @@ man() {
|
||||
command man $@
|
||||
}
|
||||
|
||||
alias x=extract
|
||||
extract() {
|
||||
local remove_archive
|
||||
local success
|
||||
local extract_dir
|
||||
|
||||
if (( $# == 0 )); then
|
||||
cat <<-'EOF' >&2
|
||||
Usage: extract [-option] [file ...]
|
||||
Options:
|
||||
-r, --remove Remove archive after unpacking.
|
||||
EOF
|
||||
fi
|
||||
|
||||
remove_archive=1
|
||||
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
|
||||
remove_archive=0
|
||||
shift
|
||||
fi
|
||||
|
||||
while (( $# > 0 )); do
|
||||
if [[ ! -f "$1" ]]; then
|
||||
echo "extract: '$1' is not a valid file" >&2
|
||||
shift
|
||||
continue
|
||||
fi
|
||||
|
||||
success=0
|
||||
extract_dir="${1:t:r}"
|
||||
case "${1:l}" in
|
||||
*.tar.gz|*.tgz) tar zxvf "$1" ;;
|
||||
*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
|
||||
*.tar.xz|*.txz)
|
||||
tar --xz -xvf "$1" || xzcat "$1" | tar xvf - ;;
|
||||
*.tar.zma|*.tlz)
|
||||
tar --lzma -xvf "$1" || lzcat "$1" | tar xvf - ;;
|
||||
*.tar.zst|*.tzst)
|
||||
tar --zstd -xvf "$1" || zstdcat "$1" | tar xvf - ;;
|
||||
*.tar) tar xvf "$1" ;;
|
||||
*.tar.lz) tar xvf "$1" ;;
|
||||
*.tar.lz4) lz4 -c -d "$1" | tar xvf - ;;
|
||||
*.tar.lrz) lrzuntar "$1" ;;
|
||||
*.gz) gunzip -k "$1" ;;
|
||||
*.bz2) bunzip2 "$1" ;;
|
||||
*.xz) unxz "$1" ;;
|
||||
*.lrz) lrunzip "$1" ;;
|
||||
*.lz4) lz4 -d "$1" ;;
|
||||
*.lzma) unlzma "$1" ;;
|
||||
*.z) uncompress "$1" ;;
|
||||
*.zip|*.war|*.jar|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$1" -d "$extract_dir" ;;
|
||||
*.rar) unrar x -ad "$1" ;;
|
||||
*.rpm) mkdir "$extract_dir" && cd "$extract_dir" && rpm2cpio "../$1" | cpio --quiet -id && cd .. ;;
|
||||
*.7z) 7za x "$1" ;;
|
||||
*.deb)
|
||||
mkdir -p "$extract_dir/control"
|
||||
mkdir -p "$extract_dir/data"
|
||||
cd "$extract_dir"; ar vx "../${1}" > /dev/null
|
||||
cd control; tar xzvf ../control.tar.gz
|
||||
cd ../data; extract ../data.tar.*
|
||||
cd ..; rm *.tar.* debian-binary
|
||||
cd ..
|
||||
;;
|
||||
*.zst) unzstd "$1" ;;
|
||||
*)
|
||||
echo "extract: '$1' cannot be extracted" >&2
|
||||
success=1
|
||||
;;
|
||||
esac
|
||||
|
||||
(( success = $success > 0 ? $success : $? ))
|
||||
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
# nnn with cd on quit
|
||||
if command -v nnn >/dev/null; then
|
||||
alias ncp="cat ${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} | tr '\0' '\n'"
|
||||
|
@ -1,86 +0,0 @@
|
||||
function extract -d "Extract archives"
|
||||
set -l remove_archive
|
||||
set -l success
|
||||
set -l extract_dir
|
||||
|
||||
if test -z "$argv[1]"
|
||||
echo -e "\e[1;34mUsage:\e[0m extract [-option] [file...]
|
||||
\e[1;33mOptions:\e[0m
|
||||
-r, --remove Remove archive after unpacking."
|
||||
end
|
||||
|
||||
set remove_archive 1
|
||||
if [ "$argv[1]" = "-r" ] || [ "$argv[1]" = "--remove" ]
|
||||
set remove_archive 0
|
||||
set --erase argv[1]
|
||||
end
|
||||
|
||||
while test -n "$argv[1]"
|
||||
if not test -f "$argv[1]"
|
||||
echo "extract: '$argv[1]' is not a valid file" >&2
|
||||
set --erase argv[1]
|
||||
continue
|
||||
end
|
||||
|
||||
set success 0
|
||||
set extract_dir (echo "$argv[1]" | cut -d'.' -f1)
|
||||
switch "$argv[1]"
|
||||
case "*.tar.gz" or "*.tgz"
|
||||
tar zxvf "$argv[1]"
|
||||
case "*.tar.bz2" or "*.tbz" or "*.tbz2"
|
||||
tar xvjf "$argv[1]"
|
||||
case "*.tar.xz" or "*.txz"
|
||||
tar --xz -xvf "$argv[1]"; or xzcat "$argv[1]" | tar xvf -
|
||||
case "*.tar.zma" or "*.tlz"
|
||||
tar --lzma -xvf "$argv[1]"; or lzcat "$argv[1]" | tar xvf -
|
||||
case "*.tar.zst" or "*.tzst"
|
||||
tar --zstd -xvf "$argv[1]"; or zstdcat "$argv[1]" | tar xvf -
|
||||
case "*.tar" or "*.tar.lz"
|
||||
tar xvf "$argv[1]"
|
||||
case "*.tar.lz4"
|
||||
lz4 -c -d "$argv[1]" | tar xvf -
|
||||
case "*.tar.lrz"
|
||||
lrzuntar "$argv[1]"
|
||||
case "*.gz"
|
||||
gunzip -d "$argv[1]"
|
||||
case "*.bz2"
|
||||
bunzip2 "$argv[1]"
|
||||
case "*.xz"
|
||||
unxz "$argv[1]"
|
||||
case "*.lrz"
|
||||
lrunzip "$argv[1]"
|
||||
case "*.lz4"
|
||||
lz4 -d "$argv[1]"
|
||||
case "*.lzma"
|
||||
unlzma "$argv[1]"
|
||||
case "*.z"
|
||||
uncompress "$argv[1]"
|
||||
case "*.zip" or "*.war" or "*.jar" or "*.sublime-package" or "*.ipa" or "*.ipsw" or "*.xpi" or "*.apk" or "*.aar" or "*.whl"
|
||||
unzip "$argv[1]" -d "$extract_dir"
|
||||
case "*.rar"
|
||||
unrar x -ad "$argv[1]"
|
||||
case "*.rpm"
|
||||
mkdir "$extract_dir"; and cd "$extract_dir"; and rpm2cpio "../$argv[1]" | cpio --quiet -id; and cd ..
|
||||
case "*.7z"
|
||||
7za x "$argv[1]"
|
||||
case "*.deb"
|
||||
mkdir -p "$extract_dir/control"
|
||||
mkdir -p "$extract_dir/data"
|
||||
cd "$extract_dir"; ar vx "../$argv[1]" > /dev/null
|
||||
cd control; tar xzvf ../control.tar.gz
|
||||
cd ../data; extract ../data.tar.*
|
||||
cd ..; rm *.tar.* debian-binary
|
||||
cd ..
|
||||
case "*.zst"
|
||||
unzstd "$argv[1]"
|
||||
case "*"
|
||||
echo "extract: '$argv[1]' cannot be extracted" >&2
|
||||
set success 1
|
||||
end
|
||||
|
||||
if [ "$success" = 0 ] && [ "$remove_archive" = 0 ]
|
||||
rm "$argv[1]"
|
||||
end
|
||||
set --erase argv[1]
|
||||
end
|
||||
end
|
@ -104,8 +104,7 @@ source $ZDOTDIR/aliases.zsh
|
||||
# /____/
|
||||
# Some OMZ stuff
|
||||
zinit wait lucid for \
|
||||
OMZ::lib/clipboard.zsh \
|
||||
OMZ::plugins/extract
|
||||
OMZ::lib/clipboard.zsh
|
||||
zinit ice blockf as"completion" for \
|
||||
OMZ::plugins/docker/_docker \
|
||||
OMZ::plugins/rust/_rust \
|
||||
|
@ -1,4 +1,5 @@
|
||||
# remap
|
||||
alias x=extract
|
||||
alias p="pulsemixer"
|
||||
alias startx="startx $HOME/.config/X11/xinitrc"
|
||||
alias fehwpp="feh --no-fehbg --bg-fill --randomize ~/Pictures/Wallpapers/*"
|
||||
|
55
home/.local/bin/extract
Executable file
55
home/.local/bin/extract
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
if [ -f "$1" ]; then
|
||||
printf -- "%s" "Delete after extracting?(y/N) "
|
||||
read -r choice
|
||||
|
||||
printf -- "%s\n" "Extracting $1 ..."
|
||||
extract_dir=$(echo "$1" | cut -d'.' -f1)
|
||||
case "$1" in
|
||||
*.tar.gz|*.tgz) tar zxvf "$1" ;;
|
||||
*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
|
||||
*.tar.xz|*.txz) tar --xz -xvf "$1" || xzcat "$1" | tar xvf - ;;
|
||||
*.tar.zma|*.tlz) tar --lzma -xvf "$1" || lzcat "$1" | tar xvf - ;;
|
||||
*.tar.zst|*.tzst) tar --zstd -xvf "$1" || zstdcat "$1" | tar xvf - ;;
|
||||
*.tar|*.tar.lz) tar xvf "$1" ;;
|
||||
*.tar.lz4) lz4 -c -d "$1" | tar xvf - ;;
|
||||
*.tar.lrz) lrzuntar "$1" ;;
|
||||
*.gz) gunzip -d "$1" ;;
|
||||
*.bz2) bunzip2 "$1" ;;
|
||||
*.xz) unxz "$1" ;;
|
||||
*.lrz) lrunzip "$1" ;;
|
||||
*.lz4) lz4 -d "$1" ;;
|
||||
*.lzma) unlzma "$1" ;;
|
||||
*.z) uncompress "$1" ;;
|
||||
*.zip|*.war|*.jar|*.ipa|*.sublime-package|*.ipsw|*.xpi|*.apk|*.aar|*.whl)
|
||||
unzip "$1" -d "$extract_dir" ;;
|
||||
*.rar) unrar x -ad "$1" ;;
|
||||
*.rpm)
|
||||
mkdir "$extract_dir"
|
||||
cd "$extract_dir"
|
||||
rpm2cpio "../$1" | cpio --quiet -id
|
||||
cd .. ;;
|
||||
*.7z) 7za x "$1" ;;
|
||||
*.deb)
|
||||
mkdir -p "$extract_dir/control"
|
||||
mkdir -p "$extract_dir/data"
|
||||
cd "$extract_dir" && ar vx "../$1" >/dev/null
|
||||
cd control && tar xzvf ../control.tar.gz
|
||||
cd ../data && extract ../data.tar.*
|
||||
cd .. && rm *.tar.* debian-binary
|
||||
cd .. ;;
|
||||
*.zst) unzstd "$1" ;;
|
||||
*) atool -X "$extract_dir" "$1" || echo "$1 cannot be extracted" ;;
|
||||
esac
|
||||
|
||||
if [ -n "$choice" ] && [ "$choice" = "y" ]; then
|
||||
rm -v "$1"
|
||||
fi
|
||||
else
|
||||
printf -- "%s\n" "File doesn't exist"
|
||||
fi
|
||||
else
|
||||
printf -- "%s\n" "Usage: extract [archive_name]"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user