My build of nnn with minor changes
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

219 рядки
7.2 KiB

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