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.
 
 
 
 
 
 

144 line
4.2 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_TOGGLEDOT,
  24. SEL_DETAIL,
  25. SEL_STATS,
  26. SEL_MEDIA,
  27. SEL_FMEDIA,
  28. SEL_DFB,
  29. SEL_FSIZE,
  30. SEL_BSIZE,
  31. SEL_MTIME,
  32. SEL_REDRAW,
  33. SEL_COPY,
  34. SEL_HELP,
  35. SEL_RUN,
  36. SEL_RUNARG,
  37. };
  38. /* Associate a pressed key to an action */
  39. struct key {
  40. int sym; /* Key pressed */
  41. enum action act; /* Action */
  42. char *run; /* Program to run */
  43. char *env; /* Environment variable to run */
  44. };
  45. /* Extension pattern and mime combination */
  46. struct assoc {
  47. char *regex; /* Regex to match on filename */
  48. char *mime; /* File type */
  49. };
  50. static struct assoc assocs[] = {
  51. { "\\.(c|cpp|h|log|md|py|sh|txt)$", "text" },
  52. };
  53. static struct key bindings[] = {
  54. /* Quit */
  55. { 'q', SEL_QUIT, "", "" },
  56. { CONTROL('Q'), SEL_QUIT, "", "" },
  57. /* Change dir on quit */
  58. { 'Q', SEL_CDQUIT, "", "" },
  59. /* Back */
  60. { KEY_BACKSPACE, SEL_BACK, "", "" },
  61. { KEY_LEFT, SEL_BACK, "", "" },
  62. { 'h', SEL_BACK, "", "" },
  63. { CONTROL('H'), SEL_BACK, "", "" },
  64. /* Inside */
  65. { KEY_ENTER, SEL_GOIN, "", "" },
  66. { '\r', SEL_GOIN, "", "" },
  67. { KEY_RIGHT, SEL_GOIN, "", "" },
  68. { 'l', SEL_GOIN, "", "" },
  69. /* Filter */
  70. { '/', SEL_FLTR, "", "" },
  71. /* Toggle filter mode */
  72. { KEY_IC, SEL_MFLTR, "", "" },
  73. /* Desktop search */
  74. { CONTROL('_'), SEL_SEARCH, "", "" },
  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. { 'b', SEL_CDBM, "", "" },
  109. /* Toggle hide .dot files */
  110. { '.', SEL_TOGGLEDOT, "", "" },
  111. /* Detailed listing */
  112. { 'd', SEL_DETAIL, "", "" },
  113. /* File details */
  114. { 'D', SEL_STATS, "", "" },
  115. /* Show media info short, run is hacked */
  116. { 'm', SEL_MEDIA, NULL, "" },
  117. /* Show media info full, run is hacked */
  118. { 'M', SEL_FMEDIA, "-f", "" },
  119. /* Open dir in desktop file manager */
  120. { 'o', SEL_DFB, "", "" },
  121. /* Toggle sort by size */
  122. { 's', SEL_FSIZE, "", "" },
  123. /* Sort by total block count including dir contents */
  124. { 'S', SEL_BSIZE, "", "" },
  125. /* Toggle sort by time */
  126. { 't', SEL_MTIME, "", "" },
  127. { CONTROL('L'), SEL_REDRAW, "", "" },
  128. { KEY_F(2), SEL_REDRAW, "", "" },
  129. /* Copy currently selected file path */
  130. { CONTROL('K'), SEL_COPY, "", "" },
  131. /* Show help */
  132. { '?', SEL_HELP, "", "" },
  133. /* Run command */
  134. { '!', SEL_RUN, "sh", "SHELL" },
  135. /* Run command with argument */
  136. { 'e', SEL_RUNARG, "vi", "EDITOR" },
  137. { 'p', SEL_RUNARG, "less", "PAGER" },
  138. };