Fix large clipboard history pastes
Clipboard history selections passed the full selected text as a process argument to omarchy-clipboard-paste-text. Large entries can exceed Linux's per-argument exec limit, so the helper never starts reliably for big copied blocks. Pass the original history index instead and have the helper read that entry from clipboard-history.json before wl-copy and Shift+Insert. Also focus the first row when opening the manager, keep filtered rows mapped to their original history indexes, and drop whitespace-only text entries.
This commit is contained in:
@@ -2,20 +2,46 @@
|
||||
|
||||
# omarchy:summary=Copy text to the clipboard and type or paste it
|
||||
# omarchy:group=clipboard
|
||||
# omarchy:args=[--shift-insert] <text>
|
||||
# omarchy:args=[--shift-insert] [--history-index <index>|<text>]
|
||||
# omarchy:examples=omarchy clipboard paste text "hello" | omarchy clipboard paste text --shift-insert "hello"
|
||||
|
||||
use_shift_insert=false
|
||||
history_index=""
|
||||
text=""
|
||||
|
||||
if [[ ${1:-} == "--shift-insert" ]]; then
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--shift-insert)
|
||||
use_shift_insert=true
|
||||
shift
|
||||
;;
|
||||
--history-index)
|
||||
history_index="${2:-}"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
copy_history_entry() {
|
||||
local history_path="$HOME/.local/state/omarchy/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
|
||||
use_shift_insert=true
|
||||
shift
|
||||
else
|
||||
text=${1:-}
|
||||
[[ -n $text ]] || exit
|
||||
printf '%s' "$text" | wl-copy
|
||||
fi
|
||||
|
||||
text=${1:-}
|
||||
[[ -n $text ]] || exit
|
||||
|
||||
printf '%s' "$text" | wl-copy
|
||||
sleep 0.15
|
||||
|
||||
if [[ $use_shift_insert == "true" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user