Skip to content

Instantly share code, notes, and snippets.

@supershadoe
Last active May 11, 2022 15:27
Show Gist options
  • Save supershadoe/d08249311966b30c4c23d9a1f75f1cdc to your computer and use it in GitHub Desktop.
Save supershadoe/d08249311966b30c4c23d9a1f75f1cdc to your computer and use it in GitHub Desktop.
systemd-boot reboot menu in zenity
#!/usr/bin/env sh
# vim:sw=4:ts=4:sts=4:et
# Reboot menu script
# This script displays a list of boot entries registered in systemd-boot
# Makes it easier to directly reboot to another OS (if dual or multi-booting)
# Created by supershadoe <supershadoe5[at]gmail[dot]com>
# (Skip to line 43 if you want to just see the code)
# COPYRIGHT NOTICE
# Copyright 2022 supershadoe
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# IMPLEMENTATION DETAILS
# set -e makes the script quit on any error
# The data is just flown to other commands using pipes
# Data is fetched from bootctl -> Processed through sed -> Provided to zenity
# as arguments using xargs -> Output of zenity processed by xargs and provided
# to systemctl
# In sed, -n is used to prevent output of pattern space(the inputted data)
# The first s// substitutes the whitespaces and `title: ` with `FALSE "` to
# keep the first row unselected in radiolist in zenity
# The second s// adds a double quote at end to close the quotes
# Quotes were used because of boot entry names having spaces in them
# The third s// substitutes the first occurance of FALSE with TRUE
# as I need the first option to be selected by default
# p prints the edited pattern space
# n changes the pattern space to the next line
# The fourth s// removes the whitespaces and `id: `
# Thus, in the end you get output in the form of `FALSE "entry name"\nentry-id\n`
# ACTUAL CODE
set -e
bootctl list | grep "title\|id" | \
sed -n "
s/[ ]*title: /FALSE \"/
s/$/\"/
0,/FALSE/{s/FALSE/TRUE/}
p
n
s/[ ]*id: //
p" | \
xargs zenity --list --radiolist \
--window-icon \
"/usr/share/icons/Adwaita/32x32/actions/system-reboot-symbolic.symbolic.png" \
--height 300 \
--width 500 \
--text "Select the boot entry to reboot to." \
--title "Reboot Menu" \
--column "Choice" \
--column "Boot Entry" \
--column "UID" \
--print-column 3 | \
xargs -I "{}" systemctl reboot --boot-loader-entry={}
@supershadoe
Copy link
Author

supershadoe commented Jan 11, 2022

Useful for whoever uses systemd-boot as their boot loader.

This script reboots the PC directly into the selected boot entry instead of selecting in boot loader while rebooting(saves you from hitting the Esc button 100 times if you have the menu hidden by default)

Made to be used in XFCE Whisker menu as custom reboot command but it can be used in any DE by assigning this script to a shortcut or some menu. Check the methods for your DE.

Make sure you have zenity to show the menu.

Check out gnome-shell-extension-reboot-menu if you use GNOME for a cleaner integration with the GNOME Shell.

Comment down below if you have any issues or reach out to me via links in my profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment