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.

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