-
Notifications
You must be signed in to change notification settings - Fork 6
/
gnome-terminal-profile.install
executable file
·208 lines (188 loc) · 8.59 KB
/
gnome-terminal-profile.install
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash -Eue
#
# Install the gnome-terminal custom profile and VGA font for Rogue
#
# Copyright (C) 2015 Rodrigo Silva (MestreLion) <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. See <http://www.gnu.org/licenses/gpl.html>
#
# Adapted from gnome-terminal.install at https://github.com/MestreLion/scripts
#------------------------------------------------------------------------------
# User input
force=0
#------------------------------------------------------------------------------
# Constants
# name must match profile name used by ../roguepc-gnome-terminal !
# Also it must *NOT* contain single-quotes! Spaces and double-quotes are OK
name=RoguePC
gconfdata=gnome-terminal-profile.gconf.xml
#------------------------------------------------------------------------------
# Environment
mydir=$(dirname "$(readlink -f "$0")")
version=$(gnome-terminal --version | awk '{print $4}')
usage() {
echo "Install the gnome-terminal custom profile and VGA font for Rogue"
echo "Optional, but makes Rogue look just like the PC-DOS version"
echo "Usage: ${0##.*/} [-h|--help] [-f|--force]"
exit
}
version_compare() {
# Usage: version_compare <greater|lesser> version [versions...]
# Return 0 if version is the greatest (or the least) of all versions,
# non-zero otherwise
if [[ "$1" == "greater" ]]; then
local cmd=(tail -n1)
else
local cmd=(head -n1)
fi
shift
local version=$(printf "%s\n" "$@" | LC_ALL=C sort --version-sort | "${cmd[@]}")
if ! [[ "$version" == "$1" ]]; then
return 1
fi
}
#------------------------------------------------------------------------------
# For gnome-terminal < 3.8 (~2013): use gconf backend
gt_gconf() {
local name=$1
local gconftool=gconftool
local gcrootkey=/apps/gnome-terminal
local gclistkey=$gcrootkey/global/profile_list
local gcprofrootkey=$gcrootkey/profiles
# Get the first profile key available
local i=-1
local prefix=Profile
while "$gconftool" --dir-exists "$gcprofrootkey"/"$prefix$((++i))"; do :
done
local profile="${prefix}${i}"
local profkey="$gcprofrootkey"/"$profile"
echo "Creating Gnome Terminal profile: $name ($profile)"
# Load the new profile key
"$gconftool" --load <(sed -z 's/\n //g' <<-EOF
<gconfentryfile>
<entrylist base="/apps/gnome-terminal/profiles/${profile}">
<entry><key>allow_bold</key><value><bool>false</bool></value></entry>
<entry><key>alternate_screen_scroll</key><value><bool>true</bool></value></entry>
<entry><key>background_color</key><value><string>#000000000000</string></value></entry>
<entry><key>background_darkness</key><value><float>1</float></value></entry>
<entry><key>background_image</key><value><string></string></value></entry>
<entry><key>background_type</key><value><string>solid</string></value></entry>
<entry><key>backspace_binding</key><value><string>ascii-del</string></value></entry>
<entry><key>bold_color</key><value><string>#000000000000</string></value></entry>
<entry><key>bold_color_same_as_fg</key><value><bool>true</bool></value></entry>
<entry><key>cursor_blink_mode</key><value><string>system</string></value></entry>
<entry><key>cursor_shape</key><value><string>underline</string></value></entry>
<entry><key>custom_command</key><value><string></string></value></entry>
<entry><key>default_show_menubar</key><value><bool>true</bool></value></entry>
<entry><key>default_size_columns</key><value><int>80</int></value></entry>
<entry><key>default_size_rows</key><value><int>25</int></value></entry>
<entry><key>delete_binding</key><value><string>escape-sequence</string></value></entry>
<entry><key>exit_action</key><value><string>close</string></value></entry>
<entry><key>font</key><value><string>Perfect DOS VGA 437 Unicode 24</string></value></entry>
<entry><key>foreground_color</key><value><string>#AAAAAAAAAAAA</string></value></entry>
<entry><key>login_shell</key><value><bool>false</bool></value></entry>
<entry><key>palette</key><value><string>
#000000000000:#AAAA00000000:#0000AAAA0000:#AAAA55550000:
#00000000AAAA:#AAAA0000AAAA:#0000AAAAAAAA:#AAAAAAAAAAAA:
#555555555555:#FFFF55555555:#5555FFFF5555:#FFFFFFFF5555:
#55555555FFFF:#FFFF5555FFFF:#5555FFFFFFFF:#FFFFFFFFFFFF
</string></value></entry>
<entry><key>scroll_background</key><value><bool>true</bool></value></entry>
<entry><key>scroll_on_keystroke</key><value><bool>true</bool></value></entry>
<entry><key>scroll_on_output</key><value><bool>false</bool></value></entry>
<entry><key>scrollback_lines</key><value><int>512</int></value></entry>
<entry><key>scrollback_unlimited</key><value><bool>false</bool></value></entry>
<entry><key>scrollbar_position</key><value><string>right</string></value></entry>
<entry><key>silent_bell</key><value><bool>false</bool></value></entry>
<entry><key>title</key><value><string>Rogue</string></value></entry>
<entry><key>title_mode</key><value><string>replace</string></value></entry>
<entry><key>update_records</key><value><bool>true</bool></value></entry>
<entry><key>use_custom_command</key><value><bool>false</bool></value></entry>
<entry><key>use_custom_default_size</key><value><bool>true</bool></value></entry>
<entry><key>use_system_font</key><value><bool>false</bool></value></entry>
<entry><key>use_theme_colors</key><value><bool>false</bool></value></entry>
<entry><key>visible_name</key><value><string>${name}</string></value></entry>
<entry><key>word_chars</key><value><string>-A-Za-z0-9,./?%&#:_=+@~</string></value></entry>
</entrylist>
</gconfentryfile>
EOF
) &&
# Update the profile list
"$gconftool" --type list --list-type string --set "$gclistkey" \
"$("$gconftool" --get "$gclistkey" | sed "s/]/,$profile]/")"
}
#------------------------------------------------------------------------------
# For gnome-terminal 3.8 onwards: use dconf / gsettings backend
gt_dconf() {
local name=$1
local path='/org/gnome/terminal/legacy/profiles:/'
local profiles= profile= puid= pname= sep=
while IFS= read -r puid; do
pname=$(dconf read "${path}${puid}visible-name")
if [[ "'${name}'" != "$pname" ]]; then continue; fi
if ((force)); then profile=$puid; break; fi
echo >&2 "Profile '$name' already exists: ${puid:1:-1}"
echo >&2 "Delete or rename it, or run again with --force to overwrite"
exit 1
done < <(dconf list "$path" | awk '/^:/{print}')
if [[ "$profile" ]]; then
echo "Updating Gnome Terminal profile: $name (${profile:1:-1})"
else
profile=":$(uuidgen)/"
echo "Creating Gnome Terminal profile: $name (${profile:1:-1})"
profiles=$(dconf read "${path}list")
if [[ "${profiles: -2}" == "']" ]]; then sep=', '; fi
dconf write "${path}list" "${profiles::-1}${sep}'${profile:1:-1}']"
fi
# Created with: dconf dump "${path}${profile}" | sort
dconf load "${path}${profile}" < <(sed -Ez 's/\n +//g' <<-EOF
[/]
background-color='#000000'
cursor-blink-mode='on'
cursor-shape='underline'
default-size-columns=80
default-size-rows=25
font='Perfect DOS VGA 437 Unicode 24'
foreground-color='#AAAAAA'
palette=['#000000', '#AA0000', '#00AA00', '#AA5500',
'#0000AA', '#AA00AA', '#00AAAA', '#AAAAAA',
'#555555', '#FF5555', '#55FF55', '#FFFF55',
'#5555FF', '#FF55FF', '#55FFFF', '#FFFFFF']
scrollbar-policy='never'
use-system-font=false
use-theme-colors=false
use-theme-transparency=false
use-transparent-background=false
visible-name='$name'
EOF
)
}
#------------------------------------------------------------------------------
for arg in "$@"; do [[ "$arg" == "-h" || "$arg" == "--help" ]] && usage ; done
while (($#)); do
case "$1" in
-f|--force) force=1;;
*) printf >&2 "invalid argument: $1\nTry '${0##.*/} --help' for usage\n"; exit 1;;
esac
shift || break
done
if ! version_compare "greater" "$version" 3.8; then
gt_gconf "$name"
else
gt_dconf "$name"
fi
echo "Installing custom font"
"$mydir"/perfect-dos-unicode-font.install
echo "Done!"
echo "Use 'roguepc-gnome-terminal' launcher for the ultimate Rogue experience!"