-
Notifications
You must be signed in to change notification settings - Fork 25
/
distrobox-terminal-profile.sh
executable file
·128 lines (108 loc) · 3.09 KB
/
distrobox-terminal-profile.sh
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
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
#
# This file is part of the distrobox project:
# https://github.com/89luca89/distrobox
#
# Copyright (C) 2021 distrobox contributors
#
# distrobox is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# distrobox 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 distrobox; if not, see <http://www.gnu.org/licenses/>.
# Print usage to stdout.
# Arguments:
# None
# Outputs:
# print usage with examples.
show_help() {
cat <<EOF
Usage:
distrobox-terminal-profile -n PROFILE_NAME -s SHORTCUT -c CONTAINER_NAME
Options:
--name/-n: user name
--shortcut/-s: keyboard shortcut eg: <Super>Enter, <Alt>s, <Primary><Alt>t
--container/-c: container name
EOF
}
# Parse arguments
while :; do
case $1 in
-h | --help)
# Call a "show_help" function to display a synopsis, then exit.
show_help
exit 0
;;
-n | --name)
if [ -n "$2" ]; then
PROFILE_NAME="$2"
shift
shift
fi
;;
-s | --shortcut)
if [ -n "$2" ]; then
KEYS_SHORTCUT="$2"
shift
shift
fi
;;
-c | --container)
if [ -n "$2" ]; then
CONTAINER_NAME="$2"
shift
shift
fi
;;
*) # Default case: If no more options then break out of the loop.
break ;;
esac
done
set -o errexit
set -o nounset
PROFILE_UUID=$(cat /proc/sys/kernel/random/uuid)
# Gemerate the dconf file for terminal profile
DCONF_PROFILE=$(dconf dump /org/gnome/terminal/legacy/profiles:/)
if ! echo "$DCONF_PROFILE" | grep 'list='; then
DCONF_PROFILE="
[/]
list=['b1dcc9dd-5262-4d8d-a863-c897e6d979b9']
$DCONF_PROFILE
"
fi
DCONF_PROFILE=$(echo "$DCONF_PROFILE" | sed "s|list=\[|list=\['$PROFILE_UUID',|g")
DCONF_PROFILE="$DCONF_PROFILE
[:$PROFILE_UUID]
background-color='rgb(32,32,32)'
bold-is-bright=true
custom-command='$(command -v distrobox-enter) -n $CONTAINER_NAME'
font='UbuntuMono Nerd Font 14'
foreground-color='rgb(255,255,255)'
scrollbar-policy='never'
use-custom-command=true
use-system-font=true
use-theme-colors=false
visible-name='$PROFILE_NAME'
"
echo "$DCONF_PROFILE" > /tmp/dconf.conf
dconf load /org/gnome/terminal/legacy/profiles:/ < /tmp/dconf.conf
DCONF_KEYS=$(dconf dump /org/gnome/settings-daemon/plugins/media-keys/)
KEYS_INDEX=$(echo "$DCONF_KEYS" | grep -Eo "[0-9]+" | sort -u | tail -n 1)
KEYS_INDEX=$((KEYS_INDEX + 1))
DCONF_KEYS=$(echo "$DCONF_KEYS" | sed "s|custom-keybindings=\[|custom-keybindings=\['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom$KEYS_INDEX/',|g")
DCONF_KEYS="$DCONF_KEYS
[custom-keybindings/custom$KEYS_INDEX]
binding='$KEYS_SHORTCUT'
command='gnome-terminal --tab-with-profile=$PROFILE_NAME'
name='Gnome Terminal - $PROFILE_NAME'
"
echo "$DCONF_KEYS" > /tmp/dconf.conf
dconf load /org/gnome/settings-daemon/plugins/media-keys/ < /tmp/dconf.conf
rm /tmp/dconf.conf