~hnaguski/vtt

944c20b79aac937c571ebfed194bf4f9ee4e96d5 — Henry Naguski 8 months ago e99e293
update to 1.18, add zsh autocompletion, add rudimentary pack.png replacement
5 files changed, 111 insertions(+), 48 deletions(-)

M Makefile
A _vtt
M vtd
M vts
M vtu
M Makefile => Makefile +6 -1
@@ 5,7 5,9 @@
include config.mk

install:
	mkdir -p $(DESTDIR)$(PREFIX)/bin
	mkdir -p $(DESTDIR)$(PREFIX)/bin $(PREFIX)/share/vtt $(PREFIX)/share/zsh/site-functions
	cp -rf templates $(PREFIX)/share/vtt/
	cp -f _vtt $(PREFIX)/share/zsh/site-functions/_vtt
	cp -f vtu $(DESTDIR)$(PREFIX)/bin
	cp -f vts $(DESTDIR)$(PREFIX)/bin
	cp -f vtd $(DESTDIR)$(PREFIX)/bin


@@ 17,4 19,7 @@ uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/vtu
	rm -f $(DESTDIR)$(PREFIX)/bin/vts
	rm -f $(DESTDIR)$(PREFIX)/bin/vtd
	rm -f $(PREFIX)/share/zsh/site-functions/_vtt
	rm -rf $(PREFIX)/share/vtt

.PHONY: install uninstall

A _vtt => _vtt +34 -0
@@ 0,0 1,34 @@
#compdef vtu vts vtd

_vtt_avaliable_packs() {
	compadd "$@" -- ${${${(f)"$(jq -r '.categories[].packs[].name' "${VTT_CACHE:-$HOME/.cache}"/rpcategories-${VTT_MCVER:-1.18}.json | sort)"}#??? }%%-[^- ]# *}
}

_vtd() {
	_arguments : \
		'*:package:_vtt_avaliable_packs'
}

_vtu() {
	_arguments : \
		-c'[remove rpcategories files in VTT_CACHE directory]' \
		-h'[print help for vtu]'
}

_vts() {
	_arguments : \
		-a'[list all packs]' \
		-i'[print information about a pack]' \
		-h'[print help for vts]' \
		'*:package:_vtt_avaliable_packs'
}

_vtt() {
	case "$service" in
		vtd) _vtd "$@";;
		vtu) _vtu "$@";;
		vts) _vts "$@";;
	esac
}

_vtt "$@"

M vtd => vtd +37 -13
@@ 1,10 1,17 @@
#!/bin/sh

VTT_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}"
VTT_MCVER="${VTT_MCVER:-1.17}"
VTT_MCVER="${VTT_MCVER:-1.18}"
VTT_TMPDIR="${VTT_TMPDIR:-/tmp/vtt.$$}"
VTT_TEMPLATEDIR="${VTT_TEMPLATEDIR:-${XDG_DATA_HOME:-$HOME/.local/share}/vtt/templates}"

usage() {
	printf "usage: %s [-f FILE] [PACK]\n" "$0"
	exit 1
}

cleanup() {
	rm -rf "$VTT_TMPDIR"
}

downloadmany() {


@@ 14,10 21,11 @@ downloadmany() {
	# corrupted, and is very slow due to jq taking a while to startup.
	while read line; do
		downloadsingle "$line"
	done < "$1"
	done <"$1"
}

downloadsingle() {
	mkdir -p "$VTT_TMPDIR/$name"
	# get name and category of input
	jq -r '.categories[] | select(.packs[].name | test("^'"$1"'$"; "i")) | "\(.packs[] | select(.name | test("^'"$1"'$";"i")).name) \"\(.category)\""' "$VTT_CACHE/rpcategories-$VTT_MCVER.json" | while read -r name category; do
		# dirty hack to generate json string for single pack


@@ 27,23 35,39 @@ downloadsingle() {
		packdl=$(curl -s "https://vanillatweaks.net/assets/server/zipresourcepacks.php" --data-urlencode "packs=$packs" --data-urlencode "version=$VTT_MCVER" | jq -r .link)

		# download the pack if the link exists
		[ "$packdl" != null ] && wget -q --show-progress -O "$name".zip "https://vanillatweaks.net$packdl" 
		[ "$packdl" != null ] && wget -q --show-progress -O "$VTT_TMPDIR/$name.zip" "https://vanillatweaks.net$packdl"

		if [ -z "$noReplaceImage" ]; then
			zip -j -u "$VTT_TMPDIR/$name.zip" "$VTT_TEMPLATEDIR/$VTT_MCVER/$name/pack.png"
		fi
		mv "$VTT_TMPDIR/$name.zip" "$outputdir"
	done
}

[ -z "$1" ] && usage
trap cleanup INT

while getopts ":f:" arg; do
outputdir="$PWD"
while getopts ":f:o:n" arg; do
	case $arg in
		f)
			downloadmany "$OPTARG"
			exit 0
			;;
		?)
			usage
			exit 1
			;;
	f)
		downloadmany "$OPTARG"
		exit 0
		;;
	o)
		outputdir="$OPTARG"
		;;
	n)
		noReplaceImage=1
		printf 'Not replacing pack.png\n'
		;;
	?)
		usage
		exit 1
		;;
	esac
done
shift $((OPTIND - 1))

[ -z "$1" ] && usage
downloadsingle "$1"
cleanup

M vts => vts +19 -19
@@ 1,6 1,6 @@
#!/bin/sh
VTT_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}"
VTT_MCVER="${VTT_MCVER:-1.17}"
VTT_MCVER="${VTT_MCVER:-1.18}"

usage() {
	printf "usage: %s [-a] [-h] [-i PACK] [PACK]\n" "$0"


@@ 28,24 28,24 @@ search() {

while getopts ":ahi:" arg; do
	case $arg in
		a) # list name and description of every pack
			listall
			exit 0
			;;

		h) # help
			usage
			exit 0
			;;

		i) # show information about a specific resource pack
			#info "$OPTARG"
			;;
		?)
			printf "Invalid option: -%s\n" "$OPTARG"
			usage
			exit 1
			;;
	a) # list name and description of every pack
		listall
		exit 0
		;;

	h) # help
		usage
		exit 0
		;;

	i) # show information about a specific resource pack
		#info "$OPTARG"
		;;
	?)
		printf "Invalid option: -%s\n" "$OPTARG"
		usage
		exit 1
		;;
	esac
done


M vtu => vtu +15 -15
@@ 1,13 1,13 @@
#!/bin/sh
VTT_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}"
VTT_MCVER="${VTT_MCVER:-1.17}"
VTT_MCVER="${VTT_MCVER:-1.18}"

usage() {
	printf "usage: %s [-c] [-h]\n" "$0"
}

cleanjson() {
	printf "Removing all rpcategories files from %s\n" "$VTT_CACHE" 
	printf "Removing all rpcategories files from %s\n" "$VTT_CACHE"
	rm "$VTT_CACHE"/rpcategories-*.json
}



@@ 25,19 25,19 @@ update() {

while getopts ":ch" arg; do
	case $arg in
		c) # clean up all rpcategories files in the VTT_CACHE directory
			cleanjson
			exit 0
			;;
		h) # help
			usage
			exit 0
			;;
		?)
			printf "Invalid option: -%s\n" "$OPTARG"
			usage
			exit 1
			;;
	c) # clean up all rpcategories files in the VTT_CACHE directory
		cleanjson
		exit 0
		;;
	h) # help
		usage
		exit 0
		;;
	?)
		printf "Invalid option: -%s\n" "$OPTARG"
		usage
		exit 1
		;;
	esac
done