📄 readme
字号:
Writing scripts for Midnight Commander's external vfsIMPORTANT NOTE: There may be some bugs left in extfs. Enjoy.Starting with version 3.1, the Midnight Commander comes with so calledextfs, which is one of the virtual filesystems. This system makes itpossible to create new virtual filesystems for the GNU MC very easily.Such work has two basic steps:Editing $(libdir)/extfs/extfs.ini.Creating a shell script/program to handle requests.(Note: $(libdir) should be substituted for actual libdir path stored whenconfigured or compiled, like /usr/local/lib/mc or /usr/lib/mc).The first one is very easy:You assign a vfs suffix. For example, if you have .zip file, and wouldlike to see what's inside it, path will be/anypath/my.zip#uzip/some_path/...Then you add a line extfs.ini file containing just that extension. Ifyour vfs does not require file to work on, add ':' to the end of name.In this example, .zip is suffix, but I call vfs 'uzip'. Why? Well,what this vfs essentially does is UNzip. UN is too long, so I choosedU. Note that sometime in future filesystem like zip may exist: It willtake whole tree and create .zip file from it. So /usr#zip will bezipfile containing whole /usr tree.The second one may require some your knowledge of shell/c programming:You have to create a program (with executable permissions) prefix in$(libdir)/extfs (in our example $(libdir)/extfs/uzip).* Commands that should be implemented by your shell script----------------------------------------------------------Return zero from your script upon completion of the command, otherwisenonzero for failure or in case of an unsupported command.$libdir/extfs/prefix command [arguments]* Command: list archivenameThis command should list the complete archive content in the following format(a little modified ls -l listing):AAAAAAA NNN OOOOOOOO GGGGGGGG SSSSSSSS DATETIME [PATH/]FILENAME [-> [PATH/]FILENAME[/]]]where (things in [] are optional):AAAAAAA is the permission string like in ls -lNNN is the number of linksOOOOOOOO is the owner (either UID or name)GGGGGGGG is the group (either GID or name)SSSSSSSS is the file sizeFILENAME is the filenamePATH is the path from the archive's root without the leading slash (/)DATETIME has one of the following formats: Mon DD hh:mm, Mon DD YYYY, Mon DD YYYY hh:mm, MM-DD-YYYY hh:mm where Mon is a three letter English month name, DD is day 1-31, MM is month 01-12, YYYY is four digit year, hh hour is and mm is minute.If the -> [PATH/]FILENAME part is present, it means:If permissions start with an l (ell), then it is the name that symlinkpoints to. (If this PATH starts with a MC vfs prefix, then it is a symlinksomewhere to the other virtual filesystem (if you want to specify path fromthe local root, use local:/path_name instead of /path_name, since /path_namemeans from root of the archive listed).If permissions do not start with l, but number of links is greater than one,then it says that this file should be a hardlinked with the other file.* Command: copyout archivename storedfilename extracttoThis should extract from archive archivename the file calledstoredfilename (possibly with path if not located in archive's root[this is wrong. current extfs strips paths! -- pavel@ucw.cz])to file extractto.* Command: copyin archivename storedfilename sourcefileThis should add to the archivename the sourcefile with the namestoredfilename inside the archive. Important note: archivename in the above examples may not have theextension you are expecting to have, like it may happen thatarchivename will be something like /tmp/f43513254 or justanything. Some archivers do not like it, so you'll have to find someworkaround.* Command: rm archivename storedfilenameThis should remove storedfilename from archivename.* Command: mkdir archivename dirnameThis should create a new directory called dirname inside archivename.* Command: rmdir archivename dirnameThis should remove an existing directory dirname. If the directory isnot empty, mc will recursively delete it (possibly prompting).* Command: runUndocumented :-)---------------------------------------------------------Don't forget to mark this file executable (chmod 755 ThisFile, for example)For skeleton structure of executable, look at some of filesystemssimilar to yours.---------------------------------------------------------In constructing these routines, errors will be made, and mc will not displaya malformed printing line. That can lead the programmer down many falsetrails in search of the bug. Since this routine is an executable shell scriptit can be run from the command line independently of mc, and its output willshow on the console or can be redirected to a file.* Putting it to use----------------------------------------------------------The file .mc.ext in a home directory, and in mc's user directory (commonly/usr/local/lib/mc), contains instructions for operations on files dependingon filename extensions. It is well documented in other files in this distribution, so here are just a few notes specifically on use of theVirtual File System you just built.There are entries in .mc.ext defining a few operations that can be done on afile from an mc panel. Typically they are annotated with a hash mark and afile extension like this:# zipThere must be a way to find the file by extension, so the next line doesthat. In essence it says "identify the string ".zip" or (|) ".ZIP" at theend ($) of a filename": regex/\.(zip|ZIP)$The operations themselves follow that. They must be indented by at least aspace, and a tab works as well. In particular, the Open operation willnow use your new virtual file system by cd'ing to it like this: Open=%cd zip:%d/%pThis is the line used when a file is highlighted in a panel and the userpresses <Enter> or <Return>. The contents of the archive should show justas if they were in a real directory, and can be manipulated as such.The rest of the entry pertains to use of the F3 View key: View=%view{ascii} unzip -v %fAnd perhaps an optional icon for X: Icon=zip.xpmAnd perhaps an operation to extract the contents of the file, called froma menu selection: Extract=unzip %f '*'This is just an example. The current entry for .zip files has a menu selectionof 'Unzip' which could be used in place of 'Extract'. What goes here dependson what items you have in, or add to, the menu system, and that's another subject. The sum of this is the .mc.ext entry:# zipregex/\.(zip|ZIP)$ Open=%cd zip:%d/%p View=%view{ascii} unzip -v %f Icon=zip.xpm Extract=unzip %f '*'Add an entry like this to the .mc.ext file in a user's home directory, If youwant others to have it, add it to the mc.ext file in the mc system directory,often /usr/local/lib/mc/mc.ext. Notice this file is not prepended with a dot.Once all this is done, and things are in their proper places, exit mc if youwere using it, and restart it so it picks up the new information.That's all there is to it. The hardest part is making a listing functionthat sorts the output of a system listing command and turns it into a formthat mc can use. Currently awk (or gawk) is used because nearly all systemshave it. If another scripting language is available, like perl, that couldalso be used.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -