Cairnbin

Untitled

text 14 views Created: November 24, 2026 at 21:45:09 EST
  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
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

#!/usr/bin/env bash

# haste - Simple, fast Hastebin-compatible paste uploader
# API: https://pste.us/api/v1/pastes

set -Eeuo pipefail

readonly API="https://pste.us/api/v1/pastes"
readonly NAME="${0##*/}"

QUIET=0
VERBOSE=0
CONTENT=""
FILE=""

usage() {
    cat <<EOF
$NAME - Upload text to pste.us

Usage:
  $NAME [options] [text]
  command | $NAME
  $NAME file.txt

Options:
  -q, --quiet       Print only the URL
  -v, --verbose     Show HTTP details
  -h, --help        Show this help

Examples:
  $NAME "Hello World"
  $NAME file.txt
  cat file.txt | $NAME
  $NAME -q "Hello World"
  echo "Hello World" | $NAME
EOF
}

log() {
    (( QUIET )) || printf '%s\n' "$*" >&2
}

die() {
    printf '%s: %s\n' "$NAME" "$*" >&2
    exit 1
}

command -v curl >/dev/null 2>&1 || die "curl is required"
command -v jq >/dev/null 2>&1 || die "jq is required"

# Parse options
while (($#)); do
    case "$1" in
        -q|--quiet)
            QUIET=1
            shift
            ;;
        -v|--verbose)
            VERBOSE=1
            shift
            ;;
        -h|--help)
            usage
            exit 0
            ;;
        --)
            shift
            break
            ;;
        -*)
            die "Unknown option: $1"
            ;;
        *)
            if [[ -n "$FILE" || -n "$CONTENT" ]]; then
                die "Only one input source is allowed"
            fi
            if [[ -f "$1" ]]; then
                FILE="$1"
            else
                CONTENT="$1"
            fi
            shift
            ;;
    esac
done

# Read input
if [[ -n "$FILE" ]]; then
    CONTENT=$(cat -- "$FILE") || die "Unable to read file"
elif (($#)); then
    CONTENT="$*"
elif [[ ! -t 0 ]]; then
    CONTENT=$(cat) || die "Unable to read stdin"
else
    usage
    exit 1
fi

[[ -n "$CONTENT" ]] || die "Nothing to upload"

# Build JSON safely
PAYLOAD=$(jq -n --arg content "$CONTENT" \
    '{content: $content, language: "text"}') ||
    die "Failed to encode JSON"

# Upload
RESPONSE=$(mktemp) || die "Cannot create temporary file"
trap 'rm -f "$RESPONSE"' EXIT

log "Uploading paste..."

CURL_ARGS=(
    --silent
    --show-error
    --fail-with-body
    --location
    --request POST
    --header "Content-Type: application/json"
    --header "Accept: application/json"
    --data-binary "$PAYLOAD"
    --output "$RESPONSE"
    --write-out '%{http_code}'
    --connect-timeout 10
    --max-time 60
)

(( VERBOSE )) && CURL_ARGS+=(--verbose)

if ! STATUS=$(curl "${CURL_ARGS[@]}" "$API"); then
    cat "$RESPONSE" >&2
    die "Upload failed (HTTP ${STATUS:-unknown})"
fi

[[ "$STATUS" =~ ^2[0-9][0-9]$ ]] ||
    die "Server returned HTTP $STATUS: $(cat "$RESPONSE")"

# Extract URL from API response
URL=$(jq -er '
    .data.url //
    .data.link //
    .url //
    .link //
    empty
' "$RESPONSE" 2>/dev/null) ||
    die "Could not find paste URL in response: $(cat "$RESPONSE")"

# Validate URL
[[ "$URL" == https://* ]] ||
    die "Server returned an invalid URL: $URL"

# Output
printf '%s\n' "$URL"

# Clipboard (only in interactive mode)
if (( ! QUIET )) && [[ -t 1 ]]; then
    if command -v wl-copy >/dev/null 2>&1; then
        printf '%s' "$URL" | wl-copy
        log "Copied to clipboard."
    elif command -v xclip >/dev/null 2>&1; then
        printf '%s' "$URL" | xclip -selection clipboard
        log "Copied to clipboard."
    elif command -v pbcopy >/dev/null 2>&1; then
        printf '%s' "$URL" | pbcopy
        log "Copied to clipboard."
    fi
fi

Embed this paste

Install this app

  1. Tap the Share button
  2. Scroll down and tap "Add to Home Screen"
  3. Tap "Add" in the top right

Please confirm