My build of nnn with minor changes
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

171 řádky
5.1 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_OPEN,
  38. SEL_NEW,
  39. SEL_RENAME,
  40. SEL_HELP,
  41. SEL_RUN,
  42. SEL_RUNARG,
  43. SEL_CDQUIT,
  44. SEL_QUIT,
  45. };
  46. /* Associate a pressed key to an action */
  47. struct key {
  48. int sym; /* Key pressed */
  49. enum action act; /* Action */
  50. char *run; /* Program to run or program option */
  51. char *env; /* Environment variable to run */
  52. };
  53. /* Extension pattern and mime combination */
  54. struct assoc {
  55. char *regex; /* Regex to match on filename */
  56. char *mime; /* File type */
  57. };
  58. static struct assoc assocs[] = {
  59. { "\\.(c|cpp|h|log|md|py|sh|txt)$", "text" },
  60. };
  61. static struct key bindings[] = {
  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. /* Next */
  73. { 'j', SEL_NEXT, "", "" },
  74. { KEY_DOWN, SEL_NEXT, "", "" },
  75. { CONTROL('N'), SEL_NEXT, "", "" },
  76. /* Previous */
  77. { 'k', SEL_PREV, "", "" },
  78. { KEY_UP, SEL_PREV, "", "" },
  79. { CONTROL('P'), SEL_PREV, "", "" },
  80. /* Page down */
  81. { KEY_NPAGE, SEL_PGDN, "", "" },
  82. { CONTROL('D'), SEL_PGDN, "", "" },
  83. /* Page up */
  84. { KEY_PPAGE, SEL_PGUP, "", "" },
  85. { CONTROL('U'), SEL_PGUP, "", "" },
  86. /* First entry */
  87. { KEY_HOME, SEL_HOME, "", "" },
  88. { 'g', SEL_HOME, "", "" },
  89. { CONTROL('A'), SEL_HOME, "", "" },
  90. { '^', SEL_HOME, "", "" },
  91. /* Last entry */
  92. { KEY_END, SEL_END, "", "" },
  93. { 'G', SEL_END, "", "" },
  94. { CONTROL('E'), SEL_END, "", "" },
  95. { '$', SEL_END, "", "" },
  96. /* Change dir */
  97. { 'c', SEL_CD, "", "" },
  98. /* HOME */
  99. { '~', SEL_CDHOME, "", "" },
  100. /* Initial directory */
  101. { '&', SEL_CDBEGIN, "", "" },
  102. /* Last visited dir */
  103. { '-', SEL_CDLAST, "", "" },
  104. /* Change dir using bookmark */
  105. { CONTROL('B'), SEL_CDBM, "", "" },
  106. /* Mark a path to visit later */
  107. { 'B', SEL_PIN, "", "" },
  108. /* Visit marked directory */
  109. { CONTROL('V'), SEL_VISIT, "", "" },
  110. /* Filter */
  111. { '/', SEL_FLTR, "", "" },
  112. /* Toggle filter mode */
  113. { KEY_IC, SEL_MFLTR, "", "" },
  114. /* Desktop search */
  115. { CONTROL('_'), SEL_SEARCH, "", "" },
  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. /* List archive */
  129. { 'F', SEL_LIST, "-l", "" },
  130. /* Extract archive */
  131. { CONTROL('F'), SEL_EXTRACT, "-x", "" },
  132. /* Toggle sort by size */
  133. { 's', SEL_FSIZE, "", "" },
  134. /* Sort by total block count including dir contents */
  135. { 'S', SEL_BSIZE, "", "" },
  136. { CONTROL('J'), SEL_BSIZE, "", "" },
  137. /* Toggle sort by time */
  138. { 't', SEL_MTIME, "", "" },
  139. /* Redraw window */
  140. { CONTROL('L'), SEL_REDRAW, "", "" },
  141. { KEY_F(5), SEL_REDRAW, "", "" }, /* Undocumented */
  142. /* Copy currently selected file path */
  143. { CONTROL('K'), SEL_COPY, "", "" },
  144. /* Toggle copy multiple file paths */
  145. { CONTROL('Y'), SEL_COPYMUL, "", "" },
  146. /* Open in a custom application */
  147. { CONTROL('O'), SEL_OPEN, "", "" },
  148. /* Create a new file */
  149. { 'n', SEL_NEW, "", "" },
  150. /* Show rename prompt */
  151. { CONTROL('R'), SEL_RENAME, "", "" },
  152. { KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
  153. /* Show help */
  154. { '?', SEL_HELP, "", "" },
  155. /* Run command */
  156. { '!', SEL_RUN, "sh", "SHELL" },
  157. /* Run command with argument */
  158. { 'e', SEL_RUNARG, "vi", "EDITOR" },
  159. { 'p', SEL_RUNARG, "less", "PAGER" },
  160. /* Change dir on quit */
  161. { 'Q', SEL_CDQUIT, "", "" },
  162. /* Quit */
  163. { 'q', SEL_QUIT, "", "" },
  164. { CONTROL('X'), SEL_QUIT, "", "" },
  165. };