Compare commits

...

4 Commits

5 changed files with 86 additions and 6 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
pkg
old
src
*.pkg.tar.*

View File

@@ -1,14 +1,25 @@
# PKGBUILD
pkgname=comp
pkgver=1.0
pkgrel=1
pkgver=1.2
pkgrel=5
pkgdesc="Simple folder compression with pv and pigz"
arch=('any')
license=('MIT')
depends=('tar' 'pv' 'pigz')
source=('comp.sh')
md5sums=('SKIP')
deps=('tar>0.0.0' 'pv>0.0.0' 'pigz>0.0.0')
source=('comp.sh' 'comp.bash' '_comp')
sha256sums=('18752ab3436748a777b2b384fdd8b5dc1fd69d81fe73c7f0482d8d633e1509e5'
'e90c5e24ad932296b932a8dd0cfcc42051209a755828408229d73c2dc6321e83'
'8ed621a9435b3f6d066abde2fb7eae964dda82ab90824b7fc07d167834863633')
prepare() {
sed -i "s/__VERSION__/$pkgver/" "$srcdir/comp.sh"
}
package() {
install -Dm755 "$srcdir/comp.sh" "$pkgdir/usr/bin/comp"
install -Dm644 "$srcdir/comp.bash" "$pkgdir/usr/share/bash-completion/completions/comp"
install -Dm644 "$srcdir/_comp" "$pkgdir/usr/share/zsh/site-functions/_comp"
}

19
_comp Normal file
View File

@@ -0,0 +1,19 @@
#compdef comp
_comp() {
_arguments \
'-h[Prints help message]' \
'--help[Prints help message]' \
'-v[Print version]' \
'--version[Print version]' \
'1:file or folder to compress:_files_or_dirs' \
'2:output file:_files'
# Custom function to complete both files and directories
_files_or_dirs() {
_alternative \
'directories:: _directories' \
'files:: _files'
}
}

23
comp.bash Normal file
View File

@@ -0,0 +1,23 @@
# completions/comp.bash
_comp_completions()
{
local cur prev opts
COMPREPLY=()
cur = "${COMP_WORDS[COMP_CWORD]}"
prev = "${COMP_WORDS[COMP_CWORD-1]}"
opts = "-h --help -v --version"
if [[ "$cur" == -* ]]; then
COMPREPLY = ( $(compgen -W "${opts}" -- "$cur"))
return 0
fi
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $(compgen -d -- "$cur") $(compgen -f -- "$cur"))
return 0
fi
return 0
}
complete -F _comp_completions comp

24
comp.sh Normal file → Executable file
View File

@@ -3,8 +3,30 @@
# Usage: comp <folder_to_compress> [output_fildename]
# Check if input folder is provided
VERSION="__VERSION__"
if [[ -z "$1" ]]; then
echo "Usage: comp <folder_to_compress> [output_filename]"
echo "Usage: comp <folder_or_file_to_compress> [output_file]"
echo "comp <options>"
exit 1
elif [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage:"
echo " comp <folder_or_file_to_compress> [output_file]"
echo " comp <option>"
echo ""
echo "Options:"
echo " -h --help: Print's this message"
echo " -v --version: Ptints the current version"
exit 0
elif [[ "$1" == "-v" || "$1" == "--version" ]]; then
echo "comp version: $VERSION"
exit 0
elif [[ ! -d "$1" || ! -f "$1" ]]; then
echo "Invalid argument '$1'"
echo "Usage:"
echo " comp <folder_to_compress> [output_file]"
echo " comp <option>"
exit 1
fi