• Stars
    star
    412
  • Rank 105,024 (Top 3 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Configurable power menu mode for Rofi and dmenu

Rofi Power Menu Mode

Rofi Power Menu provides a mode for offering basic power menu operations such as shutting down, logging out, rebooting and suspending. By default, it shows all choices and asks for confirmation for irreversible actions. The choices, their order and whether they require confirmation, can be all configured with command-line options. It also shows symbols by default, but this requires a monospace font with good support for symbols, so it can be disabled with --no-symbols.

In contrast to other similar solutions I've found, the power menu is implemented as a rofi mode, not as a stand-alone executable that launches rofi by itself. This makes it possible to combine the script with the full power of how rofi can use modi. For instance, you can have multiple modi available (-modi) or combine multiple modi in one mode (-combi-modi), pass your own themes (-theme) and configurations as CLI flags (e.g., -fullscreen, -sidebar-mode, -matching fuzzy, -location).

There's also a stand-alone script which uses dmenu (or rofi in dmenu mode). It's also a bit easier to use as you don't need to type the small amount of rofi "boilerplate".

Just to give an example, the screenshot below shows Rofi Power Menu launched as:

rofi \
  -show p \
  -modi p:'rofi-power-menu --symbols-font "Symbols Nerd Font Mono"' \
  -font "JetBrains Mono NF 16" \
  -theme Paper \
  -theme-str 'window {width: 8em;} listview {lines: 6;}'

Screenshot of Rofi Power Menu

Install

You can use the script directly from this directory without needing to install it at all. If you want rofi to find it more easily, the script needs to be found in PATH. If you have ~/.local/bin in PATH, you can just copy the script there:

cp rofi-power-menu ~/.local/bin/

Usage

A simple example showing how to launch the power menu:

rofi -show power-menu -modi power-menu:rofi-power-menu

If you didn't install the script in PATH, you need to give the path to the script. If you're running rofi under this directory where the script is, you can run it as follows:

rofi -show power-menu -modi power-menu:./rofi-power-menu

--help

rofi-power-menu - a power menu mode for Rofi

Usage: rofi-power-menu [--choices CHOICES] [--confirm CHOICES]
                       [--choose CHOICE] [--dry-run] [--symbols|--no-symbols]

Use with Rofi in script mode. For instance, to ask for shutdown or reboot:

  rofi -show menu -modi "menu:rofi-power-menu --choices=shutdown/reboot"

Available options:
  --dry-run            Don't perform the selected action but print it to stderr.
  --choices CHOICES    Show only the selected choices in the given order. Use /
                       as the separator. Available choices are lockscreen,
                       logout,suspend, hibernate, reboot and shutdown. By
                       default, all available choices are shown.
  --confirm CHOICES    Require confirmation for the gives choices only. Use / as
                       the separator. Available choices are lockscreen, logout,
                       suspend, hibernate, reboot and shutdown. By default, only
                       irreversible actions logout, reboot and shutdown require
                       confirmation.
  --choose CHOICE      Preselect the given choice and only ask for a
                       confirmation (if confirmation is set to be requested). It
                       is strongly recommended to combine this option with
                       --confirm=CHOICE if the choice wouldn't require
                       confirmation by default. Available choices are
                       lockscreen, logout, suspend, hibernate, reboot and
                       shutdown.
  --[no-]symbols       Show Unicode symbols or not. Requires a font with support
                       for the symbols. Use, for instance, fonts from the
                       Nerdfonts collection. By default, they are shown
  --[no-]text          Show text description or not.
  --symbols-font FONT  Use the given font for symbols. By default, the symbols
                       use the same font as the text. That font is configured
                       with rofi.
  -h,--help            Show this help text.

--choices=CHOICE1/CHOICE2/...

By default, the menu shows all available choices in a particular order. You can control the shown choices and their order by using --choices and listing the desired choices with / as the separator. Available choices are:

  • lockscreen: Lock screen
  • logout: Log out (confirmation asked by default)
  • suspend: Suspend
  • hibernate: Hibernate
  • reboot: Reboot (confirmation asked by default)
  • shutdown: Shutdown (confirmation asked by default)

For instance, to show only shutdown and reboot choices:

rofi -show power-menu -modi "power-menu:./rofi-power-menu --choices=shutdown/reboot"

Or if you want a typical session menu:

rofi -show session-menu -modi "session-menu:./rofi-power-menu --choices=logout/lockscreen"

--confirm=CHOICE1/CHOICE2/...

By default, confirmation is asked for irreversible actions logout, reboot and shutdown. You can choose for which actions you want confirmation (if any) by listing them with --confirm option. For instance, confirmation can be asked only for reboot and shutdown:

rofi -show power-menu -modi "power-menu:./rofi-power-menu --confirm=reboot/shutdown"

If you don't want confirmations for any actions, just give an empty string:

rofi -show power-menu -modi "power-menu:./rofi-power-menu --confirm=''"

--choose=CHOICE

To open just a confirmation dialog for some fixed choice, you can use --choose=CHOICE, where CHOICE can again be one of the choices listed above. You should also require confirmation for that choice if that isn't done by default. For instance, a simple logout confirmation:

rofi -show logout -modi "logout:./rofi-power-menu --choose=logout"

For some choices (e.g., hibernate), confirmation isn't asked by default, so you probably want to ask that in this case:

rofi -show hibernate -modi "hibernate:./rofi-power-menu --choose=hibernate --confirm=hibernate"

If confirmation isn't asked, the action is performed immediately. Although, that's probably not useful, it is possible. However, note that Rofi will still pop up a menu with no options available. It would be nice if Rofi would not appear at all if it wasn't given any choices. This works when running the accompanied stand-alone script dmenu-power-menu.

--[no-]symbols

Disable or enable Unicode symbols/icons/glyphs. They are enabled by default. In order for them to show up correctly, you need a font that supports the used glyphs. It is recommended to use fonts from the Nerdfonts collection. In addition, it is recommended to use a monospace font, otherwise the symbols widths might be messed up. So, for instance, "Symbols Nerd Font Mono", "Iosevka Nerd Font Mono" or "JetBrainsMono NF" are good options.

--dry-run

For debugging and development purposes, you can pass --dry-run flag. Then, the selected action isn't performed but only printed to stderr.

dmenu

There's a stand-alone script dmenu-power-menu that can be used to run the power menu with dmenu (or rofi in dmenu mode if dmenu isn't found). That script takes the same command-line arguments as listed above for the main script rofi-power-menu. The stand-alone script might be easier to use but you cannot pass arguments to dmenu/rofi so their configuration is hardcoded. Also, you need to install rofi-script-to-dmenu.

Copyright

Copyright (c) 2020 Jaakko Luttinen

MIT License

More Repositories

1

tikz-bayesnet

TikZ library for drawing Bayesian networks, graphical models and (directed) factor graphs in LaTeX.
TeX
826
star
2

suitesparse

PLEASE SEE THE OFFICIAL REPOSITORY. THIS IS NOT MAINTAINED ANYMORE.
C
93
star
3

matlab

A collection of MATLAB scripts
MATLAB
90
star
4

nixos-configuration

Personal NixOS configuration
Nix
63
star
5

NiDE

Niche i3 Desktop Environment: Keyboard-driven DE installed in the home directory
Nix
32
star
6

variational-bayes-book

Open access book on variational Bayesian methods written collaboratively
Python
28
star
7

d3py

Thin Python wrapper for D3.js
Python
21
star
8

junction-tree

The junction tree algorithm for (discrete) factor graphs
Python
18
star
9

neural-network-exercises

Exercises for the course T-61.5130 Machine Learning and Neural Networks
TeX
11
star
10

django-sportsteam

Web site for a sports team or club using Django.
Python
7
star
11

rofi-script-to-dmenu

Run rofi scripts with dmenu (or with dmenu mode of rofi)
Shell
6
star
12

CryptOS

Live offline OS for cryptocurrencies based on NixOS
Nix
5
star
13

haskpy

Haskell/Hask inspired classes and functions in Python
Python
5
star
14

dbus-listen

Execute a command or a script on D-Bus signals
Haskell
3
star
15

jaakkoluttinen.fi

My personal home page
Python
2
star
16

dotfiles

Personal dotfiles
Python
2
star
17

dash-demo

Plotly Dash demo
Python
2
star
18

tikz-in-readthedocs

DEPRECATED. Wrapper for binaries required by TikZ at readthedocs.org
Python
2
star
19

sphinx-bayesnet

BayesNet extension for Sphinx
Python
1
star
20

sphinx-tikz

DEPRECATED. TikZ extension for Sphinx (NOTE! Official and up-to-date repository available at bitbucket by the author)
Python
1
star
21

thesis

PhD Thesis: Bayesian latent Gaussian models
TeX
1
star
22

geneticart

Simple art generator using generative algorithms (school project work in 2006)
Java
1
star
23

mail-forwarder

A simple mail server to forward custom email addresses to one existing email address
Python
1
star