-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconf_utils.sh
More file actions
executable file
·39 lines (35 loc) · 821 Bytes
/
Copy pathconf_utils.sh
File metadata and controls
executable file
·39 lines (35 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/lib/bashlib.sh"
source "${SCRIPT_DIR}/lib/cli.sh"
conf.set() {
local showhelp=0
while (("$#")) && [[ "$1" == -* ]]; do
case "$1" in
--help | -h)
showhelp=1
shift
;;
--*)
echo "Unknown option: $1" >&2
showhelp=1
return 1
;;
*) break ;;
esac
done
((showhelp)) && {
echo "Usage: ${FUNCNAME[0]} [OPTIONS] key value file"
return 0
}
local conf_file="${1:?"Conf file is required"}"
local key="${2:?"Key is required"}"
local value="${3:?"Value is required"}"
[[ ! $(grep -q "^${key}=" "${conf_file}") ]] && {
echo "${key}=${value}" >>"${conf_file}"
return 0
}
sed -i "s/^${key}=.*/${key}=${value}/" "${conf_file}"
}
export -f conf.set
register_simple_completion "conf.set"