Vendor the command set the menu and shell depend on
This commit is contained in:
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
# blob:summary=Copy text to the clipboard and type or paste it
|
||||
# blob:group=clipboard
|
||||
# blob:args=[--shift-insert] [--copy-only] [--history-index <index>|<text>]
|
||||
# blob:examples=blob clipboard paste text "hello" | blob clipboard paste text --shift-insert "hello"
|
||||
# blob:hidden=true
|
||||
|
||||
use_shift_insert=false
|
||||
copy_only=false
|
||||
history_index=""
|
||||
text=""
|
||||
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
--shift-insert)
|
||||
use_shift_insert=true
|
||||
shift
|
||||
;;
|
||||
--copy-only)
|
||||
copy_only=true
|
||||
shift
|
||||
;;
|
||||
--history-index)
|
||||
history_index="${2:-}"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
copy_history_entry() {
|
||||
local history_path="$HOME/.local/state/blob/clipboard-history.json"
|
||||
|
||||
[[ $history_index =~ ^[0-9]+$ ]] || exit
|
||||
jq -e --argjson index "$history_index" '.[$index].type == "text" and (.[$index].text | type == "string")' "$history_path" >/dev/null || exit
|
||||
jq -j --argjson index "$history_index" '.[$index].text' "$history_path" | wl-copy
|
||||
}
|
||||
|
||||
if [[ -n $history_index ]]; then
|
||||
copy_history_entry
|
||||
if [[ $copy_only != "true" ]]; then
|
||||
use_shift_insert=true
|
||||
fi
|
||||
else
|
||||
text=${1:-}
|
||||
[[ -n $text ]] || exit
|
||||
printf '%s' "$text" | wl-copy
|
||||
fi
|
||||
|
||||
if [[ $copy_only == "true" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
sleep 0.15
|
||||
|
||||
if [[ $use_shift_insert == "true" ]]; then
|
||||
wtype -M shift -k Insert -m shift 2>/dev/null || true
|
||||
else
|
||||
wtype "$text" 2>/dev/null || true
|
||||
fi
|
||||
Reference in New Issue
Block a user