setconf is a small
utility that can be used for changing settings in configuration textfiles.
can it do?
If there's a textfile
fields like these:
lights := on
setconf can change the values to something else. It will take the first
key it finds and change the value.
setconf can also change values that span over multiple lines, by adding an end string as the last parameter. A typical end string would be ')' or ']'.
You are writing a PKGBUILD
for Arch and wish to change a setting without using sed.
Let's say you want to change CC from abc to gcc and that "CC=gcc make"
doesn't cut it, for some reason.
Then you can use the following command:
setconf Makefile CC gcc
- It aims to solve a tiny problem properly instead of a
thousand problems halfway, in true UNIX-spirit.
- It can be used with a command that is very easy to read, as opposed to using sed for the same task.
- There is less redundancy:
- They key does not have to be specified twice.
- They old value does not have to be specified.
- It should be clear from the syntax what is being done.
- It's only one small executable, not a big package.
- It can add options and files if they are missing, by using --add.
Setting a value:
sed -i filename 's/key=oldvalue/key=value/g'
setconf filename key value
Setting a value, adding the key and value if missing and creating the file if missing:
grep -q 'x=' file 2>/dev/null && sed 's/x=.*/x=7/g' -i file || echo 'x=7' >> file
setconf -a file x=7
Note that the example using sed will not handle variations in whitespace or in choice of assignment symbol.
. Also note that the old value may have to be provided if performing replacements with sed.
Which arguments are supported?
setconf ordinarily takes a filename, key and a new value for that key.
One can also give an optional end string, for replacing multiline values.
It's also possible to add lines with -a or --add.
See the man page or --help output for more information.
Source code and bug tracker
The source and issue tracker is available at github
git clone git://github.com/xyproto/setconf.git
pacman -S setconf
See also: package webpage
It's recommended to install setconf with your distros package management system.
Here is a quick, manual way of installing the latest version of setconf:
curl -o- http://setconf.roboticoverlords.org/setconf-0.6.3.tar.xz | tar JxC /tmp
sudo install -Dm755 /tmp/setconf-0.6.3/setconf.py /usr/bin/setconf
sudo install -Dm644 /tmp/setconf-0.6.3/setconf.1.gz /usr/share/man/man1/setconf.1.gz
Run the two last commands as root instead of with sudo, if you prefer.
Alexander F Rødseth 2014