58 lines
1.8 KiB
Bash
Executable File
58 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ollie:parallel read
|
|
# args_json: {"type":"object","required":["action"],"properties":{"action":{"type":"string","description":"get|set|history|clear"},"text":{"type":"string","description":"Text to set (for set action)"},"index":{"type":"string","description":"History index (for history action, default: 0)"}}}
|
|
# ollie:prompt
|
|
# ## gui_clipboard
|
|
#
|
|
# Read/write KDE clipboard via Klipper.
|
|
#
|
|
# - Actions: `get`, `set`, `history`, `clear`
|
|
#
|
|
# ```
|
|
# gui_clipboard(action="get")
|
|
# gui_clipboard(action="set", text="copied text")
|
|
# ```
|
|
# ollie:end
|
|
set -euo pipefail
|
|
|
|
source "$(dirname "$0")/_lib/args.sh"
|
|
|
|
SERVICE="org.kde.klipper"
|
|
PATH_OBJ="/klipper"
|
|
IFACE="org.kde.klipper.klipper"
|
|
|
|
cmd=$(arg_require "action")
|
|
|
|
case "$cmd" in
|
|
get)
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.getClipboardContents" | \
|
|
sed "s/^('//;s/')$//;s/\\\\n/\n/g"
|
|
;;
|
|
set)
|
|
text=$(arg_require "text")
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.setClipboardContents" "$text" >/dev/null
|
|
echo "OK: clipboard set"
|
|
;;
|
|
history)
|
|
index=$(arg_get "index" "0")
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.getClipboardHistoryItem" "$index" | \
|
|
sed "s/^('//;s/')$//;s/\\\\n/\n/g"
|
|
;;
|
|
clear)
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.clearClipboardHistory" >/dev/null
|
|
echo "OK: clipboard history cleared"
|
|
;;
|
|
*)
|
|
echo "error: unknown action: $cmd (use get|set|history|clear)" >&2
|
|
exit 1
|
|
;;
|
|
esac
|