Borax Mans Pad
  • About
  • Blog
  • Articles
  • Levels
  • My Computing Setup
  • Programs
  • Quake Servers
  • Links

Fvwm GNU Screen/TMUX menu generator

This program outputs an FVWM Menu that will list all attached and detached GNU Screen and/or TMUX sessions. This menu is meant to be read in as a dynamic menu using ‘Piperead".

Using the menu, you can select attached sessions, or select a detached session, or start a new session. If you select a detached session, it will reattach it with a new terminal instance.

This is handy, because you can see at a glance, which Screen or TMUX sessions you have available, whether they are attached, and if you wish, to attach a detached session to a new terminal instance.

There are three versions! A Perl script , a C version and a native D version.

Jump to the section of the one you prefer. They work similar, but the D program is my preference.

Perl Script

This program was originally created by FVWM forum user “jsosic” as a Perl script and posted on the FVWM forums here back in 2006 https://fvwmforums.org/t/screen-dynamic-submenu/1456/8

This was a Perl script that makes a dynamic menu that will list attached and detached screen sessions. Using the menu, you can select attached sessions, or select a detached session. If you select a detached session, it will reattach it with a new terminal instance.

I’ve modified the original script from jsosic to add TMUX support, modified the way it handles shell commands so it works again, and added support for session names with spaces.

Note! This script file uses xterm as the terminal emulator! Change this to your preferred terminal emulator if you desire.

A search and replace of all occurences of xterm in the script/source with the program of your choice will do it.

The script you can download is called fvwm-screen-menu.pl .

Configuring FVWM for the Perl script

Use the following function to create the dynamic menu. This function destroys the menu, and recreates it, running fvwm-screen-menu.pl to generate the actual menu.

DestroyFunc BuildScreenMenu
AddToFunc BuildScreenMenu
+ I DestroyMenu recreate SubMenuScreen
+ I AddToMenu SubMenuScreen
+ I Piperead fvwm-screen-menu.pl'

Then in your Main menu, add the following line after the initial AddToMenu line for the main menu. This sets up a dynamic action, to call the function BuildScreenMenu when a sub-menu is missing.

+ DynamicPopupAction Function BuildScreenMenu

The first 4 lines of the MainMenu configuration might look like…

DestroyMenu recreate MainMenu
DestroyMenu MainMenu
AddToMenu   MainMenu "Main Menu" Title
+ DynamicPopupAction Function BuildScreenMenu

Note your main menu may not be titled “MainMenu”, but something else.

C version

I have also a version in C, if you prefer one that is native code rather than a Perl script.

This is a simple one-file source version, and probably the one you want.

The source can be downloaded here .

By default, this uses the “xterm” shell. If you want to specify a different shell for SCREEN or TMUX, define them when compiling. Use the -DSCREEN_TERM_CMD and -DTMUX_TERM_CMD flags.

Add

-DSCREEN_TERM_CMD="\"myterm -n termname\""

and/or

-DTMUX_TERM_CMD="\"myterm -n termname\""

I prefer to give the terminal a unique name, but this is not necessary. Something like

-DTMUX_TERM_CMD="\"alacritty\""

will work just as well.

Note that you need the escaped quotes within the outer double quotes.

example below, if you want to use urxvt as the terminal with a terminal title for both Screen and TMUX

gcc -o ~/.fvwm/fvwmscreenmenu fvwmscreenmenu.c -DTMUX_TERM_CMD="\"urxvt -n tmux\"" -DSCREEN_TERM_CMD="\"urxvt -n screen\""

D version

I have also made a version in the D programming language, if you prefer one that is native code rather than a Perl script.

The source can be downloaded here . The PGP signature can be downloaded here .

A compiled binary for 64bit Debian is here . This may work on other distros.

After compilation, copy the binary fvwmscreenmenu anywhere in your $PATH, such as /usr/local/bin, or you can use ~/.fvwm.

The configure FVWM, go here

Installation

Extract the archive then change directory into the archive.

Just run “make” then copy the binary fvwmscreenmenu anywhere in your $PATH, such as /usr/local/bin.

By default, this uses the “xterm” shell.

If you want to specify a different shell for GNU Screen add SCREEN_CMD=“terminal” on the ‘make’ command line where ’terminal’ is whatever program you want to use, along with any command line paramters you want to add.

The default for GNU Screen is “xterm -n screen”

If you want to specify a different shell for TMUX add TMUX_CMD=“terminal” on the ‘make’ command line where ’terminal’ is whatever program you want to use, along with any command line paramters you want to add.

The default for TMUX is “xterm -n tmux”

For example, if you want to use urxvtc as the terminal for both GNU Screen and TMUX, and name the terminal respectively you may run;

make SCREEN_CMD="urxvtc -n screen" TMUX_CMD="urxvtc -n tmux"

Configuring FVWM for the C and D version

This is very similar to the Perl script, but you have a couple more options.

There are two command line options that can be added to fvwmscreenmenu.

--notmux

disables TMUX handling. Use this if you don’t use TMUX or don’t have it installed.

--noscreen

disables GNU Screen handling. Use this if you don’t use GNU Screen or don’t have it installed.

Using both will mean the program outputs nothing. Don’t do that!

Use the following function to create the dynamic menu. This function destroys the menu, and recreates it, running fvwmscreenmenu to generate the actual menu.

DestroyFunc BuildScreenMenu
AddToFunc BuildScreenMenu
+ I DestroyMenu recreate SubMenuScreen
+ I AddToMenu SubMenuScreen
+ I Piperead 'fvwmscreenmenu'

or, if you do not use GNU Screen, and don’t have it installed, you may use something like

DestroyFunc BuildScreenMenu
AddToFunc BuildScreenMenu
+ I DestroyMenu recreate SubMenuScreen
+ I AddToMenu SubMenuScreen
+ I Piperead 'fvwmscreenmenu --noscreen'

Then in your Main menu, add the following line after the initial AddToMenu line for the main menu. This sets up a dynamic action, to call the function BuildScreenMenu when a sub-menu is missing.

+ DynamicPopupAction Function BuildScreenMenu

The first 4 lines of the MainMenu configuration might look like…

DestroyMenu recreate MainMenu
DestroyMenu MainMenu
AddToMenu   MainMenu "Main Menu" Title
+ DynamicPopupAction Function BuildScreenMenu

Note your main menu may not be titled “MainMenu”, but something else.

Then place the following line where you want the actual menu to appear. This will popup the SubMenuScreen menu created by the function BuildScreenMenu.

+ "Screen/Tmux"	Popup SubMenuScreen

This is an example of what the menu looks like. It shows a detached TMUX session and an attached Screen session.

Fvwm Tmux menu
Screen/TMUX menu in action.

Back to Home


© Borax Man 2026

GitGud