summaryrefslogtreecommitdiff
path: root/conf.d/99-pastebin.zsh
blob: 3eb3f36696fd358b810b420aad96a8a9df4f9200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
: ${PB_INSTANCE:=ptpb.pw}
: ${PB_CURL_ARGS:=""}

PASTE_LOG_FILE=$HOME/.local/zsh/ptpb.log

# pb upload
function pbu() {
  local tmp=$(mktemp)

  if [ "$#" -eq 0 ]; then
    # paste from stdin
    curl $PB_CURL_ARGS -sF c=@- https://$PB_INSTANCE > $tmp
  else
    curl $PB_CURL_ARGS -sF c=@$1 https://$PB_INSTANCE > $tmp
  fi

  mkdir -p $(dirname $PASTE_LOG_FILE)
  { cat $tmp; echo; } | tee -a $PASTE_LOG_FILE
  cat $tmp | awk '/url/ { print $2 }' | tr -d '\n' | xclip -i

  rm $tmp
}

# pb delete, takes short id
# someone please fix this
function pbd() {
  local short=$(grep -C2 $1 $PASTE_LOG_FILE \
              | awk '/uuid/ { print $2 }')
  curl $PB_CURL_ARGS -X DELETE https://$PB_INSTANCE/$short
}

function termbin() {
  nc termbin.com 9999
}