🧹 chore: improve extract function

This commit is contained in:
eshanized
2025-01-07 03:37:20 +05:30
parent 8c5a133084
commit 8828a23ab1

View File

@@ -55,29 +55,36 @@ bind "set completion-ignore-case on"
# Function for extracting different types of archives # Function for extracting different types of archives
ex () { ex () {
if [ -f "$1" ]; then if [ "$#" -lt 1 ]; then
case "$1" in echo "Usage: ex <file> [destination]"
*.tar.bz2) tar xjf "$1" ;; return 1
*.tar.gz) tar xzf "$1" ;; fi
*.bz2) bunzip2 "$1" ;; local file="$1"
*.rar) unrar x "$1" ;; local dest="${2:-.}"
*.gz) gunzip "$1" ;; if [ -f "$file" ]; then
*.tar) tar xf "$1" ;; case "$file" in
*.tbz2) tar xjf "$1" ;; *.tar.bz2) tar xjf "$file" -C "$dest" ;;
*.tgz) tar xzf "$1" ;; *.tar.gz) tar xzf "$file" -C "$dest" ;;
*.zip) unzip "$1" ;; *.bz2) bunzip2 "$file" ;;
*.Z) uncompress "$1" ;; *.rar) unrar x "$file" "$dest" ;;
*.7z) 7z x "$1" ;; *.gz) gunzip "$file" ;;
*.deb) ar x "$1" ;; *.tar) tar xf "$file" -C "$dest" ;;
*.tar.xz) tar xf "$1" ;; *.tbz2) tar xjf "$file" -C "$dest" ;;
*.tar.zst) tar xf "$1" ;; *.tgz) tar xzf "$file" -C "$dest" ;;
*) echo "'$1' cannot be extracted via ex()" ;; *.zip) unzip "$file" -d "$dest" ;;
*.Z) uncompress "$file" ;;
*.7z) 7z x "$file" -o"$dest" ;;
*.deb) ar x "$file" -C "$dest" ;;
*.tar.xz) tar xf "$file" -C "$dest" ;;
*.tar.zst) tar xf "$file" -C "$dest" ;;
*) echo "'$file' cannot be extracted via ex()" ;;
esac esac
else else
echo "'$1' is not a valid file" echo "'$file' is not a valid file"
fi fi
} }
# Custom PS1 prompt with IP address and conditional formatting based on terminal type # Custom PS1 prompt with IP address and conditional formatting based on terminal type
get_ip_address() { get_ip_address() {
# Extract non-local IP address # Extract non-local IP address