Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Ohmyzsh
Commits
492f712d
Unverified
Commit
492f712d
authored
Jan 05, 2021
by
Konfekt
Committed by
GitHub
Jan 05, 2021
Browse files
feat(plugins): add `universalarchive` plugin to conveniently compress files (#6846)
Co-authored-by:
Marc Cornellà
<
marc.cornella@live.com
>
parent
2118d35e
Changes
3
Hide whitespace changes
Inline
Side-by-side
plugins/universalarchive/README.md
0 → 100644
View file @
492f712d
# universalarchive plugin
Lets you compress files by a command
`ua <format> <files>`
, supporting various
compression formats (e.g. 7z, tar.gz, lzma, ...).
To enable it, add
`universalarchive`
to the plugins array in your zshrc file:
```
zsh
plugins
=(
... universalarchive
)
```
## Usage
Run
`ua <format> <files>`
to compress
`<files>`
into an archive file using
`<format>`
.
For example:
```
sh
ua xz
*
.html
```
this command will compress all
`.html`
files in directory
`folder`
into
`folder.xz`
.
This plugin saves you from having to remember which command line arguments compress a file.
## Supported compression formats
| Extension | Description |
|:-----------------|:-------------------------------|
|
`7z`
| 7zip file |
|
`bz2`
| Bzip2 file |
|
`gz`
| Gzip file |
|
`lzma`
| LZMA archive |
|
`lzo`
| LZO archive |
|
`rar`
| WinRAR archive |
|
`tar`
| Tarball |
|
`tbz`
/
`tar.bz2`
| Tarball with bzip2 compression |
|
`tgz`
/
`tar.gz`
| Tarball with gzip compression |
|
`tlz`
/
`tar.lzma`
| Tarball with lzma compression |
|
`txz`
/
`tar.xz`
| Tarball with lzma2 compression |
|
`tZ`
/
`tar.Z`
| Tarball with LZW compression |
|
`xz`
| LZMA2 archive |
|
`Z`
| Z archive (LZW) |
|
`zip`
| Zip archive |
|
`zst`
| Zstd archive |
See
[
list of archive formats
](
https://en.wikipedia.org/wiki/List_of_archive_formats
)
for more information regarding the archive formats.
plugins/universalarchive/_universalarchive
0 → 100644
View file @
492f712d
#compdef ua
_arguments \
"1:archive format:(7z bz2 gz lzma lzo rar tar tar.bz2 tar.gz tar.lzma tar.xz tar.Z tbz tgz tlz txz tZ xz Z zip zst)" \
"*:input files:_files" \
&& return 0
plugins/universalarchive/universalarchive.plugin.zsh
0 → 100644
View file @
492f712d
function
ua
()
{
local
usage
=
\
"Archive files and directories using a given compression algorithm.
Usage:
$0
<format> <files>
Example:
$0
tbz PKGBUILD
Supported archive formats are:
7z, bz2, gz, lzma, lzo, rar, tar, tbz (tar.bz2), tgz (tar.gz),
tlz (tar.lzma), txz (tar.xz), tZ (tar.Z), xz, Z, zip, and zst."
if
[[
$#
-lt
2
]]
;
then
echo
>
&2
"
$usage
"
return
1
fi
local
ext
=
"
$1
"
local
input
=
"
$(
realpath
"
$2
"
)
"
shift
if
[[
!
-e
"
$input
"
]]
;
then
echo
>
&2
"
$input
not found"
return
1
fi
# generate output file name
local
output
if
[[
$#
-gt
1
]]
;
then
output
=
"
$(
basename
"
${
input
%/*
}
"
)
"
elif
[[
-f
"
$input
"
]]
;
then
output
=
"
$(
basename
"
${
input
%.[^.]*
}
"
)
"
elif
[[
-d
"
$input
"
]]
;
then
output
=
"
$(
basename
"
${
input
}
"
)
"
fi
# if output file exists, generate a random name
if
[[
-f
"
${
output
}
.
${
ext
}
"
]]
;
then
output
=
$(
mktemp
"
${
output
}
_XXX"
)
&&
rm
"
$output
"
||
return
1
fi
# add extension
output
=
"
${
output
}
.
${
ext
}
"
# safety check
if
[[
-f
"
$output
"
]]
;
then
echo
>
&2
"output file '
$output
' already exists. Aborting"
return
1
fi
case
"
$ext
"
in
7z
)
7z u
"
${
output
}
"
"
${
@
}
"
;;
bz2
)
bzip2
-vcf
"
${
@
}
"
>
"
${
output
}
"
;;
gz
)
gzip
-vcf
"
${
@
}
"
>
"
${
output
}
"
;;
lzma
)
lzma
-vc
-T0
"
${
@
}
"
>
"
${
output
}
"
;;
lzo
)
lzop
-vc
"
${
@
}
"
>
"
${
output
}
"
;;
rar
)
rar a
"
${
output
}
"
"
${
@
}
"
;;
tar
)
tar
-cvf
"
${
output
}
"
"
${
@
}
"
;;
tbz|tar.bz2
)
tar
-cvjf
"
${
output
}
"
"
${
@
}
"
;;
tgz|tar.gz
)
tar
-cvzf
"
${
output
}
"
"
${
@
}
"
;;
tlz|tar.lzma
)
XZ_OPT
=
-T0
tar
--lzma
-cvf
"
${
output
}
"
"
${
@
}
"
;;
txz|tar.xz
)
XZ_OPT
=
-T0
tar
-cvJf
"
${
output
}
"
"
${
@
}
"
;;
tZ|tar.Z
)
tar
-cvZf
"
${
output
}
"
"
${
@
}
"
;;
xz
)
xz
-vc
-T0
"
${
@
}
"
>
"
${
output
}
"
;;
Z
)
compress
-vcf
"
${
@
}
"
>
"
${
output
}
"
;;
zip
)
zip
-rull
"
${
output
}
"
"
${
@
}
"
;;
zst
)
zstd
-c
-T0
"
${
@
}
"
>
"
${
output
}
"
;;
*
)
echo
>
&2
"
$usage
"
;
return
1
;;
esac
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment