function _pasteconfig { PSSH="git@codevoid.de" RPATH="/srv/codevoid-gopher/p" URL1="https://codevoid.de/?q=gopher://codevoid.de:70/0/p" URL2="gopher://codevoid.de:70/0/p" } function lspaste { _pasteconfig ssh $PSSH "ls -1 $RPATH" | while read -r file; do printf "$file|$URL1/$file|$URL2/$file\n" done | column -t -s"|" } function rmpaste { _pasteconfig if [ "$1" = "-h" ]; then printf "Usage:\n" printf " rmpaste - deletes last paste based on ~/.pastehistory\n" printf " rmpaste - deletes paste with \n" return 0 fi if [ -z $1 ]; then if ! [ -s ~/.pastehistory ]; then printf "The history file is empty.\n" return 0 fi f=$(tail -1 ~/.pastehistory | cut -d'|' -f2) # I'm using mksh, which handles reads differently if [ -z "${KSH_VERSION}" ]; then read -p "Delete last paste? ($f) [y/N] : " d else read d?"Delete last paste? ($f) [y/N] : " fi if [ "$d" = "y" ]; then ssh $PSSH "rm $RPATH/$f" head -n1 ~/.pastehistory > ~/.pastehistory fi else ssh $PSSH "rm $RPATH/$1" fi } function paste { _pasteconfig f="$1" if [ "$1" = "-h" ]; then printf "Usage:\n" printf " paste < text.txt - read from stdin, generate filename\n" printf " paste new.txt < file.txt - read from stdin with filename\n" printf " paste file.txt - upload file as is\n" return 0 fi if [ -z "$1" ]; then f="$(date +"%Y-%m-%d_%S-%M")-$(pwgen -1 4 -A -0).txt" ssh $PSSH "cat > $RPATH/$f" elif [ -f "$f" ]; then scp "$f" $PSSH:"$RPATH/$f" else ssh $PSSH "cat > $RPATH/$f" fi # Print ways to access the content printf "$URL1/$f\n" printf "$URL2/$f\n" # write paste history (for convenience and rmpaste) printf "$(date +"%Y-%m-%d %S:%M")|$f\n" >> ~/.pastehistory if which xclip > /dev/null; then # put this one into the X selection buffer right away printf "$URL2/$f" | xclip fi if which notify-send > /dev/null; then # overkill, but hey - why not. notify-send "Your paste is ready." fi }