dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

eztmp (1198B)


      1#!/bin/sh
      2
      3# https://stackoverflow.com/a/38021063
      4urlencodepipe() {
      5  local LANG=C; local c; while IFS= read -r c; do
      6    case $c in [a-zA-Z0-9.~_-]) printf "$c"; continue ;; esac
      7    printf "$c" | od -An -tx1 | tr ' ' % | tr -d '\n'
      8  done <<EOF
      9$(fold -w1)
     10EOF
     11  echo
     12}
     13urlencode() { printf "$*" | urlencodepipe ;}
     14
     15RAND=$(cat /dev/urandom | tr -dc 'a-z0-9' | head --bytes 8)
     16#URL="https://$USER:$PASSWORD@$DOMAIN:$PORT/path"
     17
     18# upload image from clipboard
     19[ "$1" = "-c" ] \
     20	&& { xclip -selection clipboard -t image/png -o \
     21	| curl -o /dev/null --progress-bar -T - "$URL/$RAND.png" \
     22	&& TMPURL="https://ezup.dev/tmp/$RAND.png" \
     23	&& notify-send.sh --icon=terminal "Clipboard Image Uploaded\n$TMPURL"; \
     24	echo "$TMPURL" | xclip -selection clipboard; \
     25	exit 0; }
     26
     27# upload from file or stdin
     28[ ! -z "$1" ] && [ -f "$1" ] \
     29	&& FILE="$1" NAME=${RAND}_$(basename "$1") \
     30	|| { [ ! -t 0 ] && FILE="-" NAME="${RAND}.txt"; }
     31#&& FILE="$1" NAME=$(urlencode ${RAND}_$(basename "$1")) \
     32[ ! -z "$FILE" ] \
     33	&& { curl -o /dev/null --progress-bar -T "$FILE" "$URL/$NAME" \
     34	&& TMPURL="https://ezup.dev/tmp/$(urlencode $NAME)"; echo $TMPURL; \
     35	echo "$TMPURL" | xclip -selection clipboard; } \
     36	|| exit 1