Subject: fvwm-menu-directory patch

From: calmar <[email-masked]>
Date: Fri, 27 Feb 2004 11:33:18 +0100

Hi,
I'm wondering if there is any interest in a little patch at the
fvwm-menu-directory.

An additional command line what should define with what kind of a
program files with specific endings should get opened.

the additional command line option would look like this:

exec-gen="xv=jpg|jpeg,mplayer=mov|mpg|mpeg,xmms=mp3"

that would mean, xv should open all endings: jpg, jpeg, 
                 mplayer should open endings: mov, mpg, mpeg and
                 xmms should be used to open mp3 files.

for personal use this would be already enough for me actually,
but when this would be interesting to enhance ( icons ), i could
do it as well.

Actually a quick hack with special markings to see where i hacked
around. I'm not really a perl programmer, but I hope it's all ok anyway.

--- /usr/local/bin/fvwm-menu-directory2	2004-02-15 19:45:48.000000000 +0100
+++ /usr/local/bin/fvwm-menu-directory	2004-02-27 11:26:25.000000000 +0100
@@ -26,6 +26,10 @@
 my $execT = $ENV{'SHELL'} || '/bin/sh';
 my $execF = $ENV{'EDITOR'} || "vi";  # the command to execute on plain files
 my $execA = undef;
+### calmar hacked here ###
+my $extGen = "xv=jpg|jpeg,mplayer=mov|mpg|mpeg,xmms=mp3";
+my $commGen = undef;
+#######################
 my $commT = undef;
 my $commF = undef;
 my $commA = undef;
@@ -61,6 +65,10 @@
 	"exec-title=s" => \$execT,
 	"exec-file=s"  => \$execF,
 	"exec-app:s"   => \$execA,
+### calmar hacked here ###
+        "exec-gen=s"       => \$extGen,
+#######################
+
 	"command-title=s" => \$commT,
 	"command-file=s"  => \$commF,
 	"command-app=s"   => \$commA,
@@ -140,7 +148,6 @@
 $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 "";
@@ -207,6 +214,29 @@
 # add special dirs at the top if needed
 print qq($specialDirLines+ "" Nop\n) if $specialDirPos > 0;
 
+### calmar hacked here ###
+# puts strings like this: gimp=jpg|jpeg|png,emacs=c|cc|h 
+# into an hash: --> may uncomment foreach loop below to see output
+	   
+	     my %extHash;
+	     my $prog;
+	     my $ext;
+	     my $rest;
+
+	     foreach (split (/,/,$extGen)) {
+		 ($prog, $rest) = split ( /=/, $_ , 2);
+		 foreach $ext ( split (/\|/, $rest)) { 
+		     $extHash{$ext} =  $prog ;
+		     print qq($ext -> $prog\n);
+		 }
+	     }
+
+#	     foreach $ext ( keys %extHash ) {
+#		 print "$ext: $extHash{$ext}\n";
+#	     }
+
+######################
+
 # add directory contents
 foreach (@files) {
 	next if $_ eq '.' or $_ eq '..';
@@ -222,6 +252,15 @@
 		my $isApp = -x && -f;
 		my $iconStr = $isApp && $iconAStr? $iconAStr: $iconFStr;
 		my $fileAct = $isApp? $commA: $commF;
+### calmar hacked here ### 
+# overwrite $fileAct when the file ending and the program are in @extHash
+	        my $fileEnd = lc(); #lowercase $_ 
+                $fileEnd =~ s|.*\.||; # get ending
+		if  ($extHash{$fileEnd}) {
+		    $commGen =  $extHash{$fileEnd};
+		    $fileAct = qq(Exec $commGen "%f");
+		}
+#######################
 		$fileAct =~ s/%f/&escapeFileName($filePath)/ge;
 		print qq(+ "$iconStr$itemStr" $fileAct\n);
 	}

Greetings
marco candrian

-- 
  calmar 
           (o_         GNU/Linux is GREAT      
           //\                 
           V_/_        http://www.calmar.ws

---

From: Mikhael Goikhman <[email-masked]>
Date: Fri, 27 Feb 2004 11:31:01 +0000

> around. I'm not really a perl programmer, but I hope it's all ok anyway.

I didn't check the patch yet, but I probably prefer this syntax:

  --exec-mime="xv -nolimits; jpg|jpeg, mplayer -fs %n; mov|mpg|mpeg"

Or better yet instead of your option, add this one:

  --use-mailcap

that just parses and uses existing ~/.mailcap and ~/.mime.types.

P.S. I would like you to keep the strict indentation (one TAB only, never
spaces) in the code, otherwise I will need to change it manually.

Regards,
Mikhael.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: calmar <[email-masked]>
Date: Fri, 27 Feb 2004 17:47:10 +0100

> I'm wondering if there is any interest in a little patch at the
So I added `icon support'.
those new options would be
,----
| --exec-gen=program1:ext1/ext2/ext3+program2:ext1:ext2 ...
`----

then to those programs it's possible to assign a icon
,----
| --icon-gen=program1:icon.xpm+program2:icon2.xmp
`----

so here's the new patch (the hold had anyway a fault, because I
forgot to comment out a debug print .. line. Even so it worked
anyway.

Anyway,
Best Greetings
marco candrian

--- /usr/local/bin/fvwm-menu-directory2	2004-02-15 19:45:48.000000000 +0100
+++ fvwm-menu-directory	2004-02-27 17:38:32.000000000 +0100
@@ -20,12 +20,18 @@
 my $iconD = "";
 my $iconF = "";
 my $iconA = "";
+### calmar hacked here ###
+my $iconGen = "xv:mini.xv.xpm+mplayer:mini.tetris.xpm"; # prog1:pixmap+prog2:pixmap2
+#######################
 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;
+### calmar hacked here ###
+my $extGen = "xv:jpg/jpeg+mplayer:mov/mpg/mpeg+xmms:mp3/wav"; # prog1:ext1/ext2/ext3+prog2:ext1/...
+#######################
 my $commT = undef;
 my $commF = undef;
 my $commA = undef;
@@ -53,6 +59,9 @@
 	"icon-dir=s"   => \$iconD,
 	"icon-file=s"  => \$iconF,
 	"icon-app=s"   => \$iconA,
+### calmar hacked here ###
+        "icon-gen=s"       => \$iconGen,
+#######################
 	"dir=s"        => \$dir,
 	"order=i"      => \$order,
 	"all!"         => \$all,
@@ -61,6 +70,9 @@
 	"exec-title=s" => \$execT,
 	"exec-file=s"  => \$execF,
 	"exec-app:s"   => \$execA,
+### calmar hacked here ###
+        "exec-gen=s"       => \$extGen,
+#######################
 	"command-title=s" => \$commT,
 	"command-file=s"  => \$commF,
 	"command-app=s"   => \$commA,
@@ -140,7 +152,6 @@
 $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 "";
@@ -195,6 +206,7 @@
 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 "") {
@@ -207,6 +219,39 @@
 # add special dirs at the top if needed
 print qq($specialDirLines+ "" Nop\n) if $specialDirPos > 0;
 
+### calmar hacked here ###
+# puts strings like this: xv:jpg/jpeg+mplayer:mov/mpg/mpeg+xmms:mp3 
+# into an hash: --> may uncomment foreach loops below to see output
+	   
+	     my %extHash;
+	     my $prog;
+	     my $ext;
+	     my $rest;
+
+	     foreach (split (/\+/,$extGen)) {
+		 ($prog, $rest) = split ( /:/, $_ , 2);
+		 foreach $ext ( split (m|\/|, $rest)) { 
+		     $extHash{$ext} =  $prog ;
+		 }
+	     }
+
+# do about the same with the $iconGen string variable.
+
+	     my %iconHash;
+	     foreach (split (/\+/,$iconGen)) {
+		 ($prog, $rest) = split ( /:/, $_ , 2);
+		  $iconHash{$prog} =  $rest ;
+	     }
+
+
+#	     foreach $ext ( keys %extHash ) {
+#		 print "ext  $ext:  $extHash{$ext}\n";
+#	     }
+#	     foreach $ext ( keys %iconHash ) {
+#		 print "prog $ext:  $iconHash{$ext}\n";
+#	     }	 	     
+######################
+
 # add directory contents
 foreach (@files) {
 	next if $_ eq '.' or $_ eq '..';
@@ -222,6 +267,18 @@
 		my $isApp = -x && -f;
 		my $iconStr = $isApp && $iconAStr? $iconAStr: $iconFStr;
 		my $fileAct = $isApp? $commA: $commF;
+### calmar hacked here ### 
+# overwrite $fileAct when the file ending and the program are in @extHash
+	        my $fileEnd = lc(); #lowercase $_ 
+                $fileEnd =~ s|.*\.||; # get ending
+		if  ($extHash{$fileEnd}) {
+		    $fileAct = qq(Exec $extHash{$fileEnd} "%f");
+		}
+# when there is a file ending assigned to a program, check for icon for program
+	        if ($iconHash{$extHash{$fileEnd}}) {
+		    $iconStr = qq(%$iconHash{$extHash{$fileEnd}}%);
+		}
+#######################
 		$fileAct =~ s/%f/&escapeFileName($filePath)/ge;
 		print qq(+ "$iconStr$itemStr" $fileAct\n);
 	}

---

From: calmar <[email-masked]>
Date: Fri, 27 Feb 2004 18:12:32 +0100

> that just parses and uses existing ~/.mailcap and ~/.mime.types.

Sorry, I didn't see your post. Anyway I'm glad you have some good
ideas how to make this command-line option. Because I didn't like
it myself.

Then I will try to make this then

> spaces) in the code, otherwise I will need to change it manually.
I will try to set this up too.

Greetings
marco