You are not logged in.
Within my Openbox rc.xml file I have two lines as follows
<!-- <keybind key="Right"> -->
<keybind key="s-Up">
I wish to frequently toggle/ swap the above two lines for the below two lines using a script
<!-- <keybind key="s-Up"> -->
<keybind key="Right">
This allows me to quickly change a keybinding without tediously editing my rc.xml every time.
The script I have so far is below, and is not working, though I know it is close.
I'm not too bothered how this toggling is achieved.
The sed expressions below work as they should.
And the if statement seems to do the first sed swap if the condition is met but not the second if it is not met.
var_a=""
var_a=$(grep -zoP "<\!\-\- <keybind key=\"Right\"> \-\->\n\n<keybind key=\"s-Up\">" /home/kes/Dropbox/lubuntu-rc.xml | sed ':a;N;$!ba;s|\n\n||g')
var_a=$(grep -zoP "<\!\-\- <keybind key=\"Right\"> \-\->\n\n<keybind key=\"s-Up\">" /home/kes/Dropbox/lubuntu-rc.xml | tr -d '\n' )
# result of grep is
# <!-- <keybind key="Right"> --><keybind key="s-Up">
echo $var_a; sleep 0.5
#if [[ -z ! "$var_a" ];then
if [[ '$var_a'=='<!-- <keybind key="Right"> --><keybind key="s-Up">' ]]; then
sed -ie ':a;N;$!ba;s|<!-- <keybind key="Right"> -->\n\n<keybind key="s-Up">|<!-- <keybind key="s-Up"> -->\n\n<keybind key="Right">|g' /home/kes/Dropbox/lubuntu-rc.xml
else
sed -ie ':a;N;$!ba;s|<!-- <keybind key="s-Up"> -->\n\n<keybind key="Right">|<!-- <keybind key="Right"> -->\n\n<keybind key="s-Up">|g' /home/kes/Dropbox/lubuntu-rc.xml
fi
Last edited by kes (2022-12-05 09:45:06)
Offline
I don't have your lines in my rc.xml so not testing, but here is a full line that should work as an example if it's sed that is the issue.
sed -i 's/<keybind key="s-Up">/<!-- <keybind key="s-Up"> -->/g' "$HOME/Dropbox/lubuntu-rc.xml"
Another thought is creating two files and switching between the two.
Offline