dc6d8f46a7eb322ab9b9f638f19a1d56b9088564
3 # Desc: Writes keys from dconf dump
4 # Purpose: Applying custom dconf dump without clobbering other keys
5 # Usage: bkdconfwf [file]
6 # Note: Useful if 'dconf load [file]' wipes existing settings.
8 # Yell, Die, Try Three-Fingered Claw technique
9 # Ref/Attrib: https://stackoverflow.com/a/25515370
10 yell
() { echo "$0: $*" >&2; }
11 die
() { yell
"$*"; exit 111; }
12 try
() { "$@" || die
"cannot $*"; }
14 #declare -A LG_AA # Associative Array for dconf <dir/key> and <value>
16 # Process input file - save <dir/key> & <value> pairs to LG_AA
18 cat "$FILEIN" |
while read line
; do
19 yell
"Begin processing of:$line";
20 if [[ "$line" == "" ]]; then # Check for non-blank line
21 yell
"Blank line detected.";
22 elif [[ "$line" =~ ^
"["(.
*)"]"$
]]; then # Check for bracket-enclosed string (new line group)
23 yell
"New line group detected at line:$line";
24 # Note start of new line group
28 lgDir
="${lgDir#[*}"; # See [2]
29 lgDir
="${lgDir%*]}"; # See [2]
30 yell
"Path is:$lgDir";
31 elif [[ "$line" =~
(.
*)"="(.
*) ]]; then # Check for key=value pair
32 yell
"DEBUG:Key value pair detected:$line";
34 key
="${line%%=*}"; # See [1,3]
35 yell
"Key extracted:$key";
37 value
="${line#*=}"; # See [1,3]
38 yell
"Value extracted:$value";
39 # Add <path/key>=<value> to associative array LG_AA
40 #yell "DEBUG:LG_AA old:$LG_AA";
41 #yell "DEBUG:lgDir:$lgDir";
42 #yell "DEBUG:value:$value";
43 #LG_AA["$lgDir/$key"]+="'$value' ";
44 #yell "DEBUG:LG_AA new:${LG_AA[@]}";
46 try dconf
write "/$lgDir/$key" "$value";
48 yell
"ERROR:Unrecognized string detected."
50 # Increment line group counter
52 yell
"DEBUG:line group number:$lgNum"
53 yell
"Finished processing of:$line";
54 yell
"=============================";
58 # [1] How to extract substrings around specific character using parameter expansion. chepner. https://stackoverflow.com/a/15149278 https://stackoverflow.com/questions/15148796/get-string-after-character#comment43744397_15149278
59 # [2] How to extract string from brackets. Alex Howansky. https://stackoverflow.com/a/7209856
60 # [3] Advanced Bash-Scripting Guide, section 10.1 Manipulating Strings http://tldp.org/LDP/abs/html/string-manipulation.html