summaryrefslogtreecommitdiffstats
path: root/fb-client/fb-0.6.1
blob: 06dd87e616504790f490e8634b53ccb34ebd3b95 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#----------------------------------------------------
# Author:       Florian "Bluewind" Pritz <flo@xssn.at>
#
# Licensed under WTFPL v2
#   (see COPYING for full license text)
#
#----------------------------------------------------
# only works if useragent contains libcurl
# Dependencies: curl
# Optional: xclip
#----------------------------------------------------

VERSION="0.6.1"

DELETE=0
EXTENSION=""
GET=0
PASTEBIN="http://paste.xinu.at"

do_upload() {
  local EXTRA=""
  if [[ -n $EXTENSION ]]; then
    EXTRA="-F extension=$EXTENSION"
  fi
  URL="$(curl -# -n -L $EXTRA -F "file=@$1" "$PASTEBIN/file/do_upload")"
  echo $URL
  echo -n "$URL" | nohup &> /dev/null xclip
}

read_stdin() {
  if tty -s; then
    echo "^C to exit, ^D to send"
  fi
  cat > "$1"
}

help() {
  echo "fb-client version $VERSION"
  echo "usage: [cat |] $(basename "$0") [switches] [file(s)|ID(s)]"
  echo "  Upload/nopaste file/stdin to paste.xinu.at and copy URL to clipboard."
  echo "  ~/.netrc: machine paste.xinu.at password PASSWORD"
  echo ""
  echo "Switches:"
  echo "  -e EXTENSION   extension for default highlighting (e.g. \"diff\")"
  echo "  -d             delete the IDs"
  echo "  -g             download the IDs and output on stdout (use with care!)"
  echo "  -h             this help"
  exit 0
}

while getopts ":e:gdh" OPTION; do
  case $OPTION in
    e) EXTENSION="$OPTARG";;
    g) GET=1;;
    d) DELETE=1;;
    h) help;;
    \?) echo "unknown option \"-$OPTARG\"" >&2; exit 1;;
    :) echo "Option \"-$OPTARG\" needs an argument" >&2; exit 1;;
  esac
done

shift $((OPTIND - 1))

TMPDIR="$(mktemp -d "/tmp/fb.XXXXXX")"

if (($# == 0)); then
  read_stdin "$TMPDIR/stdin"
  do_upload "$TMPDIR/stdin"
else
  for i in "$@"; do
    if [[ $DELETE == 1 ]]; then
      curl -n -L "$PASTEBIN/file/delete/$i"
    elif [[ $GET == 1 ]]; then
      curl -s -o - "$PASTEBIN/$i"
    else
      do_upload $i
    fi
  done
fi