My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

224 lignes
7.4 KiB

  1. /*
  2. * BSD 2-Clause License
  3. *
  4. * Copyright (c) 2014-2016, Lazaros Koromilas <lostd@2f30.org>
  5. * Copyright (c) 2014-2016, Dimitris Papastamos <sin@2f30.org>
  6. * Copyright (c) 2016-2018, Arun Prakash Jana <engineerarun@gmail.com>
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #define CONTROL(c) ((c) ^ 0x40)
  31. /* Supported actions */
  32. enum action {
  33. SEL_BACK = 1,
  34. SEL_GOIN,
  35. SEL_NEXT,
  36. SEL_PREV,
  37. SEL_PGDN,
  38. SEL_PGUP,
  39. SEL_HOME,
  40. SEL_END,
  41. SEL_CD,
  42. SEL_CDHOME,
  43. SEL_CDBEGIN,
  44. SEL_CDLAST,
  45. SEL_CDBM,
  46. SEL_PIN,
  47. SEL_VISIT,
  48. SEL_FLTR,
  49. SEL_MFLTR,
  50. SEL_SEARCH,
  51. SEL_TOGGLEDOT,
  52. SEL_DETAIL,
  53. SEL_STATS,
  54. SEL_MEDIA,
  55. SEL_FMEDIA,
  56. SEL_DFB,
  57. SEL_ARCHIVE,
  58. SEL_LIST,
  59. SEL_EXTRACT,
  60. SEL_FSIZE, /* file size */
  61. SEL_ASIZE, /* apparent size */
  62. SEL_BSIZE, /* block size */
  63. SEL_MTIME,
  64. SEL_REDRAW,
  65. SEL_COPY,
  66. SEL_COPYMUL,
  67. SEL_COPYLIST,
  68. SEL_QUOTE,
  69. SEL_OPEN,
  70. SEL_NEW,
  71. SEL_RENAME,
  72. SEL_RENAMEALL,
  73. SEL_HELP,
  74. SEL_RUN,
  75. SEL_RUNSCRIPT,
  76. SEL_RUNARG,
  77. SEL_LOCK,
  78. SEL_CDQUIT,
  79. SEL_QUIT,
  80. };
  81. /* Associate a pressed key to an action */
  82. struct key {
  83. int sym; /* Key pressed */
  84. enum action act; /* Action */
  85. char *run; /* Program to run or program option */
  86. char *env; /* Environment variable to run */
  87. };
  88. /* Extension pattern and mime combination */
  89. struct assoc {
  90. char *regex; /* Regex to match on filename */
  91. char *mime; /* File type */
  92. };
  93. static struct assoc assocs[] = {
  94. { "\\.(c|cpp|h|log|md|py|rb|sh|txt)$", "text" },
  95. };
  96. static struct key bindings[] = {
  97. /* Back */
  98. { KEY_BACKSPACE, SEL_BACK, "", "" },
  99. { KEY_LEFT, SEL_BACK, "", "" },
  100. { 'h', SEL_BACK, "", "" },
  101. { CONTROL('H'), SEL_BACK, "", "" },
  102. /* Inside */
  103. { KEY_ENTER, SEL_GOIN, "", "" },
  104. { '\r', SEL_GOIN, "", "" },
  105. { KEY_RIGHT, SEL_GOIN, "", "" },
  106. { 'l', SEL_GOIN, "", "" },
  107. /* Next */
  108. { 'j', SEL_NEXT, "", "" },
  109. { KEY_DOWN, SEL_NEXT, "", "" },
  110. { CONTROL('N'), SEL_NEXT, "", "" },
  111. /* Previous */
  112. { 'k', SEL_PREV, "", "" },
  113. { KEY_UP, SEL_PREV, "", "" },
  114. { CONTROL('P'), SEL_PREV, "", "" },
  115. /* Page down */
  116. { KEY_NPAGE, SEL_PGDN, "", "" },
  117. { CONTROL('D'), SEL_PGDN, "", "" },
  118. /* Page up */
  119. { KEY_PPAGE, SEL_PGUP, "", "" },
  120. { CONTROL('U'), SEL_PGUP, "", "" },
  121. /* First entry */
  122. { KEY_HOME, SEL_HOME, "", "" },
  123. { 'g', SEL_HOME, "", "" },
  124. { CONTROL('A'), SEL_HOME, "", "" },
  125. { '^', SEL_HOME, "", "" },
  126. /* Last entry */
  127. { KEY_END, SEL_END, "", "" },
  128. { 'G', SEL_END, "", "" },
  129. { CONTROL('E'), SEL_END, "", "" },
  130. { '$', SEL_END, "", "" },
  131. /* Change dir */
  132. { 'c', SEL_CD, "", "" },
  133. /* HOME */
  134. { '~', SEL_CDHOME, "", "" },
  135. /* Initial directory */
  136. { '&', SEL_CDBEGIN, "", "" },
  137. /* Last visited dir */
  138. { '-', SEL_CDLAST, "", "" },
  139. /* Change dir using bookmark */
  140. { CONTROL('B'), SEL_CDBM, "", "" },
  141. /* Mark a path to visit later */
  142. { 'b', SEL_PIN, "", "" },
  143. /* Visit marked directory */
  144. { CONTROL('V'), SEL_VISIT, "", "" },
  145. /* Filter */
  146. { '/', SEL_FLTR, "", "" },
  147. /* Toggle filter mode */
  148. { KEY_IC, SEL_MFLTR, "", "" },
  149. { CONTROL('I'), SEL_MFLTR, "", "" },
  150. /* Desktop search */
  151. { CONTROL('_'), SEL_SEARCH, "", "" },
  152. /* Toggle hide .dot files */
  153. { '.', SEL_TOGGLEDOT, "", "" },
  154. /* Detailed listing */
  155. { 'd', SEL_DETAIL, "", "" },
  156. /* File details */
  157. { 'D', SEL_STATS, "", "" },
  158. /* Show media info short, run is hacked */
  159. { 'm', SEL_MEDIA, NULL, "" },
  160. /* Show media info full, run is hacked */
  161. { 'M', SEL_FMEDIA, "-f", "" },
  162. /* Open dir in desktop file manager */
  163. { 'o', SEL_DFB, "", "" },
  164. /* Create archive */
  165. { 'f', SEL_ARCHIVE, "", "" },
  166. /* List archive */
  167. { 'F', SEL_LIST, "-l", "" },
  168. /* Extract archive */
  169. { CONTROL('F'), SEL_EXTRACT, "-x", "" },
  170. /* Toggle sort by size */
  171. { 's', SEL_FSIZE, "", "" },
  172. /* Sort by apparent size including dir contents */
  173. { 'S', SEL_ASIZE, "", "" },
  174. /* Sort by total block count including dir contents */
  175. { CONTROL('J'), SEL_BSIZE, "", "" },
  176. /* Toggle sort by time */
  177. { 't', SEL_MTIME, "", "" },
  178. /* Redraw window */
  179. { CONTROL('L'), SEL_REDRAW, "", "" },
  180. { KEY_F(5), SEL_REDRAW, "", "" }, /* Undocumented */
  181. /* Copy currently selected file path */
  182. { CONTROL('K'), SEL_COPY, "", "" },
  183. { ' ', SEL_COPY, "", "" },
  184. /* Toggle copy multiple file paths */
  185. { CONTROL('Y'), SEL_COPYMUL, "", "" },
  186. /* Show list of copied files */
  187. { 'y', SEL_COPYLIST, "", "" },
  188. /* Toggle quote on while copy */
  189. { CONTROL('T'), SEL_QUOTE, "", "" },
  190. /* Open in a custom application */
  191. { CONTROL('O'), SEL_OPEN, "", "" },
  192. /* Create a new file */
  193. { 'n', SEL_NEW, "", "" },
  194. /* Show rename prompt */
  195. { CONTROL('R'), SEL_RENAME, "", "" },
  196. { KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
  197. /* Rename contents of current dir */
  198. { 'r', SEL_RENAMEALL, "", "" },
  199. /* Show help */
  200. { '?', SEL_HELP, "", "" },
  201. /* Run command */
  202. { '!', SEL_RUN, "sh", "SHELL" },
  203. { CONTROL(']'), SEL_RUN, "sh", "SHELL" },
  204. /* Run a custom script */
  205. { 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
  206. /* Run command with argument */
  207. { 'e', SEL_RUNARG, "", "VISUAL" },
  208. { 'p', SEL_RUNARG, "less", "PAGER" },
  209. /* Lock screen */
  210. { 'L', SEL_LOCK, "", "" },
  211. /* Change dir on quit */
  212. { 'Q', SEL_CDQUIT, "", "" },
  213. { CONTROL('G'), SEL_CDQUIT, "", "" },
  214. /* Quit */
  215. { 'q', SEL_QUIT, "", "" },
  216. { CONTROL('X'), SEL_QUIT, "", "" },
  217. };