I'm trying to find a way to access bash's killring externally. I'm stuck with 1) no way to recursively use readline's yank
and 2) lacking better knowledge of how to follow the kill ring pointer in heap memory. But, I suspect if there is a solution, it's not using either method I've tried.
My first kludge is to create a bash macro that pushes the killring into a file: store the point, paste, put old point up to new point into a file, and finally undo the paste
bash_setprevpoint() { READLINE_POINT_PREV=$READLINE_POINT; }
bash_copyfromprevpoint() { echo ${READLINE_LINE:$READLINE_POINT_PREV:$(($READLINE_POINT-$READLINE_POINT_PREV))} > /tmp/bash_killring.txt; }
bind -x '"\C-\xfe":"bash_setprevpoint"'; bind -x '"\C-\xff":"bash_copyfromprevpoint"'
bind '"\e_":"\C-\xfe\C-y\C-\xff\C-x\C-u"'
But I have no idea how to recursively call e.g. M-y until the killring repeats. I only get the most recent kill. And the keybinding has to be used before it is needed.
My other thought is to look directly into the strings of the bash heap with a script like:
read heap_beg heap_end <<< $(perl -lne 'print "0x$1 0x$2" if m/^([^-]+)-([^ ]+) .*heap/' /proc/$PPID/maps)
sudo dd if=/proc/$PPID/mem bs=1 skip=$(($heap_beg)) count=$(($heap_end-$heap_beg)) |strings -n6|uniq |fzf
but there are a lot more strings than just the killring and it's slow/parsing a lot of data.
The want for external kill ring access is most salient when I'm working in shell and realize the next command should be run in tmux. But when entering, I loose the killring I've previously built up -- which stored the command I typed and then yanked to run tmux instead. That and some useful files that were a pain to tab complete. But there are many times that something like a universal sink for all the kill rings (like a clipboard manager) would be useful.
similar to Integrate readline's kill-ring and the X11 clipboard