#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; # Launch this with 'rofi' with something like this: # # % rofi -show Select -modes "Select:~/bin/rofi_menu.pl" my $selection = $ARGV[0]; my $app = {}; if (defined $selection) { select_option($app, $selection); } else { show_options($app); } # ----------- # Subroutines # ----------- sub show_options { my ($app) = @_; my @categories = qw(Apps Tools Settings); print join ("\n", @categories); } # ----------- sub select_option { my ($app, $selection) = @_; warn "Selected: $selection\n"; if ($selection eq 'Apps') { show_apps($app); } elsif ($selection eq 'Tools') { show_tools($app); } elsif ($selection eq 'Settings') { show_settings($app); } elsif (my ($sub_app) = $selection =~ /^Apps:(.*)/) { app_launch($app, $sub_app); } elsif (my ($sub_tool) = $selection =~ /^Tools:(.*)/) { tool_launch($app, $sub_tool); } elsif (my ($sub_setting) = $selection =~ /^Settings:(.*)/) { setting_launch($app, $sub_setting); } } # ----------- sub show_apps { my ($app) = @_; my @apps = qw(Gimp VSCode Antigravity Chrome); print join ("\n", map { "Apps:$_" } @apps); } # ----------- sub show_tools { my ($app) = @_; my @apps = qw(Neovide Wezterm Calculator Audio); print join ("\n", map { "Tools:$_" } @apps); } # ----------- sub show_settings { my ($app) = @_; my @apps = qw(Neovim Ghostty Git MPD ncmpcpp); print join ("\n", map { "Settings:$_" } @apps); } # ----------- sub app_launch { my ($app, $sub_app) = @_; if ($sub_app eq "Gimp") { launch_program($app, '/usr/bin/gimp'); } elsif ($sub_app eq "Antigravity") { launch_program($app, '~/bin/dwl_antigravity'); } elsif ($sub_app eq "VSCode") { launch_program($app, '/opt/vscode/VSCode-linux-x64/code', '--enable-features=UseOzonePlatform,WaylandWindowDecorations', '--ozone-platform-hint=auto', '--unity-launch'); } elsif ($sub_app eq "Chrome") { launch_program($app, 'chromium', '--enable-features=UseOzonePlatform,WaylandWindowDecorations', '--ozone-platform=wayland', '--ozone-platform-hint=auto', '--unity-launch'); } } # ----------- sub tool_launch { my ($app, $sub_tool) = @_; if ($sub_tool eq "Neovide") { launch_program($app, 'neovide', '--fork'); } elsif ($sub_tool eq "Wezterm") { launch_program($app, 'wezterm'); } elsif ($sub_tool eq "Calculator") { launch_program($app, 'gnome-calculator'); } elsif ($sub_tool eq "Audio") { launch_program($app, 'rofi', '-show', 'menu', '-modes', 'menu:~/bin/rofi_sound.pl'); } } # ----------- sub setting_launch { my ($app, $sub_setting) = @_; if ($sub_setting eq "Neovim") { launch_program($app, 'neovide', '--fork', '~/.config/nvim/init.lua'); } elsif ($sub_setting eq "Ghostty") { launch_program($app, 'neovide', '--fork', '~/.config/ghostty/config'); } elsif ($sub_setting eq "Git") { launch_program($app, 'neovide', '--fork', '~/.gitconfig'); } elsif ($sub_setting eq "MPD") { launch_program($app, 'neovide', '--fork', '~/.config/mpd/mpd.conf'); } elsif ($sub_setting eq "ncmpcpp") { launch_program($app, 'neovide', '--fork', '~/.config/ncmpcpp/config'); } } # ----------- sub launch_program { my ($app, @program) = @_; my $prog = join(' ', @program); my $launch_cmd = "nohup $prog > /dev/null 2>&1 &"; my $pid = fork(); die "launch_program: couldn't fork: $!" unless defined $pid; if ($pid == 0) { # Child process # Detach from the parent process's session to survive terminal closure # (optional but recommended for complete daemonization) # Use 'setsid()' if available/needed. A simple exit of the parent may suffice. # Execute the new program in place of the child process exec($launch_cmd) or die "Couldn't exec your program: $!"; } else { # Parent process # Parent can do other things here, or simply exit exit(0); # Exit the parent script } }