function extract --description "Extract common archive formats" if test (count $argv) -ne 1 echo "Usage: extract " return 1 end set -l file $argv[1] if not test -f "$file" echo "File not found: $file" return 1 end switch "$file" case "*.tar.bz2" "*.tbz2" tar -xjf "$file" case "*.tar.gz" "*.tgz" tar -xzf "$file" case "*.tar.xz" "*.txz" tar -xJf "$file" case "*.tar.zst" tar --zstd -xf "$file" case "*.tar" tar -xf "$file" case "*.zip" unzip "$file" case "*.7z" 7z x "$file" case "*.rar" unrar x "$file" case "*.gz" gunzip "$file" case "*.bz2" bunzip2 "$file" case "*.xz" unxz "$file" case "*.zst" unzstd "$file" case '*' echo "Unsupported archive format." return 1 end end