File: fvwm_make_browse_menu.sh

package info (click to toggle)
fvwm 1%3A2.6.7-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 16,752 kB
  • ctags: 14,275
  • sloc: ansic: 145,770; xml: 17,086; perl: 7,302; sh: 4,885; makefile: 1,055; yacc: 688; python: 629; lex: 188; sed: 11
file content (89 lines) | stat: -rwxr-xr-x 2,366 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
#
###
#  This script demonstrates the fvwm menu DynamicPopupAction functionality.
#  You can use a more configurable fvwm-menu-directory instead.
#  The line below almost exactly simulates this script:
#    fvwm-menu-directory --reuse --links --order 4 --name <menu name> \
#      --exec-file vi --exec-title - --special-dirs
###
#
#  Modification History
#
#  Created on 05/06/99 by Dominik Vogt (domivogt):
#
#  provides output to read in with PipeRead to build a menu
#  containing a directory listing.
#
#  You should put these lines into your fvwm configuration file to invoke
#  this script:
#
#  AddToMenu <menu name>
#  + DynamicPopupAction Piperead 'fvwm_make_browse_menu.sh <menu name>'

#
# configuration section
#

# the file containing the desired directory name
DIRFILE="$HOME/.fvwm_browse_menu_cwd"

# you may use the absolute path here if you have an alias like ls="ls -F"
LS=ls
SED=sed

# the name of our menu
MENU=`echo "$1" | $SED -e s:\"::g`

# the command to execute on plain files
ACTION=vi

# the terminal program to invoke
TERMINAL="xterm -e"

#
# you may customize this script below here.
#

# create a file containing the current working directory
if [ ! -f "$DIRFILE" ] ; then
    echo "$HOME" > "$DIRFILE"
fi

# get desired directory
DIR="`cat "$DIRFILE"`"
if [ ! -d "$DIR" ] ; then
    DIR="$HOME"
fi

# dump all menu items
echo DestroyMenu recreate \""$MENU"\"

# add a new title
echo AddToMenu \""$MENU"\" \"`cat "$DIRFILE"`\" Title

# add '..' entry
cd "$DIR"/..
echo AddToMenu \""$MENU"\" \"..\" PipeRead \'echo \""`/bin/pwd`"\" \> "$DIRFILE" ';' echo Menu \\\""$MENU"\\\" WarpTitle\'

# add separator
echo AddToMenu \""$MENU"\" \"\" Nop

# add $HOME entry
echo AddToMenu \""$MENU"\" \"~\" PipeRead \'echo \""$HOME"\" \> "$DIRFILE" ';' echo Menu \\\""$MENU"\\\" WarpTitle\'

# add separator
echo AddToMenu \""$MENU"\" \"\" Nop

# add directory contents
for i in `"$LS" "$DIR"` ; do
    if [ -d "$DIR/$i" ] ; then
        # it's a directory
        cd "$DIR/$i"
        # put new path in $DIRFILE and invoke the menu again
        echo AddToMenu \""$MENU"\" \""$i/"\" PipeRead \'echo \"`echo $DIR/$i|$SED -e s://:/:g`\" \> "$DIRFILE" ';' echo Menu \\\""$MENU"\\\" WarpTitle\'
    else
        # something else, apply $ACTION to it
        echo AddToMenu \""$MENU"\" \""$i"\" Exec $TERMINAL $ACTION \""$DIR/$i"\"
    fi
done