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.
 
 
 
 
 
 

194 lignes
5.8 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #define CONTROL(c) ((c) ^ 0x40)
  3. /* Supported actions */
  4. enum action {
  5. SEL_BACK = 1,
  6. SEL_GOIN,
  7. SEL_NEXT,
  8. SEL_PREV,
  9. SEL_PGDN,
  10. SEL_PGUP,
  11. SEL_HOME,
  12. SEL_END,
  13. SEL_CD,
  14. SEL_CDHOME,
  15. SEL_CDBEGIN,
  16. SEL_CDLAST,
  17. SEL_CDBM,
  18. SEL_PIN,
  19. SEL_VISIT,
  20. SEL_FLTR,
  21. SEL_MFLTR,
  22. SEL_SEARCH,
  23. SEL_TOGGLEDOT,
  24. SEL_DETAIL,
  25. SEL_STATS,
  26. SEL_MEDIA,
  27. SEL_FMEDIA,
  28. SEL_DFB,
  29. SEL_ARCHIVE,
  30. SEL_LIST,
  31. SEL_EXTRACT,
  32. SEL_FSIZE,
  33. SEL_BSIZE,
  34. SEL_MTIME,
  35. SEL_REDRAW,
  36. SEL_COPY,
  37. SEL_COPYMUL,
  38. SEL_QUOTE,
  39. SEL_OPEN,
  40. SEL_NEW,
  41. SEL_RENAME,
  42. SEL_RENAMEALL,
  43. SEL_HELP,
  44. SEL_RUN,
  45. SEL_RUNSCRIPT,
  46. SEL_RUNARG,
  47. #ifdef __linux__
  48. SEL_LOCK,
  49. #endif
  50. SEL_CDQUIT,
  51. SEL_QUIT,
  52. };
  53. /* Associate a pressed key to an action */
  54. struct key {
  55. int sym; /* Key pressed */
  56. enum action act; /* Action */
  57. char *run; /* Program to run or program option */
  58. char *env; /* Environment variable to run */
  59. };
  60. /* Extension pattern and mime combination */
  61. struct assoc {
  62. char *regex; /* Regex to match on filename */
  63. char *mime; /* File type */
  64. };
  65. static struct assoc assocs[] = {
  66. { "\\.(c|cpp|h|log|md|py|rb|sh|txt)$", "text" },
  67. };
  68. static struct key bindings[] = {
  69. /* Back */
  70. { KEY_BACKSPACE, SEL_BACK, "", "" },
  71. { KEY_LEFT, SEL_BACK, "", "" },
  72. { 'h', SEL_BACK, "", "" },
  73. { CONTROL('H'), SEL_BACK, "", "" },
  74. /* Inside */
  75. { KEY_ENTER, SEL_GOIN, "", "" },
  76. { '\r', SEL_GOIN, "", "" },
  77. { KEY_RIGHT, SEL_GOIN, "", "" },
  78. { 'l', SEL_GOIN, "", "" },
  79. /* Next */
  80. { 'j', SEL_NEXT, "", "" },
  81. { KEY_DOWN, SEL_NEXT, "", "" },
  82. { CONTROL('N'), SEL_NEXT, "", "" },
  83. /* Previous */
  84. { 'k', SEL_PREV, "", "" },
  85. { KEY_UP, SEL_PREV, "", "" },
  86. { CONTROL('P'), SEL_PREV, "", "" },
  87. /* Page down */
  88. { KEY_NPAGE, SEL_PGDN, "", "" },
  89. { CONTROL('D'), SEL_PGDN, "", "" },
  90. /* Page up */
  91. { KEY_PPAGE, SEL_PGUP, "", "" },
  92. { CONTROL('U'), SEL_PGUP, "", "" },
  93. /* First entry */
  94. { KEY_HOME, SEL_HOME, "", "" },
  95. { 'g', SEL_HOME, "", "" },
  96. { CONTROL('A'), SEL_HOME, "", "" },
  97. { '^', SEL_HOME, "", "" },
  98. /* Last entry */
  99. { KEY_END, SEL_END, "", "" },
  100. { 'G', SEL_END, "", "" },
  101. { CONTROL('E'), SEL_END, "", "" },
  102. { '$', SEL_END, "", "" },
  103. /* Change dir */
  104. { 'c', SEL_CD, "", "" },
  105. /* HOME */
  106. { '~', SEL_CDHOME, "", "" },
  107. /* Initial directory */
  108. { '&', SEL_CDBEGIN, "", "" },
  109. /* Last visited dir */
  110. { '-', SEL_CDLAST, "", "" },
  111. /* Change dir using bookmark */
  112. { CONTROL('B'), SEL_CDBM, "", "" },
  113. /* Mark a path to visit later */
  114. { 'b', SEL_PIN, "", "" },
  115. /* Visit marked directory */
  116. { CONTROL('V'), SEL_VISIT, "", "" },
  117. /* Filter */
  118. { '/', SEL_FLTR, "", "" },
  119. /* Toggle filter mode */
  120. { KEY_IC, SEL_MFLTR, "", "" },
  121. { CONTROL('I'), SEL_MFLTR, "", "" },
  122. /* Desktop search */
  123. { CONTROL('_'), SEL_SEARCH, "", "" },
  124. /* Toggle hide .dot files */
  125. { '.', SEL_TOGGLEDOT, "", "" },
  126. /* Detailed listing */
  127. { 'd', SEL_DETAIL, "", "" },
  128. /* File details */
  129. { 'D', SEL_STATS, "", "" },
  130. /* Show media info short, run is hacked */
  131. { 'm', SEL_MEDIA, NULL, "" },
  132. /* Show media info full, run is hacked */
  133. { 'M', SEL_FMEDIA, "-f", "" },
  134. /* Open dir in desktop file manager */
  135. { 'o', SEL_DFB, "", "" },
  136. /* Create archive */
  137. { 'f', SEL_ARCHIVE, "", "" },
  138. /* List archive */
  139. { 'F', SEL_LIST, "-l", "" },
  140. /* Extract archive */
  141. { CONTROL('F'), SEL_EXTRACT, "-x", "" },
  142. /* Toggle sort by size */
  143. { 's', SEL_FSIZE, "", "" },
  144. /* Sort by total block count including dir contents */
  145. { 'S', SEL_BSIZE, "", "" },
  146. { CONTROL('J'), SEL_BSIZE, "", "" },
  147. /* Toggle sort by time */
  148. { 't', SEL_MTIME, "", "" },
  149. /* Redraw window */
  150. { CONTROL('L'), SEL_REDRAW, "", "" },
  151. { KEY_F(5), SEL_REDRAW, "", "" }, /* Undocumented */
  152. /* Copy currently selected file path */
  153. { CONTROL('K'), SEL_COPY, "", "" },
  154. { ' ', SEL_COPY, "", "" },
  155. /* Toggle copy multiple file paths */
  156. { CONTROL('Y'), SEL_COPYMUL, "", "" },
  157. /* Toggle quote on while copy */
  158. { CONTROL('T'), SEL_QUOTE, "", "" },
  159. /* Open in a custom application */
  160. { CONTROL('O'), SEL_OPEN, "", "" },
  161. /* Create a new file */
  162. { 'n', SEL_NEW, "", "" },
  163. /* Show rename prompt */
  164. { CONTROL('R'), SEL_RENAME, "", "" },
  165. { KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
  166. /* Rename contents of current dir */
  167. { 'r', SEL_RENAMEALL, "", "" },
  168. /* Show help */
  169. { '?', SEL_HELP, "", "" },
  170. /* Run command */
  171. { '!', SEL_RUN, "sh", "SHELL" },
  172. { CONTROL(']'), SEL_RUN, "sh", "SHELL" },
  173. /* Run a custom script */
  174. { 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
  175. /* Run command with argument */
  176. { 'e', SEL_RUNARG, "", "VISUAL" },
  177. { 'p', SEL_RUNARG, "less", "PAGER" },
  178. #ifdef __linux__
  179. /* Lock screen */
  180. { 'L', SEL_LOCK, "", "" },
  181. #endif
  182. /* Change dir on quit */
  183. { 'Q', SEL_CDQUIT, "", "" },
  184. { CONTROL('G'), SEL_CDQUIT, "", "" },
  185. /* Quit */
  186. { 'q', SEL_QUIT, "", "" },
  187. { CONTROL('X'), SEL_QUIT, "", "" },
  188. };