README 7.3 KB

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