aboutsummaryrefslogtreecommitdiff
path: root/clip-capture
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukasz.kasprzak@pm.me>2026-04-14 22:32:43 +0200
committerLukasz Kasprzak <lukasz.kasprzak@pm.me>2026-04-14 22:32:43 +0200
commit83f7fe4b8402bab171d110703a1b1115efbc9b28 (patch)
tree19110702c7d740f6bd8ee4f5d2ebcb97442be237 /clip-capture
parent51d43498b07dc97d795947964534f0903cd05db5 (diff)
downloadbin-83f7fe4b8402bab171d110703a1b1115efbc9b28.tar.gz
bin-83f7fe4b8402bab171d110703a1b1115efbc9b28.zip
cleaned up many scrits and deleted some that were of no use; renamed a lot
Diffstat (limited to 'clip-capture')
-rwxr-xr-xclip-capture45
1 files changed, 45 insertions, 0 deletions
diff --git a/clip-capture b/clip-capture
new file mode 100755
index 0000000..8bedcda
--- /dev/null
+++ b/clip-capture
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+OUTFILE="${OUTFILE:-$HOME/.clips}"
+HAS_NOTIFY=$(command -v notify-send >/dev/null 2>&1 && echo 1 || echo 0)
+
+notify() {
+ [[ "$HAS_NOTIFY" == 1 ]] && notify-send -u "$1" "$2" "$3"
+}
+
+die() {
+ notify critical "capture-clip" "$1"
+ printf 'ERROR: %s\n' "$1" >&2
+ exit 1
+}
+
+get_clipboard() {
+ local out
+ if command -v xclip >/dev/null 2>&1; then
+ out="$(xclip -o -selection clipboard 2>/dev/null)"
+ [[ -z "$out" ]] && out="$(xclip -o -selection primary 2>/dev/null)"
+ printf '%s' "$out"; return
+ fi
+ if command -v xsel >/dev/null 2>&1; then
+ out="$(xsel --clipboard --output 2>/dev/null)"
+ [[ -z "$out" ]] && out="$(xsel --primary --output 2>/dev/null)"
+ printf '%s' "$out"; return
+ fi
+ die "need xclip or xsel"
+}
+
+clip="$(get_clipboard)"
+[[ -n "$clip" ]] || die "clipboard is empty"
+
+ts="$(date '+%Y-%m-%d %H:%M:%S')"
+{
+ printf '# captured %s\n' "$ts"
+ printf '%s\n' "$clip"
+ printf -- '---\n'
+} >> "$OUTFILE"
+
+lines="$(printf '%s\n' "$clip" | wc -l | awk '{print $1}')"
+chars="${#clip}"
+
+notify normal "capture-clip" "Saved to ~/.clips ($lines lines, $chars chars)"