How to use the command 'rofi' (with examples)
- Linux
- December 25, 2023
Rofi is an application launcher and window switcher that can be used to quickly switch between applications and windows. It provides a way to easily search and launch apps, execute commands, and switch between open windows in a graphical user interface.
Use case 1: Showing the list of apps
Code:
rofi -show drun
Motivation: This command is useful when you want to quickly search and launch applications installed on your system. It provides a graphical list of apps, allowing you to easily navigate and select the desired app.
Explanation:
rofi
: The command to invoke Rofi.-show drun
: Specifies the mode to display the list of applications (drun
stands for “desktop run”).
Example output: A graphical interface will appear showing a list of available applications along with a search bar. You can use the search bar to filter the list of apps, and then press Enter to launch the selected app.
Use case 2: Showing the list of all commands
Code:
rofi -show run
Motivation: This command is useful when you want to quickly execute commands without opening a terminal. It provides a graphical interface with a search bar, making it easier to find and execute commands.
Explanation:
rofi
: The command to invoke Rofi.-show run
: Specifies the mode to display the list of commands (run
mode).
Example output: A graphical interface will appear showing a list of available commands along with a search bar. You can use the search bar to filter the list of commands, and then press Enter to execute the selected command.
Use case 3: Switching between windows
Code:
rofi -show window
Motivation: This command is useful when you have multiple windows open and want to quickly switch between them. It provides a graphical interface that displays all open windows, making it easier to select and switch to the desired window.
Explanation:
rofi
: The command to invoke Rofi.-show window
: Specifies the mode to display the list of open windows.
Example output: A graphical interface will appear showing a list of open windows along with a search bar. You can use the search bar to filter the list of windows, and then press Enter to switch to the selected window.
Use case 4: Piping a list of items to stdin and printing the selected item to stdout
Code:
printf "Choice1\nChoice2\nChoice3" | rofi -dmenu
Motivation: This command is useful when you have a predefined list of choices and want to select one interactively. It allows you to pipe the list to Rofi and select one of the choices using its graphical interface.
Explanation:
printf "Choice1\nChoice2\nChoice3"
: Prints a list of choices separated by newline characters.|
: Pipes the output of theprintf
command to the input of the next command.rofi
: The command to invoke Rofi.-dmenu
: Specifies that Rofi displays a dmenu-like interface for selecting items from a list.
Example output:
A graphical interface will appear showing the list of choices provided by the printf
command. You can use the arrow keys to navigate through the list, and then press Enter to select the desired choice. The selected choice will be printed to the terminal’s stdout.
Conclusion:
Rofi is a versatile command-line tool that provides a convenient way to launch applications, execute commands, and switch between windows. Its graphical interface and various modes make it easier and more efficient to perform these tasks. Whether you want to quickly search and launch apps, execute commands, switch between windows, or select choices from a predefined list, Rofi can help streamline your workflow.