My build of nnn with minor changes
 
 
 
 
 
 

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