-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathreboot-to-os
executable file
·75 lines (63 loc) · 1.27 KB
/
reboot-to-os
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/env bash
declare -a entries
mapfile -t entries < <(awk 'BEGIN {
l=0
menuindex= 0
stack[t=0] = 0
}
function push(x) {
stack[t++] = x
}
function pop() {
if ( t > 0 ) {
return stack[--t]
} else {
return ""
}
}
{
if ( $0 ~ /.*menu.*{.*/ ) {
push( $0 )
l++
} else if ( $0 ~ /.*{.*/ ) {
push( $0 )
} else if ( $0 ~ /.*}.*/ ) {
X = pop()
if( X ~ /.*menu.*{.*/ ) {
l--
match( X, /^[^'\'']*'\''([^'\'']*)'\''.*$/, arr )
if ( l == 0 ) {
print menuindex ": " arr[1]
menuindex++
submenu=0
} else {
print " " (menuindex-1) ">" submenu ": " arr[1]
submenu++
}
}
}
}' /boot/grub/grub.cfg)
declare selected_entry
selected_entry="$(printf "%s\n" "${entries[@]}" | fzf --cycle --tiebreak=begin,chunk,length --layout=reverse | xargs)"
sudo grub-reboot "$(echo "${selected_entry}" | cut -d':' -f1)"
read -p "Reboot Now? [yN] " -n 1 -r
echo
case $REPLY in
y|Y)
echo
echo "[countdown] rebooting in..."
secs=$((5))
while [ $secs -ge 0 ]; do
sleep 1 &
printf "\r %d " $(( secs ))
secs=$(( secs - 1 ))
wait
done
echo
sudo reboot
;;
*)
echo "Next reboot would boot to:"
echo " ${selected_entry}"
;;
esac