Merge branch '4490_cleanup'
[midnight-commander.git] / misc / mc.menu.in
blob9d37e378a08a4a709c6c80689f0baa9c6dd64b2a
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 7       Compress the current subdirectory (tar.zst)
88         Pwd=`basename %d /`
89         echo -n "Name of the compressed file (without extension) [$Pwd]: "
90         read tar
91         [ "$tar"x = x ] && tar="$Pwd"
92         cd .. && \
93         tar cf - "$Pwd" | zstd -f > "$tar.tar.zst" && \
94         echo "../$tar.tar.zst created."
96 8       Compress the current subdirectory (tar.lzo)
97         Pwd=`basename %d /`
98         echo -n "Name of the compressed file (without extension) [$Pwd]: "
99         read tar
100         [ "$tar"x = x ] && tar="$Pwd"
101         cd .. && \
102         tar cf - "$Pwd" | lzop -f > "$tar.tar.lzo" && \
103         echo "../$tar.tar.lzo created."
105 = f \.c$ & t r
106 + f \.c$ & t r & ! t t
107 c       Compile and link current .c file
108         make "`basename %f .c`" 2>/dev/null || cc -O -o "`basename %f .c`" %f
110 + t r & ! t t
111 a       Append file to opposite
112         cat %f >> %D/%f
114 + t t
115 A       Append files to opposite files
116         for i in %t ; do
117             cat "$i" >> %D/"$i"
118         done
120 + t r & ! t t
121 d       Delete file if a copy exists in the other directory.
122         if [ %d = %D ]; then
123             echo "The two directories must be different."
124             exit 1
125         fi
126         if [ -f %D/%f ]; then        # if two of them, then
127             if cmp -s %D/%f %f; then
128                 rm %f && echo %f": DELETED."
129             else
130                 echo %f" and "%D/%f" differ: NOT deleted."
131                 echo -n "Press RETURN "
132                 read key
133             fi
134         else
135             echo %f": No copy in "%D/%f": NOT deleted."
136         fi
138 + t t
139 D       Delete tagged files if a copy exists in the other directory.
140         if [ %d = %D ]; then
141             echo "The two directories must be different."
142             exit 1
143         fi
144         for i in %t ; do
145             if [ -f %D/"$i" ]; then
146                 SUM1=`sum "$i"`
147                 SUM2=`sum %D/"$i"`
148                 if [ "$SUM1" = "$SUM2" ]; then
149                     rm "$i" && echo "${i}: DELETED."
150                 else
151                     echo "$i and "%D"/$i differ: NOT deleted."
152                 fi
153             else
154                 echo "$i has no copy in "%D": NOT deleted."
155             fi
156         done
158 m       View manual page
159         MAN=%{Enter manual name}
160         %view{ascii,nroff} MANROFFOPT='@MAN_FLAGS@' MAN_KEEP_FORMATTING=1 man -P cat "$MAN"
162 = f \.gz$ & t r
163 + ! t t
164 n       Inspect gzip'ed newsbatch file
165         dd if=%f bs=1 skip=12 | zcat | ${PAGER-more}
166         # assuming the cunbatch header is 12 bytes long.
168 = t r &
169 + ! t t
170 h       Strip headers from current newsarticle
171         CHECK=`awk '{print $1 ; exit}' %f` 2>/dev/null
172         case "$CHECK" in
173             Newsgroups:|Path:)
174                 I=`mktemp "${MC_TMPDIR:-/tmp}/news.XXXXXX"` || exit 1
175                 cp %f "$I" && sed '/^'"$CHECK"' /,/^$/d' "$I" > %f
176                 [ "$?" = "0" ] && rm "$I"
177                 echo %f": header removed."
178                 ;;
179             *)
180                 echo %f" is not a news article."
181                 ;;
182         esac
184 + t t
185 H       Strip headers from the marked newsarticles
186         for i in %t ; do
187             CHECK=`awk '{print $1 ; exit}' "$i"` 2>/dev/null
188             WFILE=`mktemp "${MC_TMPDIR:-/tmp}/news.XXXXXX"` || exit 1
189             case "$CHECK" in
190                 Newsgroups:|Path:)
191                     cp "$i" "$WFILE" && sed '/^'"$CHECK"' /,/^$/d' "$WFILE" > "$i"
192                     if [ "$?" = "0" ]; then
193                         rm "$WFILE"; echo "$i header removed. OK."
194                     else
195                         echo "Oops! Please check $i against $WFILE."
196                     fi
197                     ;;
198                 *)
199                     echo "$i skipped: Not a news article."
200                     ;;
201             esac
202         done
204 = t r
205 + ! t t
206 r       Copy file to remote host
207         echo -n "To which host?: "
208         read Host
209         echo -n "To which directory on $Host?: "
210         read Dir
211         rcp -p %f "${Host}:${Dir}"
213 + t t
214 R       Copy files to remote host (no error checking)
215         echo -n "Copy files to which host?: "
216         read Host
217         echo -n "To which directory on $Host? :"
218         read Dir
219         rcp -pr %u "${Host}:${Dir}"
221 = f \.tex$ & t r
222 + f \.tex$ & t r & ! t t
223 t       Run latex on file and show it with xdvi
224         latex %f && xdvi "`basename %f .tex`".dvi
226 =+ f ^part | f ^Part | f uue & t r
227 + t t
228 U       Uudecode marked news articles (needs work)
229         (
230             for i in %t ; do # strip headers
231                 FIRST=`awk '{print $1 ; exit}' "$i"`
232                 cat "$i" | sed '/^'"$FIRST"' /,/^$/d'
233             done
234         ) | sed '/^$/d' | sed -n '/^begin 6/,/^end$/p' | uudecode
235         if [ "$?" != "0" ]; then
236             echo "Cannot decode "%t"."
237         fi
238         echo "Please test the output file before deleting anything."
240 =+ f \.tar\.gz$ | f \.tar\.z$ | f \.tgz$ | f \.tpz$ | f \.tar\.lz$ | f \.tar\.lz4$ | f \.tar\.lzma$ | f \.tar\.lzo$ | f \.tar\.7z$ | f \.tar\.xz$ | f \.tar\.zst | f \.tar\.Z$ | f \.tar\.bz2$ & t rl
241 x       Extract the contents of a compressed tar file
242         unset PRG
243         case %f in
244             *.tar.7z)   PRG="7za e -so";;
245             *.tar.bz2)  PRG="bunzip2 -c";;
246             *.tar.gz|*.tar.z|*.tgz|*.tpz|*.tar.Z) PRG="gzip -dc";;
247             *.tar.lz)   PRG="lzip -dc";;
248             *.tar.lz4)  PRG="lz4 -dc";;
249             *.tar.lzma) PRG="lzma -dc";;
250             *.tar.lzo)  PRG="lzop -dc";;
251             *.tar.xz)   PRG="xz -dc";;
252             *.tar.zst)  PRG="zstd -dc";;
253             *)          exit 1;;
254         esac
255         $PRG %f | tar xvf -
257 = t r
258 + ! t t
259 y       Gzip or gunzip current file
260         unset DECOMP
261         case %f in
262             *.gz|*.[zZ]) DECOMP=-d;;
263         esac
264         # Do *not* add quotes around $DECOMP!
265         gzip $DECOMP -v %f
267 + t t
268 Y       Gzip or gunzip tagged files
269         for i in %t ; do
270             unset DECOMP
271             case "$i" in
272                 *.gz|*.[zZ]) DECOMP=-d;;
273             esac
274             gzip $DECOMP -v "$i"
275         done
277 + ! t t
278 b       Bzip2 or bunzip2 current file
279         unset DECOMP
280         case %f in
281             *.bz2) DECOMP=-d;;
282         esac
283         bzip2 $DECOMP -v %f
285 + t t
286 B       Bzip2 or bunzip2 tagged files
287         for i in %t ; do
288             unset DECOMP
289             case "$i" in
290                 *.bz2) DECOMP=-d;;
291             esac
292             bzip2 $DECOMP -v "$i"
293         done
295 + f \.tar.gz$ | f \.tgz$ | f \.tpz$ | f \.tar.Z$ | f \.tar.z$ | f \.tar.bz2$ | f \.tar.F$ & t r & ! t t
296 z       Extract compressed tar file to subdirectory
297         unset D
298         set gzip -cd
299         case %f in
300             *.tar.F)   D=`basename %f .tar.F`; set freeze -dc;;
301             *.tar.Z)   D=`basename %f .tar.Z`;;
302             *.tar.bz2) D=`basename %f .tar.bz2`; set bunzip2 -c;;
303             *.tar.gz)  D=`basename %f .tar.gz`;;
304             *.tar.z)   D=`basename %f .tar.z`;;
305             *.tgz)     D=`basename %f .tgz`;;
306             *.tpz)     D=`basename %f .tpz`;;
307         esac
308         mkdir "$D"; cd "$D" && ("$1" "$2" ../%f | tar xvf -)
310 + t t
311 Z       Extract compressed tar files to subdirectories
312         for i in %t ; do
313             set gzip -dc
314             unset D
315             case "$i" in
316                 *.tar.F)   D=`basename "$i" .tar.F`; set freeze -dc;;
317                 *.tar.Z)   D=`basename "$i" .tar.Z`;;
318                 *.tar.bz2) D=`basename "$i" .tar.bz2`; set bunzip2 -c;;
319                 *.tar.gz)  D=`basename "$i" .tar.gz`;;
320                 *.tar.z)   D=`basename "$i" .tar.z`;;
321                 *.tgz)     D=`basename "$i" .tgz`;;
322                 *.tpz)     D=`basename "$i" .tpz`;;
323           esac
324           mkdir "$D"; (cd "$D" && "$1" "$2" "../$i" | tar xvf -)
325         done
327 + f \.gz$ | f \.tgz$ | f \.tpz$ | f \.Z$ | f \.z$ | f \.bz2$ & t r & ! t t
328 c       Convert gz<->bz2, tar.gz<->tar.bz2 & tgz->tar.bz2
329         unset D
330         unset EXT
331         case %f in
332             *.Z)   EXT=Z;;
333             *.bz2) EXT=bz2;;
334             *.gz)  EXT=gz;;
335             *.tgz) EXT=tgz;;
336             *.tpz) EXT=tpz;;
337             *.z)   EXT=z;;
338         esac
339         case "$EXT" in
340             bz2|Z|gz|z) D=`basename %f ."$EXT"`;;
341             tgz|tpz)    D=`basename %f ."$EXT"`.tar;;
342         esac
343         if [ "$EXT" = "bz2" ]; then
344             bunzip2 -v %f
345             gzip -f9 -v "$D"
346         else
347             gunzip -v %f
348             bzip2 -v "$D"
349         fi
351 + t t
352 C       Convert gz<->bz2, tar.gz<->tar.bz2 & tgz->tar.bz2
353         for i in %t ; do
354             unset D
355             unset EXT
356             case "$i" in
357                 *.Z)   EXT=Z;;
358                 *.bz2) EXT=bz2;;
359                 *.gz)  EXT=gz;;
360                 *.tgz) EXT=tgz;;
361                 *.tpz) EXT=tpz;;
362                 *.z)   EXT=z;;
363             esac
364             case "$EXT" in
365                 bz2|Z|gz|z) D=`basename "$i" ."$EXT"`;;
366                 tgz|tpz)    D=`basename "$i" ."$EXT"`.tar;;
367             esac
368             if [ "$EXT" = "bz2" ]; then
369                 bunzip2 -v "$i"
370                 gzip -f9 -v "$D"
371             else
372                 gunzip -v "$i"
373                 bzip2 -v "$D"
374             fi
375         done
377 + x /usr/bin/open | x /usr/local/bin/open & x /bin/sh
378 o       Open next a free console
379         open -s -- sh