Page 1 of 1

How to replace a value of a key of cinnamon configuration file through the bash command line?

Posted: Fri Jan 17, 2020 1:37 pm
by antrrax
How to replace a value of a key of cinnamon configuration file through the bash command line?
I am trying to use the jq package. For example:

In the file ~/.cinnamon/configs/menu@cinnamon.org/0.json

how to replace "favbox-min-height" -> "value" to 405.0

I tried like this but it didn't work:
$ jq '.favbox-min-heigh.value = 405.0' '~/.cinnamon/configs/menu@cinnamon.org/0.json'

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Posted: Fri Jan 17, 2020 4:53 pm
by gittiest personITW
You can use the 'sed' command.

sudo sed -i 's/OLDTEXT/NEWTEXT/g' /home/USER/.cinnamon/configs/menu@cinnamon.org/0.json

The CAPITALS are obviously what you substitute.
Be very careful as it will substitute every instance of OLDTEXT with NEWTEXT.
Best do a backup of that file first.

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Posted: Fri Jan 17, 2020 6:40 pm
by antrrax
gittiest personITW wrote:
Fri Jan 17, 2020 4:53 pm
Be very careful as it will substitute every instance of OLDTEXT with NEWTEXT.
Using sed to replace values in a json file would not be a good thing, as it could inadvertently misconfigure something.

for example, in the file ~/.cinnamon/configs/menu@cinnamon.org/0.json there are many equal [keys: values]:

Code: Select all

"value": true
If I use sed in these cases, I would have problems

So I would like to replace the values via the jq application which should better work with json

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Posted: Sat Jan 18, 2020 5:06 am
by smurphos
antrrax wrote:
Fri Jan 17, 2020 6:40 pm
So I would like to replace the values via the jq application which should better work with json
This might help - https://stackoverflow.com/questions/427 ... n-using-jq

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Posted: Wed Jan 22, 2020 8:21 am
by antrrax
For those interested in the solution:
First install the packages:
$sudo apt install jq
$sudo apt install moreutils
The Jq creates a new json with the modified value
The Sponge from the moreutils package, replaces the original json with the json created by Jq

Code: Select all

$jq '.["favbox-min-height"] |= (.value = 405.0)' ~/.cinnamon/configs/menu@cinnamon.org/0.json | sponge ~/.cinnamon/configs/menu@cinnamon.org/0.json
other expample:

Code: Select all

$jq '.["menu"] |= (.title = "test")' ~/.cinnamon/configs/menu@cinnamon.org/0.json | sponge ~/.cinnamon/configs/menu@cinnamon.org/0.json
Then restart cinnamon