My build of nnn with minor changes
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

226 wiersze
7.4 KiB

  1. /*
  2. * BSD 2-Clause License
  3. *
  4. * Copyright (c) 2014-2016, Lazaros Koromilas <lostd@2f30.org>
  5. * Copyright (c) 2014-2016, Dimitris Papastamos <sin@2f30.org>
  6. * Copyright (c) 2016-2018, Arun Prakash Jana <engineerarun@gmail.com>
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #pragma once
  31. #include <curses.h>
  32. #define CONTROL(c) ((c) ^ 0x40)
  33. /* Supported actions */
  34. enum action {
  35. SEL_BACK = 1,
  36. SEL_GOIN,
  37. SEL_NEXT,
  38. SEL_PREV,
  39. SEL_PGDN,
  40. SEL_PGUP,
  41. SEL_HOME,
  42. SEL_END,
  43. SEL_CDHOME,
  44. SEL_CDBEGIN,
  45. SEL_CDLAST,
  46. SEL_CDBM,
  47. SEL_PIN,
  48. SEL_VISIT,
  49. SEL_FLTR,
  50. SEL_MFLTR,
  51. SEL_TOGGLEDOT,
  52. SEL_DETAIL,
  53. SEL_STATS,
  54. SEL_MEDIA,
  55. SEL_FMEDIA,
  56. SEL_LAUNCH,
  57. SEL_ARCHIVE,
  58. SEL_LIST,
  59. SEL_EXTRACT,
  60. SEL_FSIZE, /* file size */
  61. SEL_ASIZE, /* apparent size */
  62. SEL_BSIZE, /* block size */
  63. SEL_MTIME,
  64. SEL_REDRAW,
  65. SEL_COPY,
  66. SEL_COPYMUL,
  67. SEL_COPYLIST,
  68. SEL_QUOTE,
  69. SEL_OPEN,
  70. SEL_NEW,
  71. SEL_RENAME,
  72. SEL_RENAMEALL,
  73. SEL_HELP,
  74. SEL_RUN,
  75. SEL_RUNSCRIPT,
  76. SEL_RUNARG,
  77. SEL_LOCK,
  78. SEL_QUITCTX,
  79. SEL_CDQUIT,
  80. SEL_QUIT,
  81. };
  82. /* Associate a pressed key to an action */
  83. struct key {
  84. int sym; /* Key pressed */
  85. enum action act; /* Action */
  86. char *run; /* Program to run or program option */
  87. char *env; /* Environment variable to run */
  88. };
  89. /* Extension pattern and mime combination */
  90. struct assoc {
  91. char *regex; /* Regex to match on filename */
  92. char *mime; /* File type */
  93. };
  94. static struct assoc assocs[] = {
  95. { "\\.(c|cpp|h|log|md|py|rb|sh|txt)$", "text" },
  96. };
  97. static struct key bindings[] = {
  98. /* Back */
  99. { KEY_BACKSPACE, SEL_BACK, "", "" },
  100. { 8 /* BS */, SEL_BACK, "", "" },
  101. { 127 /* DEL */, SEL_BACK, "", "" },
  102. { KEY_LEFT, SEL_BACK, "", "" },
  103. { 'h', SEL_BACK, "", "" },
  104. { CONTROL('H'), SEL_BACK, "", "" },
  105. /* Inside */
  106. { KEY_ENTER, SEL_GOIN, "", "" },
  107. { '\r', SEL_GOIN, "", "" },
  108. { KEY_RIGHT, SEL_GOIN, "", "" },
  109. { 'l', SEL_GOIN, "", "" },
  110. /* Next */
  111. { 'j', SEL_NEXT, "", "" },
  112. { KEY_DOWN, SEL_NEXT, "", "" },
  113. { CONTROL('N'), SEL_NEXT, "", "" },
  114. /* Previous */
  115. { 'k', SEL_PREV, "", "" },
  116. { KEY_UP, SEL_PREV, "", "" },
  117. { CONTROL('P'), SEL_PREV, "", "" },
  118. /* Page down */
  119. { KEY_NPAGE, SEL_PGDN, "", "" },
  120. { CONTROL('D'), SEL_PGDN, "", "" },
  121. /* Page up */
  122. { KEY_PPAGE, SEL_PGUP, "", "" },
  123. { CONTROL('U'), SEL_PGUP, "", "" },
  124. /* First entry */
  125. { KEY_HOME, SEL_HOME, "", "" },
  126. { 'g', SEL_HOME, "", "" },
  127. { CONTROL('A'), SEL_HOME, "", "" },
  128. { '^', SEL_HOME, "", "" },
  129. /* Last entry */
  130. { KEY_END, SEL_END, "", "" },
  131. { 'G', SEL_END, "", "" },
  132. { CONTROL('E'), SEL_END, "", "" },
  133. { '$', SEL_END, "", "" },
  134. /* HOME */
  135. { '~', SEL_CDHOME, "", "" },
  136. /* Initial directory */
  137. { '&', SEL_CDBEGIN, "", "" },
  138. /* Last visited dir */
  139. { '-', SEL_CDLAST, "", "" },
  140. /* Change dir using bookmark */
  141. { CONTROL('B'), SEL_CDBM, "", "" },
  142. /* Mark a path to visit later */
  143. { 'b', SEL_PIN, "", "" },
  144. /* Visit marked directory */
  145. { CONTROL('V'), SEL_VISIT, "", "" },
  146. /* Filter */
  147. { '/', SEL_FLTR, "", "" },
  148. /* Toggle filter mode */
  149. { KEY_IC, SEL_MFLTR, "", "" },
  150. { CONTROL('I'), SEL_MFLTR, "", "" },
  151. /* Toggle hide .dot files */
  152. { '.', SEL_TOGGLEDOT, "", "" },
  153. /* Detailed listing */
  154. { 'd', SEL_DETAIL, "", "" },
  155. /* File details */
  156. { 'D', SEL_STATS, "", "" },
  157. /* Show media info short, run is hacked */
  158. { 'm', SEL_MEDIA, NULL, "" },
  159. /* Show media info full, run is hacked */
  160. { 'M', SEL_FMEDIA, "-f", "" },
  161. /* Launch a GUI application */
  162. { 'o', SEL_LAUNCH, "", "" },
  163. /* Create archive */
  164. { 'f', SEL_ARCHIVE, "", "" },
  165. /* List archive */
  166. { 'F', SEL_LIST, "-l", "" },
  167. /* Extract archive */
  168. { CONTROL('F'), SEL_EXTRACT, "-x", "" },
  169. /* Toggle sort by size */
  170. { 's', SEL_FSIZE, "", "" },
  171. /* Sort by apparent size including dir contents */
  172. { 'S', SEL_ASIZE, "", "" },
  173. /* Sort by total block count including dir contents */
  174. { CONTROL('J'), SEL_BSIZE, "", "" },
  175. /* Toggle sort by time */
  176. { 't', SEL_MTIME, "", "" },
  177. /* Redraw window */
  178. { CONTROL('L'), SEL_REDRAW, "", "" },
  179. { KEY_F(5), SEL_REDRAW, "", "" }, /* Undocumented */
  180. /* Copy currently selected file path */
  181. { CONTROL('K'), SEL_COPY, "", "" },
  182. { ' ', SEL_COPY, "", "" },
  183. /* Toggle copy multiple file paths */
  184. { CONTROL('Y'), SEL_COPYMUL, "", "" },
  185. /* Show list of copied files */
  186. { 'y', SEL_COPYLIST, "", "" },
  187. /* Toggle quote on while copy */
  188. { CONTROL('T'), SEL_QUOTE, "", "" },
  189. /* Open in a custom application */
  190. { CONTROL('O'), SEL_OPEN, "", "" },
  191. /* Create a new file */
  192. { 'n', SEL_NEW, "", "" },
  193. /* Show rename prompt */
  194. { CONTROL('R'), SEL_RENAME, "", "" },
  195. { KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
  196. /* Rename contents of current dir */
  197. { 'r', SEL_RENAMEALL, "", "" },
  198. /* Show help */
  199. { '?', SEL_HELP, "", "" },
  200. /* Run command */
  201. { '!', SEL_RUN, "sh", "SHELL" },
  202. { CONTROL(']'), SEL_RUN, "sh", "SHELL" },
  203. /* Run a custom script */
  204. { 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
  205. /* Run command with argument */
  206. { 'e', SEL_RUNARG, "", "VISUAL" },
  207. { 'p', SEL_RUNARG, "less", "PAGER" },
  208. /* Lock screen */
  209. { 'L', SEL_LOCK, "", "" },
  210. /* Quit a context */
  211. { 'q', SEL_QUITCTX, "", "" },
  212. /* Change dir on quit */
  213. { CONTROL('G'), SEL_CDQUIT, "", "" },
  214. /* Quit */
  215. { 'Q', SEL_QUIT, "", "" },
  216. { CONTROL('X'), SEL_QUIT, "", "" },
  217. };