Updated Russian translation.
[midnight-commander.git] / src / vfs / extfs / helpers / README
blob121e06496bd58af234f68fdb9376d8033f592fcf
1             Writing scripts for Midnight Commander's external vfs
3 IMPORTANT NOTE: There may be some bugs left in extfs. Enjoy.
5 Starting with version 3.1, the Midnight Commander comes with so called
6 extfs, which is one of the virtual filesystems. This system makes it
7 possible to create new virtual filesystems for the GNU MC very easily.
9 To handle requests, create a shell/perl/python/etc script/program
10 (with executable permissions) in $(libexecdir)/mc/extfs.d
11 or in ~/.mc/extfs.d.
13 (Note: $(libexecdir) should be substituted for actual libexecdir path
14 stored when configured or compiled, like /usr/local/libexec or /usr/libexec).
16 Assign a vfs suffix. For example, if you have .zip file, and would like
17 to see what's inside it, path will be
19 /anypath/my.zip/uzip://some_path/...
21 In this example, .zip is suffix, but I call vfs 'uzip'. Why? Well,
22 what this vfs essentially does is UNzip. UN is too long, so I choosed
23 U. Note that sometime in future filesystem like zip may exist: It will
24 take whole tree and create .zip file from it. So /usr/zip:// will be
25 zipfile containing whole /usr tree.
27 If your vfs does not require file to work on, add '+' to the end of name.
28 Note, that trailing '+' in file name is not a part of vfs name, it is
29 just an vfs attribue. So you have not use it in vfs commands:
31 cd rpms://
33 is correct command, and
35 cd rpms+://
37 is incorrect command.
40 * Commands that should be implemented by your shell script
41 ----------------------------------------------------------
43 Return zero from your script upon completion of the command, otherwise
44 nonzero for failure or in case of an unsupported command.
46 $libdir/extfs/prefix command [arguments]
48 * Command: list archivename
50 This command should list the complete archive content in the following format
51 (a little modified ls -l listing):
53 AAAAAAA NNN OOOOOOOO GGGGGGGG SSSSSSSS DATETIME [PATH/]FILENAME [-> [PATH/]FILENAME[/]]]
55 where (things in [] are optional):
57 AAAAAAA  is the permission string like in ls -l
58 NNN      is the number of links
59 OOOOOOOO is the owner (either UID or name)
60 GGGGGGGG is the group (either GID or name)
61 SSSSSSSS is the file size
62 FILENAME is the filename
63 PATH     is the path from the archive's root without the leading slash (/)
64 DATETIME has one of the following formats:
65             Mon DD hh:mm, Mon DD YYYY, Mon DD YYYY hh:mm, MM-DD-YYYY hh:mm
67             where Mon is a three letter English month name, DD is day
68             1-31, MM is month 01-12, YYYY is four digit year, hh hour is
69             and mm is minute.
71 If the -> [PATH/]FILENAME part is present, it means:
73 If permissions start with an l (ell), then it is the name that symlink
74 points to. (If this PATH starts with a MC vfs prefix, then it is a symlink
75 somewhere to the other virtual filesystem (if you want to specify path from
76 the local root, use local:/path_name instead of /path_name, since /path_name
77 means from root of the archive listed).
79 If permissions do not start with l, but number of links is greater than one,
80 then it says that this file should be a hardlinked with the other file.
82 * Command: copyout archivename storedfilename extractto
84 This should extract from archive archivename the file called
85 storedfilename (possibly with path if not located in archive's root
86 [this is wrong. current extfs strips paths! -- pavel@ucw.cz])
87 to file extractto.
89 * Command: copyin archivename storedfilename sourcefile
91 This should add to the archivename the sourcefile with the name
92 storedfilename inside the archive.  
94 Important note: archivename in the above examples may not have the
95 extension you are expecting to have, like it may happen that
96 archivename will be something like /tmp/f43513254 or just
97 anything. Some archivers do not like it, so you'll have to find some
98 workaround.
100 * Command: rm archivename storedfilename
102 This should remove storedfilename from archivename.
104 * Command: mkdir archivename dirname
106 This should create a new directory called dirname inside archivename.
108 * Command: rmdir archivename dirname
110 This should remove an existing directory dirname. If the directory is
111 not empty, mc will recursively delete it (possibly prompting).
113 * Command: run
115 Undocumented :-)
117 ---------------------------------------------------------
119 Don't forget to mark this file executable (chmod 755 ThisFile, for example)
121 For skeleton structure of executable, look at some of filesystems
122 similar to yours.
124 ---------------------------------------------------------
126 In constructing these routines, errors will be made, and mc will not display
127 a malformed printing line.  That can lead the programmer down many false
128 trails in search of the bug.  Since this routine is an executable shell script
129 it can be run from the command line independently of mc, and its output will
130 show on the console or can be redirected to a file.
132 * Putting it to use
133 ----------------------------------------------------------
134 The file .mc.ext in a home directory, and in mc's user directory (commonly
135 /etc/mc), contains instructions for operations on files depending
136 on filename extensions.  It is well documented in other files in this 
137 distribution, so here are just a few notes specifically on use of the
138 Virtual File System you just built.
140 There are entries in .mc.ext defining a few operations that can be done on a
141 file from an mc panel.  Typically they are annotated with a hash mark and a
142 file extension like this:
144 # zip
146 There must be a way to find the file by extension, so the next line does
147 that.  In essence it says "identify the string ".zip" or (|) ".ZIP" at the
148 end ($) of a filename": 
150 regex/\.(zip|ZIP)$
152 The operations themselves follow that. They must be indented by at least a
153 space, and a tab works as well.  In particular, the Open operation will
154 now use your new virtual file system by cd'ing to it like this:
156    Open=%cd zip:%d/%p
158 This is the line used when a file is highlighted in a panel and the user
159 presses <Enter> or <Return>.  The contents of the archive should show just
160 as if they were in a real directory, and can be manipulated as such.
161 The rest of the entry pertains to use of the F3 View key:
163    View=%view{ascii} unzip -v %f
165 And perhaps an optional icon for X:
167    Icon=zip.xpm
169 And perhaps an operation to extract the contents of the file, called from
170 a menu selection:
172    Extract=unzip %f '*'
174 This is just an example.  The current entry for .zip files has a menu selection
175 of 'Unzip' which could be used in place of 'Extract'.  What goes here depends
176 on what items you have in, or add to, the menu system, and that's another 
177 subject.  The sum of this is the .mc.ext entry:
179 # zip
180 regex/\.(zip|ZIP)$
181    Open=%cd %p/uzip://
182    View=%view{ascii} unzip -v %f
183    Icon=zip.xpm
184    Extract=unzip %f '*'
186 Add an entry like this to the .mc.ext file in a user's home directory, If you
187 want others to have it, add it to the mc.ext file in the mc system directory,
188 often /etc/mc/mc.ext.  Notice this file is not prepended with a dot.
190 Once all this is done, and things are in their proper places, exit mc if you
191 were using it, and restart it so it picks up the new information.
193 That's all there is to it.  The hardest part is making a listing function
194 that sorts the output of a system listing command and turns it into a form
195 that mc can use.  Currently awk (or gawk) is used because nearly all systems
196 have it. If another scripting language is available, like perl, that could
197 also be used.