-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgsettings-load.rb
75 lines (69 loc) · 1.79 KB
/
gsettings-load.rb
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/ruby
configs = [
{
:schema => "org.gnome.libgnomekbd.keyboard",
:key => "layouts",
:value => "us",
:type => "array",
:append => true
},
{
:schema => "org.gnome.libgnomekbd.keyboard",
:key => "layouts",
:value => "ru",
:type => "array",
:append => true
},
{
:schema => "org.gnome.libgnomekbd.keyboard",
:key => "options",
:value => 'grp\tgrp:alt_shift_toggle',
:type => "array",
:append => false
},
{
:schema => "org.gnome.libgnomekbd.keyboard",
:key => "model",
:value => "some keyboard",
:type => "string"
},
{
:schema => "org.gnome.libgnomekbd.indicator",
:key => "show-flags",
:value => false,
:type => "boolean"
},
{
:schema => "org.gnome.libgnomekbd.indicator",
:key => "font-size",
:value => 10,
:type => "integer"
}
]
configs.each do |config|
# get the current settings
before = `/usr/bin/gsettings get #{config[:schema]} #{config[:key]}`
case config[:type]
when "array"
before = before.gsub(/^[^\[]*/, '').gsub('[', '').gsub(']', '').gsub("'", "").chomp.split(', ')
if config[:append]
unless before.include? config[:value]
after = before << config[:value]
else
after = before
end
else
after = config[:value].to_a
end
command = "/usr/bin/gsettings set #{config[:schema]} #{config[:key]} \"['#{after.join("','")}']\""
when "string"
command = "/usr/bin/gsettings set #{config[:schema]} #{config[:key]} \"#{config[:value]}\""
when "boolean"
command = "/usr/bin/gsettings set #{config[:schema]} #{config[:key]} #{config[:value]}"
when "integer"
command = "/usr/bin/gsettings set #{config[:schema]} #{config[:key]} #{config[:value]}"
else
puts "Type not know!"
end
system(command)
end