Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reboot to windows option #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions rofi-power-menu
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set -e
set -u

# All supported choices
all=(shutdown reboot suspend hibernate logout lockscreen)
all=(shutdown reboot suspend hibernate logout lockscreen windows)

# By default, show all (i.e., just copy the array)
show=("${all[@]}")
Comment on lines 18 to 19
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# By default, show all (i.e., just copy the array)
show=("${all[@]}")
# By default, show all others except "Reboot to Windows"
show=(shutdown reboot suspend hibernate logout lockscreen)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense. Then this windows option should get added to the readme for visibility.

Expand All @@ -26,6 +26,7 @@ texts[suspend]="suspend"
texts[hibernate]="hibernate"
texts[reboot]="reboot"
texts[shutdown]="shut down"
texts[windows]="reboot to Windows"

declare -A icons
icons[lockscreen]="\uf023"
Expand All @@ -36,6 +37,7 @@ icons[hibernate]="\uf7c9"
icons[reboot]="\ufc07"
icons[shutdown]="\uf011"
icons[cancel]="\u00d7"
icons[windows]="\uf17a"

declare -A actions
actions[lockscreen]="loginctl lock-session ${XDG_SESSION_ID-}"
Expand All @@ -45,9 +47,10 @@ actions[suspend]="systemctl suspend"
actions[hibernate]="systemctl hibernate"
actions[reboot]="systemctl reboot"
actions[shutdown]="systemctl poweroff"
actions[windows]="systemctl reboot --boot-loader-entry=auto-windows --boot-loader-menu=0.5"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a generic way to reboot to Windows?

Also, why doesn't normal reboot work? I suppose you can choose which OS to launch during the boot time, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is quite old. I learned a lot since opening this, so I can explain more what would be the right way to do things.

Is this a generic way to reboot to Windows?

As noted above by Spaxly, this systemctl reboot --boot-loader... command only works when you use both systemd (as init) and systemd-boot (as bootloader).

Because setting the next entry is bootloader specific, one would need to add special commands for each bootloader. As I can see it, grub also supports rebooting into another entry. See the manpage. You can specify an entry there.

Using another init (i.e. no systemd) completely breaks the entire script, as there is no systemctl when using other inits. This is also discussed in #11.

Covering all the cases would be hard I guess, so a decision needs to be taken on which inits and boot loaders should be supported. I guess we could also just start with some inits and bootloaders and then extend if people are interested.

Also, why doesn't normal reboot work? I suppose you can choose which OS to launch during the boot time, right?

Yes, you are right. Usually when you use dual booting, your bootloader shows a screen where you can select the boot entry for a few seconds. What this command does though, is that it preselects the chosen entry. No user intervention is needed until the other entry/OS is booted up. That is somewhat convenient.


# By default, ask for confirmation for actions that are irreversible
confirmations=(reboot shutdown logout)
confirmations=(reboot shutdown logout windows)

# By default, no dry run
dryrun=false
Expand Down Expand Up @@ -90,19 +93,19 @@ while true; do
echo " --dry-run Don't perform the selected action but print it to stderr."
echo " --choices CHOICES Show only the selected choices in the given order. Use / "
echo " as the separator. Available choices are lockscreen, logout,"
echo " suspend, hibernate, reboot and shutdown. By default, all"
echo " suspend, hibernate, reboot, windows and shutdown. By default, all"
echo " available choices are shown."
echo " --confirm CHOICES Require confirmation for the gives choices only. Use / as"
echo " the separator. Available choices are lockscreen, logout,"
echo " suspend, hibernate, reboot and shutdown. By default, only"
echo " irreversible actions logout, reboot and shutdown require"
echo " irreversible actions logout, reboot, windows and shutdown require"
echo " confirmation."
echo " --choose CHOICE Preselect the given choice and only ask for a confirmation"
echo " (if confirmation is set to be requested). It is strongly"
echo " recommended to combine this option with --confirm=CHOICE"
echo " if the choice wouldn't require confirmation by default."
echo " Available choices are lockscreen, logout, suspend,"
echo " hibernate, reboot and shutdown."
echo " hibernate, reboot, windows and shutdown."
echo " --[no-]symbols Show Unicode symbols or not. Requires a font with support"
echo " for the symbols. Use, for instance, fonts from the"
echo " Nerdfonts collection. By default, they are shown"
Expand Down