Lots of cleanups to fvwm-menu-desktop
[fvwm.git] / utils / fvwm_make_browse_menu.sh
blob2797321d8810268ec1e93af11ae2e4e2312e0c6e
1 #!/bin/sh
3 ###
4 # This script demonstrates the fvwm menu DynamicPopupAction functionality.
5 # You can use a more configurable fvwm-menu-directory instead.
6 # The line below almost exactly simulates this script:
7 # fvwm-menu-directory --reuse --links --order 4 --name <menu name> \
8 # --exec-file vi --exec-title - --special-dirs
9 ###
11 # Modification History
13 # Created on 05/06/99 by Dominik Vogt (domivogt):
15 # provides output to read in with PipeRead to build a menu
16 # containing a directory listing.
18 # You should put these lines into your fvwm configuration file to invoke
19 # this script:
21 # AddToMenu <menu name>
22 # + DynamicPopupAction Piperead 'fvwm_make_browse_menu.sh <menu name>'
25 # configuration section
28 # the file containing the desired directory name
29 DIRFILE="$HOME/.fvwm_browse_menu_cwd"
31 # you may use the absolute path here if you have an alias like ls="ls -F"
32 LS=ls
33 SED=sed
35 # the name of our menu
36 MENU=`echo "$1" | $SED -e s:\"::g`
38 # the command to execute on plain files
39 ACTION=vi
41 # the terminal program to invoke
42 TERMINAL="xterm -e"
45 # you may customize this script below here.
48 # create a file containing the current working directory
49 if [ ! -f "$DIRFILE" ] ; then
50 echo "$HOME" > "$DIRFILE"
53 # get desired directory
54 DIR="`cat "$DIRFILE"`"
55 if [ ! -d "$DIR" ] ; then
56 DIR="$HOME"
59 # dump all menu items
60 echo DestroyMenu recreate \""$MENU"\"
62 # add a new title
63 echo AddToMenu \""$MENU"\" \"`cat "$DIRFILE"`\" Title
65 # add '..' entry
66 cd "$DIR"/..
67 echo AddToMenu \""$MENU"\" \"..\" PipeRead \'echo \""`/bin/pwd`"\" \> "$DIRFILE" ';' echo Menu \\\""$MENU"\\\" WarpTitle\'
69 # add separator
70 echo AddToMenu \""$MENU"\" \"\" Nop
72 # add $HOME entry
73 echo AddToMenu \""$MENU"\" \"~\" PipeRead \'echo \""$HOME"\" \> "$DIRFILE" ';' echo Menu \\\""$MENU"\\\" WarpTitle\'
75 # add separator
76 echo AddToMenu \""$MENU"\" \"\" Nop
78 # add directory contents
79 for i in `"$LS" "$DIR"` ; do
80 if [ -d "$DIR/$i" ] ; then
81 # it's a directory
82 cd "$DIR/$i"
83 # put new path in $DIRFILE and invoke the menu again
84 echo AddToMenu \""$MENU"\" \""$i/"\" PipeRead \'echo \"`echo $DIR/$i|$SED -e s://:/:g`\" \> "$DIRFILE" ';' echo Menu \\\""$MENU"\\\" WarpTitle\'
85 else
86 # something else, apply $ACTION to it
87 echo AddToMenu \""$MENU"\" \""$i"\" Exec $TERMINAL $ACTION \""$DIR/$i"\"
89 done