Introduce rofi lib func for simple chooser-action menu
This commit is contained in:
@ -87,7 +87,7 @@ bind = $mainMod, A, exec, rofi -show drun
|
|||||||
# bind = $mainMod, R, exec, rofi -show run
|
# bind = $mainMod, R, exec, rofi -show run
|
||||||
# bind = $mainMod, B, exec, rofi -show filebrowser
|
# bind = $mainMod, B, exec, rofi -show filebrowser
|
||||||
bind = $mainMod, D, exec, ~/NixFlake/config/rofi/menus/systemd-podman.fish
|
bind = $mainMod, D, exec, ~/NixFlake/config/rofi/menus/systemd-podman.fish
|
||||||
bind = $mainMod, escape, exec, ~/NixFlake/config/rofi/menus/power.fish
|
bind = $mainMod, escape, exec, rofi-menu-power
|
||||||
bind = $mainMod, O, exec, ~/NixFlake/config/rofi/menus/lectures.fish
|
bind = $mainMod, O, exec, ~/NixFlake/config/rofi/menus/lectures.fish
|
||||||
bind = $mainMod, M, exec, ~/NixFlake/config/rofi/menus/keybinds.fish
|
bind = $mainMod, M, exec, ~/NixFlake/config/rofi/menus/keybinds.fish
|
||||||
bind = $mainMod, U, exec, ~/NixFlake/config/rofi/menus/vpn.fish
|
bind = $mainMod, U, exec, ~/NixFlake/config/rofi/menus/vpn.fish
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
#!/usr/bin/env fish
|
|
||||||
|
|
||||||
# User chooses option
|
|
||||||
set OPTIONS "Poweroff" "Reboot" "Reload Hyprland" "Exit Hyprland"
|
|
||||||
set OPTION (echo -e (string join "\n" $OPTIONS) | rofi -dmenu -p " power " -i)
|
|
||||||
if not contains $OPTION $OPTIONS
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
# Set command
|
|
||||||
if test "Poweroff" = $OPTION
|
|
||||||
set ACTION "poweroff"
|
|
||||||
else if test "Reboot" = $OPTION
|
|
||||||
set ACTION "reboot"
|
|
||||||
else if test "Reload Hyprland" = $OPTION
|
|
||||||
set ACTION "hyprctl reload"
|
|
||||||
else if test "Exit Hyprland" = $OPTION
|
|
||||||
set ACTION "hyprctl dispatch exit"
|
|
||||||
else
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
# Execute command
|
|
||||||
eval $ACTION
|
|
@ -17,12 +17,17 @@ in {
|
|||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
rofi-wayland
|
rofi-wayland
|
||||||
];
|
|
||||||
|
|
||||||
home.file.".config/rofi/menu-power.fish".text = mylib.rofi.mkSimpleMenu {
|
# Power Menu
|
||||||
"Poweroff" = "poweroff";
|
(mylib.rofi.mkSimpleMenu
|
||||||
"Reload Hyprland" = "hyprctl reload";
|
"power"
|
||||||
};
|
{
|
||||||
|
"Poweroff" = "poweroff";
|
||||||
|
"Reboot" = "reboot";
|
||||||
|
"Reload Hyprland" = "hyprctl reload";
|
||||||
|
"Exit Hyprland" = "hyprctl dispatch exit";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
home.activation = {
|
home.activation = {
|
||||||
# NOTE: Keep the rofi config symlinked, to allow easy changes with hotreload
|
# NOTE: Keep the rofi config symlinked, to allow easy changes with hotreload
|
||||||
|
65
lib/rofi.nix
65
lib/rofi.nix
@ -11,11 +11,64 @@
|
|||||||
# }
|
# }
|
||||||
mkSimpleMenu = let
|
mkSimpleMenu = let
|
||||||
# Makes a string like ''"Poweroff" "Reload Hyprland"''
|
# Makes a string like ''"Poweroff" "Reload Hyprland"''
|
||||||
unpack-options = attrs: "\"${lib.concatStringsSep "\" \"" builtins.attrNames attrs}\"";
|
unpack-options = attrs: "\"${lib.concatStringsSep "\" \"" (builtins.attrNames attrs)}\"";
|
||||||
in
|
|
||||||
prompt: attrs: ''
|
|
||||||
#! ${pkgs.fish}/bin/fish
|
|
||||||
|
|
||||||
set OPTIONS ${unpack-options attrs}
|
mkCase = option: action: "else if test \"${option}\" = $OPTION\n set ACTION \"${action}\"";
|
||||||
'';
|
|
||||||
|
cases = attrs:
|
||||||
|
lib.pipe attrs [
|
||||||
|
(builtins.mapAttrs mkCase)
|
||||||
|
builtins.attrValues
|
||||||
|
(builtins.concatStringsSep "\n")
|
||||||
|
];
|
||||||
|
in
|
||||||
|
prompt: attrs:
|
||||||
|
pkgs.writeScriptBin "rofi-menu-${prompt}" ''
|
||||||
|
#! ${pkgs.fish}/bin/fish
|
||||||
|
|
||||||
|
# OPTIONS contains all possible values Rofi will display
|
||||||
|
set OPTIONS ${unpack-options attrs}
|
||||||
|
|
||||||
|
# We choose a single OPTION using Rofi
|
||||||
|
set OPTION (echo -e (string join "\n" $OPTIONS) | rofi -dmenu -p " ${prompt} " -i)
|
||||||
|
|
||||||
|
# Check if the chosen OPTION is a valid choice from OPTIONS
|
||||||
|
if not contains $OPTION $OPTIONS
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set a command to execute based on the chosen OPTION
|
||||||
|
if false
|
||||||
|
exit # Easier to generate with this
|
||||||
|
${cases attrs}
|
||||||
|
else
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
# Execute the command
|
||||||
|
eval $ACTION
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Receives attrs like:
|
||||||
|
# {
|
||||||
|
# optionA = "exa -1 -D ~/Notes/TU";
|
||||||
|
# optionB = "exa -1 -D ~/Notes/TU/$OPTIONA/Lecture | grep \".pdf\"";
|
||||||
|
# commandB = "xdg-open ~/Notes/TU/$OPTIONA/Lecture/$OPTIONB";
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# Keys:
|
||||||
|
# - optionA, optionB # Command that generates Rofi options:
|
||||||
|
# exa -1 -D ~/Notes/TU
|
||||||
|
# cat /etc/rofi-vpns
|
||||||
|
# - commandA, commandB # Action to execute after sth. was chosen (mutually excl. with command)
|
||||||
|
# - actionsA, actionsB # Configure actions by lookup (mutually excl. with command):
|
||||||
|
# actionsB = {"status" = "systemctl status..."}
|
||||||
|
# - colorA, colorB # Configure highlighting conditions:
|
||||||
|
# colorA = {"red" = "systemctl ... | grep ..."};
|
||||||
|
#
|
||||||
|
# Use $OPTIONA and $OPTIONB to use the options chosen by option<A/B>-command and rofi
|
||||||
|
# Use $EVALA and $EVALB to use the outputs generated by command<A/B>
|
||||||
|
mkMenu = let
|
||||||
|
in
|
||||||
|
prompt: attrs: "";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user