README 7.2 KB

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