I have this script that I assign t oa keyboard shortcut to simulate pasting through middle click:
#!/bin/bash
aa=0
for randstring in `xsel`
do
if [[ "$randstring" =~ [ěščřžýáíéúůóťďň] ]]
then
xxx=`xsel|sed 's/ě/\\\[ecaron]/g' |sed 's/š/\\\[scaron]/g' |sed 's/č/\\\[ccaron] g' |sed 's/ř/\\\[rcaron]/g' |sed 's/ž/\\\[zcaron]/g' |sed 's/ý/\\\[yacute]/g' |sed 's/á/\\\[aacute]/g' |sed 's/í/\\\[iacute]/g' |sed 's/é/\\\[eacute]/g' |sed 's/ú/\\\[uacute]/g' |sed 's/ů/\\\[uring]/g' |sed 's/ó/\\\[oacute]/g' |sed 's/ď/\\\[dcaron]/g' |sed 's/ň/\\\[ncaron]/g' |sed 's/ť/\\\[tcaron]/g' |sed ':a;N;$!ba;s/\n/\\n/g'`
xvkbd -text "$xxx" 2>/dev/null
aa=1
break
else
aa=0
fi
done
if [[ $aa -eq 0 ]]
then
xsel | xvkbd -file - 2>/dev/null
fi
I use -text with xvkbd when the text is in Czech (my language) because xvkbd does not understand diacritics like ě but only in form like \[ecaron]. Now, with this option, if there is a newline int xsel, it does not get printed with xvkbd. However, when I do
xx="---8<-----\nToday date is: $(date +%Y%m%d)\n---8<-----"
xvkbd -text "$xx" 2>/dev/null
Newlines do get printed.
I suspect the trouble is in the last sed expression sed ':a;N;$!ba;s/\n/\\n/g', but I do not know how to make it better. I think that I need to take care for \ns somehow?