-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkpaste
executable file
·38 lines (32 loc) · 1.16 KB
/
kpaste
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
#!/bin/bash
## Paste text to http://paste.kde.org
## Written by BrainFucker ( https://github.com/rekcuFniarB/Bash-scripts )
## Licensed under the GPL3 license.
##
## Usage: cat file.txt | kpaste [format]
## Example: cat script.sh | kpaste bash
##
## Depencies: curl, xclip, notify-send
UA='Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0'
if [[ $1 ]]
# If code language not specified, send as plain text.
then Format="$1"
else Format="text"
fi
Link="$(curl -s -d "paste_user=$(whoami)" -d "paste_lang=$Format" -d "paste_expire=0" --data-urlencode paste_data@- -d "paste_submit=Paste" -A "$UA" -w %{redirect_url} -e http://paste.kde.org/ http://paste.kde.org/)"
if [[ ! $(echo "$Link"|wc -l) == 1 ]]
# When error occurs, returned value may contain html page, not link.
# Don't display it if so.
then Link="Error!"
fi
if [[ $DISPLAY ]]
then
# If X server is working, put the link to the clipboard and notify user when ready.
echo -n "$Link" | xclip
if [[ $(which notify-send) ]]
then notify-send -t 3000 -i kate Kpaste "$Link"
elif [[ $(which kdialog) ]]
then kdialog --passivepopup "$Link" 3
fi
fi
echo "$Link"