commit 51e5d5a9bd5f062bb6eb23e87bd276020769ee89 parent 7f48fbdbbf13450a6a39cab500d60d692c6e1a20 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Fri, 26 Jun 2020 15:46:13 +0200 Check if tags already exist in output file Diffstat:
M | .local/bin/memeadd | | | 14 | +++++++++----- |
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/.local/bin/memeadd b/.local/bin/memeadd @@ -1,5 +1,4 @@ #!/bin/sh -set -e out="${HOME}/tmp/me.meme" @@ -14,14 +13,19 @@ if [ ! -e "$out" ]; then fi if [ "$#" -lt 1 ]; then - urls="$(cat)" + files="$(cat)" else - urls="$@" + files="$@" fi -for f in "$urls"; do +for f in "$files"; do n="$(basename "$f")" tag="#${n%.*}" + if ! grep -q "$tag" "$out"; then + printf '%s %s\n' "$tag" "$url" >> "$out" + else + 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