1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

ultimate_extractor: various fixes (#482)

- fix regex matching
  - . -> \.
  - use $ ot match end of file name
- fix naming of variables (exte -> handlers; command -> maybe_handler)
- combine suffixes with common extractors
- in case of no match, use a proper error
This commit is contained in:
Dominik Schrempf 2023-05-10 13:17:46 +02:00 committed by GitHub
parent 3645bae992
commit a3778622cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,27 +1,26 @@
#Function to extract archives with different extensions
export def extract [name:string #name of the archive to extract
] {
let exten = [ [ex com];
['.tar.bz2' 'tar xjf']
['.tar.gz' 'tar xzf']
['.bz2' 'bunzip2']
['.rar' 'unrar x']
['.tbz2' 'tar xjf']
['.tgz' 'tar xzf']
['.zip' 'unzip']
['.7z' '/usr/bin/7z x']
['.deb' 'ar x']
['.tar.xz' 'tar xvf']
['.tar.zst' 'tar xvf']
['.tar' 'tar xvf']
['.gz' 'gunzip']
['.Z' 'uncompress']
]
let command = ($exten|where $name =~ $it.ex|first)
if ($command|is-empty) {
echo 'Error! Unsupported file extension'
# Function to extract archives with different extensions.
export def extract [name:string] {
let handlers = [ [extension command];
['tar\.bz2|tbz|tbz2' 'tar xvjf']
['tar\.gz|tgz' 'tar xvzf']
['tar\.xz|txz' 'tar xvf']
['tar\.Z' 'tar xvZf']
['bz2' 'bunzip2']
['deb' 'ar x']
['gz' 'gunzip']
['pkg' 'pkgutil --expand']
['rar' 'unrar x']
['tar' 'tar xvf']
['xz' 'xz --decompress']
['zip|war|jar|nupkg' 'unzip']
['Z' 'uncompress']
['7z' '7za x']
]
let maybe_handler = ($handlers | where $name =~ $'\.(($it.extension))$')
if ($maybe_handler | is-empty) {
error make { msg: "unsupported file extension" }
} else {
nu -c ($command.com + ' ' + $name)
let handler = ($maybe_handler | first)
nu -c ($handler.command + ' ' + $name)
}
}