#!/usr/bin/perl

# Filter this script to pod2man to get a man page:
#   pod2man -c "FVWM Utilities" fvwm-menu-directory | nroff -man | less -e

# To speed up the script, several optimizations were made: trying to minimize
# the number of additional file operations, function calls and includes.

#print STDERR "fvwm-menu-directory @ARGV\n";

use strict;
use Getopt::Long;

my $version = "2.4.19";

my $name  = "MenuBrowser";  # used only with --reuse
my $title = "%*-40p";  # may contain specifiers %d, %p.
my $itemF = "%n";      # may contain specifiers %n, %t, %T, %d, %D, %s.
my $iconT = "";
my $iconD = "";
my $iconF = "";
my $iconA = "";
my $home  = $ENV{'HOME'} || '/tmp';
my $dir   = $home;
my $xterm = "xterm -e";              # the X terminal program to invoke
my $execT = $ENV{'SHELL'} || '/bin/sh';
my $execF = $ENV{'EDITOR'} || "vi";  # the command to execute on plain files
my $execA = undef;
my $commT = undef;
my $commF = undef;
my $commA = undef;
my $all   = 0;  # whether show hidden files (like in 'ls -A')
my $links = 0;  # whether follow linked dirs or not
my $order = 5;  # -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6
my $reuse = 0;  # non-popup mode
my $wmIcons = 0;
my $checkSubdirs = 0;  # whether check subdirs for +x permissions
my $specialDirVal = undef;  # which of (.. ~ /) dirs include or none
my $memoryForSpeed = 0;
my $submenuPos = " item +100 c";  # " menu +0 +0"
my $fvwmUserDir = $ENV{'FVWM_USERDIR'} || "$home/.fvwm";
$fvwmUserDir = $home unless -d $fvwmUserDir;
my $dirFile = "$fvwmUserDir/.fvwm-menu-directory.dir";
my $changeMenuStyle = "";

GetOptions(
	"help|h|?"     => \&showHelp,
	"version|V"    => \&showVersion,
	"name=s"       => \$name,
	"title=s"      => \$title,
	"item=s"       => \$itemF,
	"icon-title=s" => \$iconT,
	"icon-dir=s"   => \$iconD,
	"icon-file=s"  => \$iconF,
	"icon-app=s"   => \$iconA,
	"dir=s"        => \$dir,
	"order=i"      => \$order,
	"all!"         => \$all,
	"links!"       => \$links,
	"xterm=s"      => \$xterm,
	"exec-title=s" => \$execT,
	"exec-file=s"  => \$execF,
	"exec-app:s"   => \$execA,
	"command-title=s" => \$commT,
	"command-file=s"  => \$commF,
	"command-app=s"   => \$commA,
	"reuse!"       => \$reuse,
	"wm-icons"     => \$wmIcons,
	"check-subdirs!"    => \$checkSubdirs,
	"special-dirs:s"    => \$specialDirVal,
	"memory-for-speed!" => \$memoryForSpeed,
	"menu-style=s" => \$changeMenuStyle,
) || wrongUsage();
wrongUsage() if @ARGV;

$name = $dir unless $reuse;
$dir =~ s:^~(/|$):$home$1:;
chomp($dir = `cat "$dirFile"`) if $reuse && -f $dirFile;

unless (-d $dir) {
	# the next line may be commented not to throw error
	#die "$dir does not exist, exiting.\n";
	$dir = $home;
}

$links || !-l $dir || exit(-1);  # exit if linked directories are disabled
chdir($dir) || exit(-1);  # exit if no execute permission on the directory

# expand title
&expandWidthSpecifier(\$title, 'd', (split('/', $dir))[-1] || '/')
	if $title =~ /%(-?\d+)?(\*-?\d+)?d/;
&expandWidthSpecifier(\$title, 'p', $dir)
	if $title =~ /%(-?\d+)?(\*-?\d+)?p/;
$title =~ s/\\t/\t/g;
$itemF =~ s/\\t/\t/g;

# item format optimization variables
my $itemF_eval = $itemF ne '%f';  # evaluation needed
my $itemF_name = undef;
my $itemF_stat = undef;  # stat() needed
my $itemF_date = undef;
my $itemF_size = undef;
my $itemF_type = undef;

if ($itemF_eval) {
	$itemF_name = $itemF =~ /%(-?\d+)?(\*-?\d+)?[nN]/;
	$itemF_date = $itemF =~ /%[dD]/;
	$itemF_size = $itemF =~ /%(-?\d+)?(\*-?\d+)?s/;
	$itemF_type = $itemF =~ /%[tT]/;
	$itemF_stat = $itemF_size || $itemF_date || $itemF_size || $itemF_type;
}

my @type1 = ("Sock", "Link", "File", "Blck", "Dir ", "Char", "Pipe");
my @type2 = ("S", "L", "F", "B", "D", "C", "P");

if ($wmIcons) {
	$iconT ||= "menu/folder-open.xpm";
	$iconD ||= "menu/folder.xpm";
	$iconF ||= "menu/file.xpm";
	$iconA ||= "menu/utility.xpm";
}

my $iconTStr = $iconT? "%$iconT%": "";
my $iconDStr = $iconD? "%$iconD%": "";
my $iconFStr = $iconF? "%$iconF%": "";
my $iconAStr = $iconA? "%$iconA%": "";

$execT = undef if defined $execT && $execT eq '-';
$execF = undef if defined $execF && $execF eq '-';
$execA = undef if defined $execA && $execA eq '-';

$execT = $execT =~ /^\^(.*)$/? $1: "$xterm $execT" if defined $execT;
$execF = $execF =~ /^\^(.*)$/? $1: "$xterm $execF" if defined $execF;
$execA = $execA =~ /^\^(.*)$/? $1: "$xterm $execA" if defined $execA;

$commT = undef if defined $commT && $commT eq '-';
$commF = undef if defined $commF && $commF eq '-';
$commA = undef if defined $commA && $commA eq '-';

$commT = defined $execT? qq(Exec cd "%d"; $execT): "Nop" if !defined $commT;
$commF = defined $execF? qq(Exec $execF "%f"):     "Nop" if !defined $commF;
$commA = defined $execA? qq(Exec $execA "%f"):    $commF if !defined $commA;

# manage special directories if needed
my ($specialDirLines, $specialDirPos, @specialDirs) = ("");
$specialDirVal = "1,2" if defined $specialDirVal && $specialDirVal eq "";
if ($specialDirVal && $specialDirVal =~ /([\d,]+)(-?)/) {
	@specialDirs = grep(/^[1-3]$/, split(/,+/, $1));
	$specialDirPos = $2? -1: 1;
}
if (@specialDirs) {
	my $parentDir = $dir eq '/' || $dir !~ m!^(.*)/[^\/]+$!? undef: $1;
	$parentDir = '/' if defined $parentDir && $parentDir eq '';
	my @specialDirDef = (
		[ '..' => $parentDir ],
		[ '~'  => $home ],
		[ '/'  => '/' ],
	);
	foreach (@specialDirs) {
		$specialDirLines .= qq(+ "" Nop\n) if $specialDirLines;
		$specialDirLines .= &evalFolderLine(@{$specialDirDef[$_ - 1]});
	}
} else {
	$specialDirPos = 0;
}

# create file listing
opendir(DIR, ".");
my @files = readdir(DIR);
closedir(DIR);
@files = grep /^[^.]/, @files unless $all;

my $absOrder = abs($order);
# To avoid warnings, '!!' must be added before '-d'. Will this slow things?
my $sortSub =
	$absOrder == 2? sub { -d $b <=> -d $a }:
	$absOrder == 3? sub { -d $a <=> -d $b }:
	$absOrder == 4? sub { $a cmp $b }:
	$absOrder == 5? sub { -d $b <=> -d $a || $a cmp $b }:
	$absOrder == 6? sub { -d $a <=> -d $b || $a cmp $b }:
	sub { 0 };
@files = sort $sortSub @files if $absOrder != 1;
@files = reverse @files if $order < 0;

# dump all menu items and start adding new items
my $menuName  = &escapeFvwmName($name);
my $menuName2 = &escapeMenuName($name);
print qq(DestroyMenu recreate "$menuName"\nAddToMenu "$menuName2"\n);

# destroy the menu after it is popped down
print qq(+ DynamicPopDownAction DestroyMenu "$menuName"\n)
	unless $memoryForSpeed || $reuse;

# set the 'missing submenu function'
print qq(+ MissingSubmenuFunction FuncFvwmMenuDirectory\n) unless $reuse;

# add a new title (item and separator, or real Title if no action)
my $titleAct = $commT; $titleAct =~ s/%d/$dir/g;
if ($title ne "") {
	if ($titleAct eq "") {
		print qq(+ "$iconTStr$title" Title\n);
	} else {
		print qq(+ "$iconTStr$title" $titleAct\n+ "" Nop\n);
	}
}

# add special dirs at the top if needed
print qq($specialDirLines+ "" Nop\n) if $specialDirPos > 0;

# add directory contents
foreach (@files) {
	next if $_ eq '.' or $_ eq '..';
	my $filePath = "$dir/$_";
	$filePath =~ s|/+|/|g;
	if (-d) {
		# it's a directory
		print &evalFolderLine($_, $filePath);
	} else {
		# something else, apply editor to it or run itself
		my $itemStr = $itemF_eval? &evalItem($_, $filePath): $_;
		$itemStr = &escapeItemName($itemStr);
		my $isApp = -x && -f;
		my $iconStr = $isApp && $iconAStr? $iconAStr: $iconFStr;
		my $fileAct = $isApp? $commA: $commF;
		$fileAct =~ s/%f/&escapeFileName($filePath)/ge;
		print qq(+ "$iconStr$itemStr" $fileAct\n);
	}
}

# add special dirs at the bottom if needed
print qq(+ "" Nop\n$specialDirLines) if $specialDirPos < 0;

# add style:
if ($changeMenuStyle ne "") {
	print qq(ChangeMenuStyle "$changeMenuStyle" "$menuName"\n);
}
exit(0);

# ---------------------------------------------------------------------------

sub escapeFvwmName ($) {
	my $name = shift;
	$name =~ s/\\/\\\\/g;
	$name =~ s/"/\\"/g;
	$name =~ s/\$/\$\$/g;
	$name;
}

sub escapeMenuName ($) {
	my $name = escapeFvwmName(shift());
	# fvwm is really inconsistent here
	$name =~ s/\^/^^/g;
	$name =~ s/@/@@/g;
	$name;
}

sub escapeItemName ($) {
	my $name = escapeFvwmName(shift());
	$name =~ s/%/%%/g;
	$name =~ s/&/&&/g;
	$name =~ s/\*/**/g;
	$name =~ s/\n/ /g;
	$name;
}

sub escapeFileName ($) {
	my $name = shift;
	$name =~ s/\\/\\\\/g;
	$name =~ s/"/\\"/g;
	$name =~ s/\$/\\\$\$/g;
	$name =~ s/\n/\\\n/g;
	$name;
}

sub evalFolderLine ($$) {
	my ($_name, $dir) = @_;
	my $itemStr = $dir && $itemF_eval? &evalItem($_name, $dir): $_name;
	$itemStr = escapeItemName($itemStr);
	my $act = !$dir || $checkSubdirs && !-x $dir? "Nop": !$reuse?
		qq(Popup ") . escapeFvwmName($dir) . qq("$submenuPos):
		qq(PipeRead 'echo ") . escapeFileName($dir) . qq(" >$dirFile; )
		. qq(echo Menu ") . escapeFvwmName($name) . qq(" WarpTitle');
	return qq(+ "$iconDStr$itemStr" $act\n);
}

sub evalItem ($$) {
	my ($name, $file) = @_;
	return $name unless $itemF_eval;

	my $itemStr = "$itemF";
	if ($itemF_name) {
		&expandWidthSpecifier(\$itemStr, 'n', $name);
		&expandWidthSpecifier(\$itemStr, 'N', $file);
	}
	return $itemStr unless $itemF_stat;

	# / $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
	# \ $size, $atime, $mtime, $ctime, $blksize, $blocks
	my ($misc1, $misc2, $mode, $misc3, $misc4, $misc5, $misc6, $size,
		$misc7, $time) = stat($file);
	if ($itemF_date) {
		eval 'use POSIX' unless defined $POSIX::VERSION;
		my @time = localtime($time);
		my $date1 = strftime("%Y-%m-%d %H:%M:%S", @time);
		my $date2 = strftime("%Y-%m-%d", @time);
		$itemStr =~ s/%d/$date1/g;
		$itemStr =~ s/%D/$date2/g;
	}
	if ($itemF_size) {
		&expandWidthSpecifier(\$itemStr, 's', $size);
	}
	if ($itemF_type) {
		my $type;
#		$type = 2 if ($mode & 0100000);  # regular
#		$type = 4 if ($mode & 0040000);  # directory
#		$type = 0 if ($mode & 0140000);  # socket
#		$type = 1 if ($mode & 0120000);  # symlink
#		$type = 3 if ($mode & 0060000);  # block
#		$type = 5 if ($mode & 0020000);  # char-dev
#		$type = 6 if ($mode & 0010000);  # fifo
		$type = -p _? 6: -c _? 5: -b _? 3: -l $file? 1:
			-S _? 0: -d _? 4: 2;
		$itemStr =~ s/%t/$type1[$type]/g;
		$itemStr =~ s/%T/$type2[$type]/g;
	}
	return $itemStr;
}

# Substitutes all %N1*N2x in $name by properly stripped and justified $value.
sub expandWidthSpecifier (\$$$) {
	my ($name, $char, $value) = @_;
	$$name =~ s/%(-?\d+)?(\*(-?)(\d+))?$char/
		my $value = !$2 || $4 <= 3 || $4 > length($value)? $value: $3?
			"..." . substr($value, -$4 + 3, $4 - 3):
			substr($value, 0, $4 - 3) . "...";
		$1? sprintf("%$1s", $value): $value;
	/ge;
}

sub showHelp {
	print "A perl script that builds directory listing for fvwm.\n\n";
	print "Usage: $0 [OPTIONS]\n";
	print "Options:\n";
	print "\t--help             show this help and exit\n";
	print "\t--version          show the version and exit\n";
	print "\t--name=NAME        menu name,  default is '$name'\n";
	print "\t--title=NAME       menu title, default is '$title'\n";
	print "\t--item=NAME        menu item format, default is '$itemF'\n";
	print "\t--icon-title=XPM   menu title icon, default is none\n";
	print "\t--icon-dir=XPM     menu dir   icon, default is none\n";
	print "\t--icon-file=XPM    menu file  icon, default is none\n";
	print "\t--icon-app=XPM     menu +x    icon, default is none\n";
	print "\t--wm-icons         define icon names to use with wm-icons\n";
	print "\t--dir=NAME         starting dir, default is '$dir'\n";
	print "\t--order=NUM        NUM (-6 .. 6), default is 5\n";
	print "\t\t1 - do not sort,  2 - dirs first, 3 - files first\n";
	print "\t\t4 - sort by name, 5 - dirs first, 6 - files first\n";
	print "\t\tNegative number represents reverse order.\n";
	print "\t--all              show hidden files, default is no\n";
	print "\t--links            follow linked dirs, default is no\n";
	print "\t--xterm=CMD        xterm call, default is '$xterm'\n";
	print "\t--exec-title=CMD   title exec command, default is '$execT'\n";
	print "\t--exec-file=CMD    file exec command, default is '$execF'\n";
	print "\t--exec-app[=CMD]   +x files exec command, default is '-'\n";
	print "\t--command-title=CMD title fvwm command, default is '-'\n";
	print "\t--command-file=CMD file fvwm command, default is '-'\n";
	print "\t--command-app=CMD  +x files fvwm command, default is '-'\n";
	print "\t--reuse            no popups, reuse the same menu (no)\n";
	print "\t--check-subdirs    check subdir for +x permission (no)\n";
	print "\t--special-dirs[=X] include .. and ~ directories (no)\n";
	print "\t--memory-for-speed use speed optimization (no)\n";
	print "\t--menu-style=NAME  assign specified MenuStyle name to menus\n";
	print "Short options are ok if not ambiguous: -a, -icon-f.\n";
	exit 0;
}

sub showVersion {
	print "$version\n";
	exit 0;
}

sub wrongUsage {
	print STDERR "Try '$0 --help' for more information.\n";
	exit -1;
}

__END__

# ---------------------------------------------------------------------------

=head1 NAME

fvwm-menu-directory - builds a directory browsing menu for FVWM

=head1 SYNOPSIS

B<fvwm-menu-directory>
[ B<--help>|B<-h>|B<-?> ]
[ B<--version>|B<-V> ]
[ B<--name>|B<-na> NAME ]
[ B<--title>|B<-t> NAME ]
[ B<--item>|B<-it> NAME ]
[ B<--icon-title>|B<-icon-t> XPM ]
[ B<--icon-dir>|B<-icon-d> XPM ]
[ B<--icon-file>|B<-icon-f> XPM ]
[ B<--icon-app>|B<-icon-a> XPM ]
[ B<--wm-icons> ]
[ B<--dir>|B<-d> NAME ]
[ B<--order>|B<-o> NUM ]
[ B<--[no]all>|B<-a> ]
[ B<--[no]links>|B<-l> ]
[ B<--xterm>|B<-x> CMD ]
[ B<--exec-title>|B<-exec-t> CMD ]
[ B<--exec-file>|B<-exec-f> CMD ]
[ B<--exec-app>|B<-exec-a> [CMD] ]
[ B<--command-title>|B<-command-t> CMD ]
[ B<--command-file>|B<-command-f> CMD ]
[ B<--command-app>|B<-command-a> CMD ]
[ B<--[no]reuse>|B<-r> ]
[ B<--[no]check-subdirs>|B<-ch> ]
[ B<--special-dirs>|B<-s> [VALUE] ]
[ B<--[no]memory-for-speed>|B<-mem> ]
[ B<--menu-style>|B<-men> NAME ]

=head1 DESCRIPTION

A perl script which provides an output to read in with PipeRead to build an
fvwm menu containing a directory listing. Almost everything can be configured.

=head1 HINTS

The title item with its own attached action is usually added to the menu.
This may be used to define an action for the directory for which the menu is
built, such as starting a terminal in this directory (the default).
However, this may annoy some users. To disable the title action use
B<--command-title> "", to remove the title complitely use B<--title> "".

=head1 OPTIONS

=over 4

=item B<--help>

show the usage and exit

=item B<--version>

show version and exit

=item B<--name> name

menu name, used only with --reuse, default is MenuBrowser

=item B<--title> title

menu title format, default is '%*-40p' - last 40 characters
of the current full path.
TAB can be specified as '\t', but in .fvwm2rc you should specify a double
backslash or a real TAB.

Format specifiers:
  %d - the current directory name
  %p - the current directory full path

These specifiers can receive an optional integer size, positive for right
adjusted string or negative for left adjusted, example: %8x; and optional
*num or *-num, which means to leave only the first or last (if minus) num of
chars, the num must be greater than 3, since the striped part is replaced
with "...", example: %*30x. Both can be combined: %-10*-20x, this instructs to
get only the 20 last characters, but if the length is less then 10 - to fill
with up to 10 spaces on the right.

=item B<--item> format

menu item format, default is '%n'. TAB and width modifiers
for %n, %N and %s can be specified as described in B<--title> above.
Note, specifying a non default format slows the script.

Format specifiers:

  %n - file/dir name (without the path)
  %N - file/dir name (full with the path)
  %d - file/dir date (yyyy-mm-dd HH:MM:SS)
  %D - file/dir date (yyyy-mm-dd)
  %s - file/dir size (in bytes)
  %t - file/dir type (File|Dir |Link|Sock|Blck|Char|Pipe)
  %T - file/dir type (F|D|L|S|B|C|P)

Example: --title '%*-40p\tDate, Type\tSize' --item '%*40n\t%d %t\t%s'

=item B<--icon-title> icon

menu title icon, default is none

=item B<--icon-dir> icon

menu dir icon, default is none

=item B<--icon-file> icon

menu file icon, default is none

=item B<--icon-app> icon

menu application icon, default is none

=item B<--wm-icons>

define icon names suitable for use with wm-icons package.
Currently this is equivalent to: --icon-title menu/folder-open.xpm --icon-item
menu/file.xpm --icon-dir menu/folder.xpm --icon-app menu/utility.xpm.

=item B<--dir> dir

starting dir, default is ${HOME-.}

=item B<--order> number

in the range (-6 .. 6), default is 5:

  1 - do not sort,  2 - dirs first, 3 - files first
  4 - sort by name, 5 - dirs first, 6 - files first
  Negative number represents reverse order.

=item B<--[no]all>

show hidden files, like in 'ls -A', default is --noall

=item B<--[no]links>

follow linked directories, default is --nolinks

=item B<--xterm> command

X terminal call, default is 'xterm -e'

=item B<--exec-title> command

an fvwm Exec command on directory title (usually the
shell), default is ${SHELL-/bin/sh}.
'-' means no Exec command, i.e. Nop.
If the command is not started with '^' X terminal call is prepended.
The command is started in the currently browsed directory.

=item B<--exec-file> command

an fvwm Exec command on regular files,
default is ${EDITOR-vi}.
'-' means no Exec command, i.e. Nop.
If the command is not started with '^' X terminal call is prepended.
The actual file name is appended to the command.

=item B<--exec-app> [command]

an fvwm Exec command on +x files, default is '-',
which means the same command as on regular files. If no command is given,
it is assumed to be empty - simply run the +x file.
If the command is not started with '^' X terminal call is prepended.
The actual file name is appended to the command.

=item B<--command-title> command

an fvwm command to execute on title.
If this option is not given (or command is '-'), the C<--exec-title>
is used instead.
In the command, %d is substituted with the full directory path.

In fact, I<--exec-title=tcsh> is equivalent
to I<--command-title='Exec cd "%d"; xterm -e tcsh'>

The empty value disables the title action.

=item B<--command-file> command

an fvwm command to execute on regular files.
If this option is not given (or command is '-'), the C<--exec-file>
is used instead.
In the command, %f is substituted with the full file path.

In fact, --exec-file=vi is equivalent
to --command-file='Exec xterm -e vi "%f"'

=item B<--command-app> command

an fvwm command to execute on +x files.
If this option is not given (or command is '-'), the C<--command-app>
is used instead.
In the command, %f is substituted with the full file path.

In fact, --exec-app=^exec is equivalent
to --command-app='Exec exec "%f"'

=item B<--[no]reuse>

no pop-up menus, reuse the same menu, default is --noreuse.
When you specify this option the Menu action is used, not Popup. Also,
the --name parameter is not ignored, and --dir parameter is ignored
if there is ~/.fvwm/.fvwm-menu-directory.dir file. This file is only created
or used with this option specified, it is the only solution for the current
fvwm menu state.

=item B<--[no]check-subdirs>

check all subdirs for having execute (+x) permission
and replace "Popup"/"Menu" command with "Nop" for these without permissions.
This has a visual effect of disabling popup triangle in the subdirectory item.
The default is --nocheck-subdirs, because: 1) enabling this slows a bit the
script, 2) with this option enabled, if no icons used and no dir/file separate
sorting used there is no way to know that the item is directory and not file.

=item B<--special-dirs> value

add .. or ~ or / special directories according to
given optional value. Without with option these directories are not added.
Default value if not specified is "1,2". The value is comma separated ordered
special directory indexes, where 1 is parent directory, 2 is home directory,
3 is root directory. If minus is prepended to the value, special directories
are added at the bottom of menu instead of top. Value "0" or any bad value
is equivalent to non-specifying this option at all.

=item B<--[no]memory-for-speed>

use speed optimization, i.e. use previously
created directory menus without destroying it when closed, default is
--nomemory-for-speed

    Warning: speed optimization takes up a lot of memory
    that is never free'd again while fvwm is running.

=item B<--menu-style> name

assign MenuStyle name to the menus

=back

Option parameters can be specified either using '=' or in the next argument.
Short options are ok if not ambiguous: C<-a>, C<-x>, C<-icon-f>; but be
careful with short options, what is now unambiguous, can become ambiguous
in the next versions.

=head1 USAGE

Put this into your fvwm configuration file to invoke the script:

  AddToFunc FuncFvwmMenuDirectory
  + I PipeRead "fvwm-menu-directory -d '$0'"

More complex example:

  # AddToFunc FuncFvwmMenuDirectory
  # + I PipeRead "fvwm-menu-directory -d '$0' -x 'Eterm -g 80x40 -e' \\
    -a -l -o 6 --exec-app --exec-title 'tcsh -l' --exec-file 'vim -R' \\
    -t 'Go to: %d' --wm-icons"

And put this in the menu from which you want to pop-up the directory menus:

  AddToMenu SomeMenu MissingSubmenuFunction FuncFvwmMenuDirectory
  + "Home Directory"  Popup $[HOME]
  + "Httpd Directory" Popup /home/httpd

Note: please use absolute path names.

It is a good idea to set the menu pop-up delay to something positive
and enable busy cursor

  MenuStyle * PopupDelayed, PopupDelay 200
  BusyCursor DynamicMenu True

in your configuration file when using this script for better results.

Another interesting usage (C<--reuse> or C<-r> is mandatary for this):

  AddToMenu Browser
  + DynamicPopupAction PipeRead \\
    "fvwm-menu-directory -r -na Browser -d / -s"
  AddToMenu SomeMenu "My Browser" Menu Browser

Here the C<--dir> parameter (starting directory) is ignored if there is
~/.fvwm/.fvwm-menu-directory.dir file, which you can delete.

=head1 AUTHORS

Inspired  on 1999-06-07 by Dominik Vogt     <domivogt@fvwm.org>.

Rewritten on 1999-08-05 by Mikhael Goikhman <migo@homemail.com>.

=head1 COPYING

The script is distributed by the same terms as fvwm itself.
See GNU General Public License for details.

=head1 BUGS

Report bugs to fvwm-bug@fvwm.org.

=cut

# ***************************************************************************
