Custom smiley selector

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Custom smiley selector

Unread post by johnraff » Tue Oct 15, 2013 5:47 pm

The smilotron - upgraded to use postimage.org instead of omploader.
If you're bored with the bbq smileys and want your own selection, this can help you.

Put some smileys (or other small images) in a folder and bind this script to a key combo like Super+s or whatever. When you hit it a feh window will come up showing your smiley collection on a black background. Click the one you want ( a tiny new window will open with that image), then press Enter. When the upload is complete feh will close and you can paste the code into your post with the mouse middle wheel.

Dependencies: feh curl xsel

Upload is only done once for each image, after that the url is kept for future use.
postimage.org only provide direct links for small images (I haven't tested where the limit is) and big images will break the script.

Image

Code: Select all

#!/bin/bash
## choose an image file from a folder, upload if necessary
## and get its url + bbcode to paste.
## Dependencies: feh curl xsel

# set your folder for smileys (and put some there)
SMILEY_DIR="$HOME/Dropbox/Public/smilies"

[[ -d $SMILEY_DIR ]] || {
    echo "$0: $SMILEY_DIR no such directory" >&2
    exit 1
}

[[ $1 = --load ]] || {
    exec feh -t "$SMILEY_DIR" --quiet --title 'Choose a smiley (click, then press enter)' --index-name no --image-bg black --action "$0 --load %n;"
    exit
}

####################################################

# if "--load" option passed, upload image (if necessary) and print out url

file="$SMILEY_DIR/$2"
[[ $(feh -U "$file") ]] || { echo "$0: $2 no such image file in $SMILEY_DIR" >&2; exit 1;}
[[ -f ${file}.url ]] || {
    awk '
    BEGIN {
        RS="<textarea"
        FS="</td>"
    }
    NR==1{next}
    /Direct Link/ {
        gsub(/<[^>]*>/,"",$1)
        sub(/^[^>]*>/,"",$1)
        printf("%s",$1)}' <( curl -Ls -F "upload[]=@$file" -F "adult=no" http://postimage.org/ || echo "$0: curl failed to upload $file" >&2 ; exit 1 ) > "${file}.url"
}

# uncomment end of next line to use clipboard instead of selection
printf '[img]%s[/img]' "$(<"${file}.url")" | xsel --input #--clipboard
pkill -f "feh -t $SMILEY_DIR"
exit
All code is one.

Post Reply