From 2cee8d21207468337ac982c8dc86762b668a21b3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 15 Jun 2022 02:02:12 +0200 Subject: [PATCH] add animoji-command --- .config/zsh/completions/_animoji-command | 11 +++++++ .config/zsh/functions/animoji-command | 42 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 .config/zsh/completions/_animoji-command create mode 100755 .config/zsh/functions/animoji-command diff --git a/.config/zsh/completions/_animoji-command b/.config/zsh/completions/_animoji-command new file mode 100644 index 0000000..3b7d43e --- /dev/null +++ b/.config/zsh/completions/_animoji-command @@ -0,0 +1,11 @@ +#compdef animoji-command + +_arguments '-h[short help text]' \ + '--help[short help text]' \ + '--delay[milliseconds to show each frame]:milliseconds' \ + '--blend[enable blending (only WebP)]' \ + '*:input files:_files' + +# Local Variables: +# mode: shell-script +# End: diff --git a/.config/zsh/functions/animoji-command b/.config/zsh/functions/animoji-command new file mode 100755 index 0000000..b8aa401 --- /dev/null +++ b/.config/zsh/functions/animoji-command @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# Output commands to generate animated images from files + +setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL + +zmodload zsh/zutil +local -a o_help=() +local -a o_delay=() +local -a o_blend=() +zparseopts -D -K -- h=o_help -help=o_help -delay:=o_delay -blend=o_blend +if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then + local ret=$(( ${#o_help} ^ 1 )) + print -u $(( 1 + ${ret} )) \ + "usage: ${0} [-h|--help] [--delay MILLISECONDS] [--blend]" "" + return ${ret} +fi + +local delay=100 +[[ ${#o_delay} -eq 2 ]] && delay=${o_delay[2]} +local blend="-b" +[[ ${#o_help} -ne 0 ]] && blend="+b" + +local -a cmd +if [[ ${1##*.} == "webp" ]]; then + cmd=(webpmux -o output.webp) + for file in ${@}; do + cmd+=(-frame ${file} +${delay}+0+0+0${blend}) + done +elif [[ ${1##*.} == "png" ]]; then + cmd=(apngasm --output output.png) + for file in ${@}; do + cmd+=(${file} ${delay}) + done +else + print -u 2 "file format not supported" + return 1 +fi +if [[ -o INTERACTIVE ]]; then + print -z "" ${cmd} +else + print "" ${cmd} +fi