File: tinyurl

package info (click to toggle)
konversation 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 17,080 kB
  • ctags: 4,900
  • sloc: cpp: 45,134; perl: 475; python: 397; sh: 211; makefile: 9
file content (30 lines) | stat: -rwxr-xr-x 884 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/env bash
#
# Creates a TinyURL from a long URL
# Licensed under GPL v2 or later at your option
# Copyright 2007 Terence Simpson

SERVER=$1
TARGET=$2
export URL="$3"
NICK="$4"

if test ! -z $URL; then
  if test $(which curl); then
    TINYURL="$(curl -s -i http://tinyurl.com/api-create.php?url=$URL|tail -1)"
  else
    TINYURL="$(wget -T10 -t2 -qO- http://tinyurl.com/api-create.php?url=$URL|tail -1)"
  fi
else qdbus org.kde.konversation /irc error "No url given: usage is \"/tinyurl URL [NickName]\""
    exit 1
fi

if test -z $TINYURL; then
    qdbus org.kde.konversation /irc error "Unable run tinyurl script, please make sure you have curl or wget installed"
else
    if test ! -z $NICK; then
        qdbus org.kde.konversation /irc say $SERVER "$TARGET" "${NICK}: $TINYURL"
    else
        qdbus org.kde.konversation /irc say $SERVER "$TARGET" "$TINYURL"
    fi
fi