Don't update conkyrc directly
* By using a temp file and comparing we can avoid excessive reloading of conky
This commit is contained in:
parent
6686a4d495
commit
1451035560
1 changed files with 16 additions and 10 deletions
|
|
@ -1,24 +1,30 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
|
CONFIG_BASE="${HOME}/.conkyrc_base"
|
||||||
|
CONFIG_NEW="${HOME}/.conkyrc_new"
|
||||||
|
CONFIG_REAL="${HOME}/.conkyrc"
|
||||||
|
|
||||||
IF_LIST=($(ip l \
|
IF_LIST=($(ip l \
|
||||||
| egrep '^[0-9]+:\s+(eth|en|wl)' \
|
| egrep '^[0-9]+:\s+(eth|en|wl)' \
|
||||||
| sed -r 's/^[0-9]+:\s+(\w+):.*/\1/' \
|
| sed -r 's/^[0-9]+:\s+(\w+):.*/\1/' \
|
||||||
| sort))
|
| sort))
|
||||||
|
|
||||||
# Reset conkyrc to default
|
# Build new config from the default
|
||||||
rm "${HOME}/.conkyrc"
|
rm "${CONFIG_NEW}"
|
||||||
cp "${HOME}/.conkyrc_base" "${HOME}/.conkyrc"
|
cp "${CONFIG_BASE}" "${CONFIG_NEW}"
|
||||||
|
|
||||||
# Add interfaces to conkyrc
|
# Add interfaces to conkyrc_new
|
||||||
for i in "${IF_LIST[@]}"; do
|
for i in "${IF_LIST[@]}"; do
|
||||||
if [[ "${i:0:1}" == "e" ]]; then
|
if [[ "${i:0:1}" == "e" ]]; then
|
||||||
sed -i -r "s/#Network/Wired:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc
|
sed -i -r "s/#Network/Wired:\${alignr}\${addr $i}\n#Network/" "${CONFIG_NEW}"
|
||||||
else
|
else
|
||||||
sed -i -r "s/#Network/Wireless:\${alignr}\${addr $i}\n#Network/" $HOME/.conkyrc
|
sed -i -r "s/#Network/Wireless:\${alignr}\${addr $i}\n#Network/" "${CONFIG_NEW}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Remove '#Network' line to prevent duplicating lines if this script is re-run
|
# Replace config if there were changes
|
||||||
sed -i -r "s/#Network//" $HOME/.conkyrc
|
if ! diff -q "${CONFIG_NEW}" "${CONFIG_REAL}" >/dev/null 2>&1; then
|
||||||
|
rm "${CONFIG_REAL}"
|
||||||
# vim: sts=2 sw=2 ts=2
|
cp "${CONFIG_NEW}" "${CONFIG_REAL}"
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue