31 lines
703 B
Bash
Executable File
31 lines
703 B
Bash
Executable File
#!/bin/bash
|
|
# mb-setvar: utility to set/change config variables
|
|
# Copyright (C) 2020 napcok <napcok@gmail.com>
|
|
|
|
|
|
if [[ $# < 1 ]]; then
|
|
self=$(basename $0)
|
|
echo "Usage: $self variable=value [/PATH/TO/CONFIG_FILE]"
|
|
echo "Current configuration:"
|
|
cat $HOME/.config/mabox/mabox.conf
|
|
exit 2
|
|
fi
|
|
if [[ $1 != *"="* ]]; then
|
|
self=$(basename $0)
|
|
echo "$self: First argument must be variable=value"
|
|
exit 2
|
|
fi
|
|
|
|
FILE=${2:-$HOME/.config/mabox/mabox.conf}
|
|
#echo $1
|
|
search=$(echo $1|cut -d= -f1)
|
|
if [[ $search =~ "bottom_img" ]]; then
|
|
sed -i /^"$search="/d $FILE
|
|
fi
|
|
if grep -Rq $search $FILE
|
|
then #found
|
|
sed -i s/^"$search=".*$/"$1"/ $FILE
|
|
else #not found
|
|
echo $1 >> $FILE
|
|
fi
|