My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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