>
> There is another similar command-line tool here:
> http://www.vergenet.net/~conrad/software/xsel/
> I can't say if it's better, but It does have a built-in --append option.
>
Thanks a lot for the response! There is 'sudo apt-get install xsel' in
Ubuntu, so I tried that, but it ended up being somewhat complicated.
First of all, xsel persistently failed to do anything while called
directly from Scite/Lua, and finally I realized xsel segfaults if you
try to run 'append' while the clipboard is empty! So that forced me to
make a script like this:
---
sudo cat > /usr/bin/appendclipboard <<EOF
CMD=""
REP=""
#DBG="-vvvv"
DBG=""
# is clipboard not empty?
# check because xsel segfaults for empty clipboard!!
echo "$1"
echo ---
xsel --clipboard -o 2>&1
if [ -n "$(xsel --clipboard -o)" ]
then
REP="Clipboard not empty.. Clipboard added."
CMD="xsel --clipboard -i -a $DBG"
else
REP="Clipboard empty.. Clipboard inited."
CMD="xsel --clipboard -i $DBG"
fi
echo ---
#REZ=$(echo "$1" | $CMD 2>&1)
# when running like this in $(), MUST add -i to xsel
# even if its manpage says its implied!!!
# else nothing is appended!
# same problem when running from Scite, even without $()
REZ=$(eval 'echo "$1" | $CMD 2>&1')
echo "$REZ"
echo ----
echo $REP
echo ---
xsel --clipboard -o
EOF
chmod +x /usr/bin/appendclipboard
----
And then, this being called by Lua as:
----
function SelAppendClipboard()
local selorig = editor:GetSelText()
-- escape bloody quotes
local sel = string.gsub(selorig, '"', '\\"')
local cmd = 'bash -c \'appendclipboard "' .. sel .. '"\''
print(cmd)
--~ local ret = os.execute(cmd)
--~ print(ret)
f = io.popen(cmd) -- runs command
l = f:read("*a") -- read output of command
print(l)
end
---
Now, this works fine, if you initially select, say, a filename of an
icon in Gnome and you copy it - so that is your initial clipboard;
then the script as above appends properly. But, if you afterwords
press Ctrl+C for a text selection in Scite (i.e. you overwrite the
clipboard with text from Scite), and then try to append - Scite
freezes (and so does strace), and can be only killed afterward !
(and don't forget to delete 'rm /tmp/SciTE.11398.in' or whatever file
is the Scite handle - otherwise Scite will silently fail to start, if
you have 'check.if.already.open=1' [# one instance of SciTE only] in
your options.. )
In any case, I didn't it was worth debugging that kind of a freeze
(with no errors whatsoever); so I made this patch:
Patch: Added Lua functions for get/set clipboard - scite-interest |
Google Groups -
http://groups.google.com/group/scite-interest/browse_thread/thread/a3fcc32957b11355
and so far so good :) ...
Thanks again,
Cheers!