dotfiles

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

memeadd (577B)


      1 #!/bin/sh
      2 
      3 out="${HOME}/tmp/memeXchange.meme"
      4 
      5 if [ "$1" = "-h" ]; then
      6 	printf 'usage: %s <file>\n' "${0##*/}" >&2
      7 	printf 'usage: ls memefile*.png | %s\n' "${0##*/}" >&2
      8 	exit 1
      9 fi
     10 
     11 add_memes() {
     12 	for f in $@; do
     13 		n="$(basename "$f")"
     14 		tag="#${n%.*}"
     15 		if grep -q "$tag " "$out"; then
     16 			printf '%s: error: tag %s already exists\n' "${0##*/}" "$tag" >&2
     17 			exit 1
     18 		fi
     19 		url="$(upload -o -p "$f")"
     20 		printf '%s %s\n' "$tag" "$url" >> "$out"
     21 	done
     22 }
     23 
     24 if [ ! -e "$out" ]; then
     25 	printf 'meme\n' > "$out"
     26 fi
     27 
     28 if [ "$#" -lt 1 ]; then
     29 	add_memes "$(cat)"
     30 else
     31 	add_memes "$@"
     32 fi