diff --git a/.local/bin/ext b/.local/bin/ext deleted file mode 100755 index c5f89c5..0000000 --- a/.local/bin/ext +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -# A general, all-purpose extraction script. Not all extraction programs here -# are installed by LARBS automatically. -# -# Default behavior: Extract archive into new directory -# Behavior with `-c` option: Extract contents into current directory - -while getopts "hc" o; do case "${o}" in - c) extracthere="True" ;; - *) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit ;; -esac done - -if [ -z "$extracthere" ]; then - archive="$(readlink -f "$*")" && - directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" && - mkdir -p "$directory" && - cd "$directory" || exit -else - archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)")" -fi - -[ "$archive" = "" ] && printf "Give archive to extract as argument.\\n" && exit - -if [ -f "$archive" ] ; then - case "$archive" in - *.tar.bz2|*.tbz2) tar xvjf "$archive" ;; - *.tar.xz) tar -xf "$archive" ;; - *.tar.gz|*.tgz) tar xvzf "$archive" ;; - *.lzma) unlzma "$archive" ;; - *.bz2) bunzip2 "$archive" ;; - *.rar) unrar x -ad "$archive" ;; - *.gz) gunzip "$archive" ;; - *.tar) tar xvf "$archive" ;; - *.zip) unzip "$archive" ;; - *.Z) uncompress "$archive" ;; - *.7z) 7z x "$archive" ;; - *.xz) unxz "$archive" ;; - *.exe) cabextract "$archive" ;; - *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;; - esac -else - printf "File \"%s\" not found.\\n" "$archive" -fi diff --git a/.local/bin/tools/ext b/.local/bin/tools/ext index 562d2b3..14970c2 120000 --- a/.local/bin/tools/ext +++ b/.local/bin/tools/ext @@ -1 +1 @@ -extract \ No newline at end of file +/home/alex/.local/bin/tools/extract \ No newline at end of file diff --git a/.local/bin/tools/extract b/.local/bin/tools/extract index a63ab10..cdec3cf 100755 --- a/.local/bin/tools/extract +++ b/.local/bin/tools/extract @@ -1,5 +1,6 @@ -#!/bin/sh -# A general, all-purpose extraction script. +#!/bin/bash +# A general, all-purpose extraction script. Not all extraction programs here +# are installed by LARBS automatically. # # Default behavior: Extract archive into new directory # Behavior with `-c` option: Extract contents into current directory @@ -9,33 +10,37 @@ while getopts "hc" o; do case "${o}" in *) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit ;; esac done -if [ -z "$extracthere" ]; then - archive="$(readlink -f "$*")" && +extractfunc(){ +toextract="$1" +case "$archive" in + *.tar.bz2|*.tbz2) tar xvjf "$toextract" ;; + *.tar.xz) tar -xf "$toextract" ;; + *.tar.gz|*.tgz) tar xvzf "$toextract" ;; + *.lzma) unlzma "$toextract" ;; + *.bz2) bunzip2 "$toextract" ;; + *.rar) unrar x -ad "$toextract" ;; + *.gz) gunzip "$toextract" ;; + *.tar) tar xvf "$toextract" ;; + *.zip) unzip "$toextract" ;; + *.Z) uncompress "$toextract" ;; + *.7z) 7z x "$toextract" ;; + *.xz) unxz "$toextract" ;; + *.exe) cabextract "$toextract" ;; + *) printf "extract: '%s' - unknown archive method\\n" "$toextract" ;; +esac +} +archives="$(readlink -f "${@##-c}" )" +while read -r archive; do directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" && - mkdir -p "$directory" && - cd "$directory" || exit -else - archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)")" -fi + if [ -f "$archive" ];then + if [ -z "$extracthere" ]; then + mkdir -p $directory && + cd "$directory" || exit + fi + extractfunc "$archive" + else + printf "File \"%s\" not found.\\n" "$archive" + fi +done < <(echo "$archives") -[ "$archive" = "" ] && printf "Give archive to extract as argument.\\n" && exit - -if [ -f "$archive" ] ; then - case "$archive" in - *.tar.bz2|*.tar.xz|*.tbz2) tar xvjf "$archive" ;; - *.tar.gz|*.tgz) tar xvzf "$archive" ;; - *.lzma) unlzma "$archive" ;; - *.bz2) bunzip2 "$archive" ;; - *.rar) unrar x -ad "$archive" ;; - *.gz) gunzip "$archive" ;; - *.tar) tar xvf "$archive" ;; - *.zip) unzip "$archive" ;; - *.Z) uncompress "$archive" ;; - *.7z) 7z x "$archive" ;; - *.xz) unxz "$archive" ;; - *.exe) cabextract "$archive" ;; - *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;; - esac -else - printf "File \"%s\" not found.\\n" "$archive" -fi +[ "$archives" = "" ] && printf "Give archive to extract as argument.\\n" && exit