Merge branch '3867_mcedit_c_macro'
[midnight-commander.git] / misc / mc.menu.in
blob8488a875009c8a512ebdf6568ad4c91a1d313dba
1 shell_patterns=0
3 ##############################################################################
4 #   %%  The % character
5 #   %f  The current file (if non-local vfs, file will be copied locally and
6 #                         %f will be full path to it)
7 #   %p  The current file
8 #   %d  The current working directory
9 #   %s  "Selected files"; the tagged files if any, otherwise the current file
10 #   %t  Tagged files
11 #   %u  Tagged files (and they are untagged on return from expand_format)
12 #   %view Runs the commands and pipes standard output to the view command
13 #   If %view is immediately followed by '{', recognize keywords
14 #   ascii, hex, nroff and unform
16 #   If the format letter is in uppercase, it refers to the other panel
18 #   With a number followed the % character you can turn quoting on (default)
19 #   and off. For example:
20 #   %f    quote expanded macro
21 #   %1f   ditto
22 #   %0f   don't quote expanded macro
23 ##############################################################################
25 + ! t t
26 @       Do something on the current file
27         CMD=%{Enter command}
28         $CMD %f
30 + t t
31 @       Do something on the tagged files
32         CMD=%{Enter command}
33         for i in %t ; do
34             $CMD "$i"
35         done
37 0       Edit a bug report and send it to root
38         I=`mktemp "${MC_TMPDIR:-/tmp}/mail.XXXXXX"` || exit 1
39         ${EDITOR-vi} "$I"
40         test -r "$I" && mail root < "$I"
41         rm -f "$I"
43 =+ f \.1$ | f \.3$ | f \.4$ | f \.5$ | f \.6$ | f \.7$ | f \.8$ | f \.man$ & t r
44 1       Display the file with roff -man
45         %view{ascii,nroff} roff @MAN_FLAGS@ @MANDOC@ %f
47 2       Call the info hypertext browser
48         info
50 = t d
51 3       Compress the current subdirectory (tar.gz)
52         Pwd=`basename %d /`
53         echo -n "Name of the compressed file (without extension) [$Pwd]: "
54         read tar
55         [ "$tar"x = x ] && tar="$Pwd"
56         cd .. && \
57         tar cf - "$Pwd" | gzip -f9 > "$tar.tar.gz" && \
58         echo "../$tar.tar.gz created."
60 4       Compress the current subdirectory (tar.bz2)
61         Pwd=`basename %d /`
62         echo -n "Name of the compressed file (without extension) [$Pwd]: "
63         read tar
64         [ "$tar"x = x ] && tar="$Pwd"
65         cd .. && \
66         tar cf - "$Pwd" | bzip2 -f > "$tar.tar.bz2" && \
67         echo "../$tar.tar.bz2 created."
69 5       Compress the current subdirectory (tar.7z)
70         Pwd=`basename %d /`
71         echo -n "Name of the compressed file (without extension) [$Pwd]: "
72         read tar
73         [ "$tar"x = x ] && tar="$Pwd"
74         cd .. && \
75         tar cf - "$Pwd" | 7za a -si "$tar.tar.7z" && \
76         echo "../$tar.tar.7z created."
78 6       Compress the current subdirectory (tar.xz)
79         Pwd=`basename %d /`
80         echo -n "Name of the compressed file (without extension) [$Pwd]: "
81         read tar
82         [ "$tar"x = x ] && tar="$Pwd"
83         cd .. && \
84         tar cf - "$Pwd" | xz -f > "$tar.tar.xz" && \
85         echo "../$tar.tar.xz created."
87 = f \.c$ & t r
88 + f \.c$ & t r & ! t t
89 c       Compile and link current .c file
90         make "`basename %f .c`" 2>/dev/null || cc -O -o "`basename %f .c`" %f
92 + t r & ! t t
93 a       Append file to opposite
94         cat %f >> %D/%f
96 + t t
97 A       Append files to opposite files
98         for i in %t ; do
99             cat "$i" >> %D/"$i"
100         done
102 + t r & ! t t
103 d       Delete file if a copy exists in the other directory.
104         if [ %d = %D ]; then
105             echo "The two directories must be different."
106             exit 1
107         fi
108         if [ -f %D/%f ]; then        # if two of them, then
109             if cmp -s %D/%f %f; then
110                 rm %f && echo %f": DELETED."
111             else
112                 echo %f" and "%D/%f" differ: NOT deleted."
113                 echo -n "Press RETURN "
114                 read key
115             fi
116         else
117             echo %f": No copy in "%D/%f": NOT deleted."
118         fi
120 + t t
121 D       Delete tagged files if a copy exists in the other directory.
122         if [ %d = %D ]; then
123             echo "The two directores must be different."
124             exit 1
125         fi
126         for i in %t ; do
127             if [ -f %D/"$i" ]; then
128                 SUM1=`sum "$i"`
129                 SUM2=`sum %D/"$i"`
130                 if [ "$SUM1" = "$SUM2" ]; then
131                     rm "$i" && echo "${i}: DELETED."
132                 else
133                     echo "$i and "%D"/$i differ: NOT deleted."
134                 fi
135             else
136                 echo "$i has no copy in "%D": NOT deleted."
137             fi
138         done
140 m       View manual page
141         MAN=%{Enter manual name}
142         %view{ascii,nroff} MANROFFOPT='@MAN_FLAGS@' MAN_KEEP_FORMATTING=1 man -P cat "$MAN"
144 = f \.gz$ & t r
145 + ! t t
146 n       Inspect gzip'ed newsbatch file
147         dd if=%f bs=1 skip=12 | zcat | ${PAGER-more}
148         # assuming the cunbatch header is 12 bytes long.
150 = t r &
151 + ! t t
152 h       Strip headers from current newsarticle
153         CHECK=`awk '{print $1 ; exit}' %f` 2>/dev/null
154         case "$CHECK" in
155             Newsgroups:|Path:)
156                 I=`mktemp "${MC_TMPDIR:-/tmp}/news.XXXXXX"` || exit 1
157                 cp %f "$I" && sed '/^'"$CHECK"' /,/^$/d' "$I" > %f
158                 [ "$?" = "0" ] && rm "$I"
159                 echo %f": header removed."
160                 ;;
161             *)
162                 echo %f" is not a news article."
163                 ;;
164         esac
166 + t t
167 H       Strip headers from the marked newsarticles
168         for i in %t ; do
169             CHECK=`awk '{print $1 ; exit}' "$i"` 2>/dev/null
170             WFILE=`mktemp "${MC_TMPDIR:-/tmp}/news.XXXXXX"` || exit 1
171             case "$CHECK" in
172                 Newsgroups:|Path:)
173                     cp "$i" "$WFILE" && sed '/^'"$CHECK"' /,/^$/d' "$WFILE" > "$i"
174                     if [ "$?" = "0" ]; then
175                         rm "$WFILE"; echo "$i header removed. OK."
176                     else
177                         echo "Oops! Please check $i against $WFILE."
178                     fi
179                     ;;
180                 *)
181                     echo "$i skipped: Not a news article."
182                     ;;
183             esac
184         done
186 = t r
187 + ! t t
188 r       Copy file to remote host
189         echo -n "To which host?: "
190         read Host
191         echo -n "To which directory on $Host?: "
192         read Dir
193         rcp -p %f "${Host}:${Dir}"
195 + t t
196 R       Copy files to remote host (no error checking)
197         echo -n "Copy files to which host?: "
198         read Host
199         echo -n "To which directory on $Host? :"
200         read Dir
201         rcp -pr %u "${Host}:${Dir}"
203 = f \.tex$ & t r
204 + f \.tex$ & t r & ! t t
205 t       Run latex on file and show it with xdvi
206         latex %f && xdvi "`basename %f .tex`".dvi
208 =+ f ^part | f ^Part | f uue & t r
209 + t t
210 U       Uudecode marked news articles (needs work)
211         (
212             for i in %t ; do # strip headers
213                 FIRST=`awk '{print $1 ; exit}' "$i"`
214                 cat "$i" | sed '/^'"$FIRST"' /,/^$/d'
215             done
216         ) | sed '/^$/d' | sed -n '/^begin 6/,/^end$/p' | uudecode
217         if [ "$?" != "0" ]; then
218             echo "Cannot decode "%t"."
219         fi
220         echo "Please test the output file before deleting anything."
222 =+ f \.tar\.gz$ | f \.tar\.z$ | f \.tgz$ | f \.tpz$ | f \.tar\.lz$ | f \.tar\.lz4$ | f \.tar\.lzma$ | f \.tar\.7z$ | f \.tar\.xz$ | f \.tar\.Z$ | f \.tar\.bz2$ & t r
223 x       Extract the contents of a compressed tar file
224         unset PRG
225         case %f in
226             *.tar.7z)   PRG="7za e -so";;
227             *.tar.bz2)  PRG="bunzip2 -c";;
228             *.tar.gz|*.tar.z|*.tgz|*.tpz|*.tar.Z) PRG="gzip -dc";;
229             *.tar.lz)   PRG="lzip -dc";;
230             *.tar.lz4)  PRG="lz4 -dc";;
231             *.tar.lzma) PRG="lzma -dc";;
232             *.tar.xz)   PRG="xz -dc";;
233             *)          exit 1;;
234         esac
235         $PRG %f | tar xvf -
237 = t r
238 + ! t t
239 y       Gzip or gunzip current file
240         unset DECOMP
241         case %f in
242             *.gz|*.[zZ]) DECOMP=-d;;
243         esac
244         # Do *not* add quotes around $DECOMP!
245         gzip $DECOMP -v %f
247 + t t
248 Y       Gzip or gunzip tagged files
249         for i in %t ; do
250             unset DECOMP
251             case "$i" in
252                 *.gz|*.[zZ]) DECOMP=-d;;
253             esac
254             gzip $DECOMP -v "$i"
255         done
257 + ! t t
258 b       Bzip2 or bunzip2 current file
259         unset DECOMP
260         case %f in
261             *.bz2) DECOMP=-d;;
262         esac
263         bzip2 $DECOMP -v %f
265 + t t
266 B       Bzip2 or bunzip2 tagged files
267         for i in %t ; do
268             unset DECOMP
269             case "$i" in
270                 *.bz2) DECOMP=-d;;
271             esac
272             bzip2 $DECOMP -v "$i"
273         done
275 + f \.tar.gz$ | f \.tgz$ | f \.tpz$ | f \.tar.Z$ | f \.tar.z$ | f \.tar.bz2$ | f \.tar.F$ & t r & ! t t
276 z       Extract compressed tar file to subdirectory
277         unset D
278         set gzip -cd
279         case %f in
280             *.tar.F)   D=`basename %f .tar.F`; set freeze -dc;;
281             *.tar.Z)   D=`basename %f .tar.Z`;;
282             *.tar.bz2) D=`basename %f .tar.bz2`; set bunzip2 -c;;
283             *.tar.gz)  D=`basename %f .tar.gz`;;
284             *.tar.z)   D=`basename %f .tar.z`;;
285             *.tgz)     D=`basename %f .tgz`;;
286             *.tpz)     D=`basename %f .tpz`;;
287         esac
288         mkdir "$D"; cd "$D" && ("$1" "$2" ../%f | tar xvf -)
290 + t t
291 Z       Extract compressed tar files to subdirectories
292         for i in %t ; do
293             set gzip -dc
294             unset D
295             case "$i" in
296                 *.tar.F)   D=`basename "$i" .tar.F`; set freeze -dc;;
297                 *.tar.Z)   D=`basename "$i" .tar.Z`;;
298                 *.tar.bz2) D=`basename "$i" .tar.bz2`; set bunzip2 -c;;
299                 *.tar.gz)  D=`basename "$i" .tar.gz`;;
300                 *.tar.z)   D=`basename "$i" .tar.z`;;
301                 *.tgz)     D=`basename "$i" .tgz`;;
302                 *.tpz)     D=`basename "$i" .tpz`;;
303           esac
304           mkdir "$D"; (cd "$D" && "$1" "$2" "../$i" | tar xvf -)
305         done
307 + f \.gz$ | f \.tgz$ | f \.tpz$ | f \.Z$ | f \.z$ | f \.bz2$ & t r & ! t t
308 c       Convert gz<->bz2, tar.gz<->tar.bz2 & tgz->tar.bz2
309         unset D
310         unset EXT
311         case %f in
312             *.Z)   EXT=Z;;
313             *.bz2) EXT=bz2;;
314             *.gz)  EXT=gz;;
315             *.tgz) EXT=tgz;;
316             *.tpz) EXT=tpz;;
317             *.z)   EXT=z;;
318         esac
319         case "$EXT" in
320             bz2|Z|gz|z) D=`basename %f ."$EXT"`;;
321             tgz|tpz)    D=`basename %f ."$EXT"`.tar;;
322         esac
323         if [ "$EXT" = "bz2" ]; then
324             bunzip2 -v %f
325             gzip -f9 -v "$D"
326         else
327             gunzip -v %f
328             bzip2 -v "$D"
329         fi
331 + t t
332 C       Convert gz<->bz2, tar.gz<->tar.bz2 & tgz->tar.bz2
333         for i in %t ; do
334             unset D
335             unset EXT
336             case "$i" in
337                 *.Z)   EXT=Z;;
338                 *.bz2) EXT=bz2;;
339                 *.gz)  EXT=gz;;
340                 *.tgz) EXT=tgz;;
341                 *.tpz) EXT=tpz;;
342                 *.z)   EXT=z;;
343             esac
344             case "$EXT" in
345                 bz2|Z|gz|z) D=`basename "$i" ."$EXT"`;;
346                 tgz|tpz)    D=`basename "$i" ."$EXT"`.tar;;
347             esac
348             if [ "$EXT" = "bz2" ]; then
349                 bunzip2 -v "$i"
350                 gzip -f9 -v "$D"
351             else
352                 gunzip -v "$i"
353                 bzip2 -v "$D"
354             fi
355         done
357 + x /usr/bin/open | x /usr/local/bin/open & x /bin/sh
358 o       Open next a free console
359         open -s -- sh