-
Notifications
You must be signed in to change notification settings - Fork 5
/
start.sh
executable file
·126 lines (98 loc) · 3.43 KB
/
start.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
#!/bin/bash
#
# rofi-desktop startup script
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit; pwd -P )"
CONFIG_DIR="${ROFI_CONFIG_DIR:-$SCRIPT_PATH/scripts/config}"
CONFIG_DIR="$SCRIPT_PATH/scripts/config"
STARTUP_FILE="$CONFIG_DIR/autostart"
FIRST_RUN_FILE="$CONFIG_DIR/first-run"
MONITORS_CACHE=${MONITORS_CACHE:-"$CONFIG_DIR/monitor-layout"}
WALLPAPER_CACHE=${WALLPAPER_CACHE:-"$CONFIG_DIR/wallpaper"}
KEYMAP_CACHE=${KEYMAP_CACHE:-"$CONFIG_DIR/keyboard-layout"}
WELCOME_MSG=${WELCOME_MSG:-"Welcome to rofi-desktop! 
Press any key to continue with the setup."}
RUN_APPMENU_PROMPT=${RUN_APPMENU_PROMPT:-"Run appmenu-service.py on startup?"}
RUN_KEYPRESS_PROMPT=${RUN_KEYPRESS_PROMPT:-"Run keypress.py on startup?"}
RUN_MONITOR_PROMPT=${RUN_MONITOR_PROMPT:-"Run x11_device_watcher.py on startup?"}
export MONITORS_CACHE
export WALLPAPER_CACHE
run_program() {
is_running=$(ps aux | grep -c "$1")
if [ "${is_running}" -lt 2 ]; then
echo "running" "$1"
"$1" &
else
echo "$1" "already running"
fi
}
ask_user() {
prompt="$1"
choice=$(echo -e "Yes\nNo" | $ROFI_CMD -p "$prompt")
if [ "$choice" = "Yes" ]; then
echo "$choice"
fi
}
wizard() {
rofi -markup -e "$WELCOME_MSG"
# TODO: set menu language
"$SCRIPT_PATH"/scripts/rofi-locale.sh
"$SCRIPT_PATH"/scripts/rofi-keyboard-layout.sh
"$SCRIPT_PATH"/scripts/rofi-clocks.sh
"$SCRIPT_PATH"/scripts/rofi-mime.sh;
# show monitor layout menu only if more than one screen is connected
connected_screens=$(xrandr | awk '( $2 == "connected" ){ print $1 }' | wc -l)
if [ "$connected_screens" -gt 1 ]; then
"$SCRIPT_PATH"/scripts/rofi-monitor-layout.sh
fi
"$SCRIPT_PATH"/scripts/rofi-wallpaper.sh;
# ask programs to run on startup and add entries to autostart file
truncate -s 0 "$STARTUP_FILE"
if [ -n "$(ask_user "$RUN_APPMENU_PROMPT")" ] ; then
echo "appmenu-service" >> "$STARTUP_FILE"
run_program "$SCRIPT_PATH/scripts/appmenu-service.py"
fi
if [ -n "$(ask_user "$RUN_KEYPRESS_PROMPT")" ]; then
echo "keypress" >> "$STARTUP_FILE"
run_program "$SCRIPT_PATH/scripts/keypress.py"
fi
if [ -n "$(ask_user "$RUN_MONITOR_PROMPT")" ]; then
echo "x11_device_watcher" >> "$STARTUP_FILE"
run_program "$SCRIPT_PATH/scripts/x11_device_watcher.py"
fi
# TODO: run greenclip
# TODO: run rofication-daemon
}
startup() {
# set wallpaper
if [ -f "$WALLPAPER_CACHE" ]; then
echo "Setting wallpaper"
"$SCRIPT_PATH/scripts/set-wallpaper.sh" "$WALLPAPER_CACHE"
fi
# set keyboard layout
if [ -f "$KEYMAP_CACHE" ]; then
echo "Setting keyboard layout" "$(cat "$KEYMAP_CACHE")"
setxkbmap "$(cat "$KEYMAP_CACHE")"
fi
# check entries in autostart file
if [ -n "$(grep appmenu-service "$STARTUP_FILE")" ]; then
run_program "$SCRIPT_PATH/scripts/appmenu-service.py"
fi
if [ -n "$(grep keypress "$STARTUP_FILE")" ]; then
run_program "$SCRIPT_PATH/scripts/keypress.py"
fi
if [ -n "$(grep x11_device_watcher "$STARTUP_FILE")" ]; then
run_program "$SCRIPT_PATH/scripts/x11_device_watcher.py"
fi
# TODO: run greenclip
# TODO: run rofication-daemon
}
# export env vars
set -a
source "$SCRIPT_PATH/config/environment"
set +a
# show wizard if first run
if [ -f "$FIRST_RUN_FILE" ]; then
startup
else
wizard
touch "$FIRST_RUN_FILE"
fi