dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit be6067452ca15a390914f02a239d5a25c091adc3
parent 422a94a366932bc9fd7bd019ba83d6aa3b45a69b
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Sun, 28 Jun 2020 21:40:28 +0200

Fix functionality when adding multiple memes

Diffstat:
M.local/bin/memeadd | 28+++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/.local/bin/memeadd b/.local/bin/memeadd @@ -8,23 +8,25 @@ if [ "$1" = "-h" ]; then exit 1 fi +add_memes() { + for f in $@; do + n="$(basename "$f")" + tag="#${n%.*}" + if grep -q "$tag " "$out"; then + printf '%s: error: tag %s already exists\n' "${0##*/}" "$tag" >&2 + exit 1 + fi + url="$(upload -o -p "$f")" + printf '%s %s\n' "$tag" "$url" >> "$out" + done +} + if [ ! -e "$out" ]; then printf 'meme\n' > "$out" fi if [ "$#" -lt 1 ]; then - files="$(cat)" + add_memes "$(cat)" else - files="$@" + add_memes "$@" fi - -for f in "$files"; do - n="$(basename "$f")" - tag="#${n%.*}" - if grep -q "$tag" "$out"; then - printf '%s: error: tag %s already exists\n' "${0##*/}" "$tag" >&2 - exit 1 - fi - url="$(upload -o -p "$f")" - printf '%s %s\n' "$tag" "$url" >> "$out" -done