diff options
| author | Lukasz Kasprzak <lukasz.kasprzak@pm.me> | 2026-01-29 01:27:17 +0100 |
|---|---|---|
| committer | Lukasz Kasprzak <lukasz.kasprzak@pm.me> | 2026-01-29 01:27:17 +0100 |
| commit | 70e6d80c2d367480478eacf46363ee88a0e994ff (patch) | |
| tree | 3585660271002a776a8756994c92f8e546f98044 /capture-clip | |
| parent | 646bb0d8df0e720c966dc2992dcf7fe1154d17cf (diff) | |
| download | bin-70e6d80c2d367480478eacf46363ee88a0e994ff.tar.gz bin-70e6d80c2d367480478eacf46363ee88a0e994ff.zip | |
added lots of new dmenu scripts
Diffstat (limited to 'capture-clip')
| -rwxr-xr-x | capture-clip | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/capture-clip b/capture-clip new file mode 100755 index 0000000..3bf17f1 --- /dev/null +++ b/capture-clip @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -euo pipefail + +OUTFILE="${OUTFILE:-$HOME/.clips}" + +notify() { + # $1 = urgency (low|normal|critical) + # $2 = title + # $3 = body + if command -v notify-send >/dev/null 2>&1; then + notify-send -u "$1" "$2" "$3" + fi +} + +die() { + notify critical "capture-clip" "$1" + printf -- "ERROR: %s\n" "$1" >&2 + exit 1 +} + +get_clipboard() { + if command -v xclip >/dev/null 2>&1; then + xclip -o -selection clipboard 2>/dev/null || xclip -o -selection primary + return 0 + fi + if command -v xsel >/dev/null 2>&1; then + xsel --clipboard --output 2>/dev/null || xsel --primary --output + return 0 + fi + die "need xclip or xsel" +} + +clip="$(get_clipboard)" + +[[ -n "$clip" ]] || die "clipboard is empty" + +ts="$(date '+%y:%m:%d %H:%M:%S')" + +{ + printf -- "# caputred %s\n" "$ts" + printf -- "%s\n" "$clip" + printf -- "---\n" +} >> "$OUTFILE" + +lines="$(printf "%s" "$clip" | wc -l | tr -d ' ')" +chars="$(printf "%s" "$clip" | wc -c | tr -d ' ')" + +notify normal "capture-clip" "Saved to ~/.clips ($lines lines, $chars chars)" + |
