dotfiles

A steaming hot pile of sh...ell scripts and configuration files.
Log | Files | Refs

commit b1809dfb43065c4e92bc779a8a52559bfafdd007
parent 153992d46beced2bfc8c823015be0031a4f1b16a
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat, 11 Nov 2023 17:02:54 +0200

Add a 0x0.st pasting script.

Diffstat:
Abin/0x0.st | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+), 0 deletions(-)

diff --git a/bin/0x0.st b/bin/0x0.st @@ -0,0 +1,62 @@ +#!/bin/sh + +set -e + +cleanup () { + if [ "$2" = "--debug" ]; then + printf "\nRemoving \"%s\"\n" "$temp_file" 1>&2 + fi + rm "$temp_file" +} + +help_message () { + printf "Usage: +\t%s -p [--debug] +\t%s -s [--debug] +\t%s -b [--debug] +\t%s [FILENAME] [--debug] + +Flags: + -p, --primary Operate on the PRIMARY selection. + -s, --secondary Operate on the SECONDARY selection. + -b, --clipboard Operate on the CLIPBOARD selection. + --debug Show debug information. +" "$0" "$0" "$0" + exit 1 + +} + +if [ -z "$(command -v xsel)" ] || [ -z "$(command -v curl)" ]; then + printf "Must install xsel and curl.\n" +fi + +if [ "$#" -ne 1 ] && + [ "$#" -ne 2 ]; then + help_message +fi + +if [ "$1" = "-p" ] || + [ "$1" = "-s" ] || + [ "$1" = "-b" ]; then + xsel_flag="$1" + + trap cleanup EXIT + + temp_file=$(mktemp) + + xsel "$xsel_flag" > "$temp_file" + + if [ "$2" = "--debug" ]; then + cat "$temp_file" + else + curl -F"file=@${temp_file}" 0x0.st + fi +else + filename="$1" + + if [ "$2" = "--debug" ]; then + cat "$filename" + else + curl -F"file=@${filename}" 0x0.st + fi +fi