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.
 
 
 
 
 
 

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