1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/* See LICENSE file for copyright and license details. */
#define CONTROL(c) ((c) ^ 0x40)
/* Supported actions */
enum action {
SEL_BACK = 1,
SEL_GOIN,
SEL_NEXT,
SEL_PREV,
SEL_PGDN,
SEL_PGUP,
SEL_HOME,
SEL_END,
SEL_CD,
SEL_CDHOME,
SEL_CDBEGIN,
SEL_CDLAST,
SEL_CDBM,
SEL_PIN,
SEL_VISIT,
SEL_FLTR,
SEL_MFLTR,
SEL_SEARCH,
SEL_TOGGLEDOT,
SEL_DETAIL,
SEL_STATS,
SEL_MEDIA,
SEL_FMEDIA,
SEL_DFB,
SEL_ARCHIVE,
SEL_LIST,
SEL_EXTRACT,
SEL_FSIZE,
SEL_BSIZE,
SEL_MTIME,
SEL_REDRAW,
SEL_COPY,
SEL_COPYMUL,
SEL_QUOTE,
SEL_OPEN,
SEL_NEW,
SEL_RENAME,
SEL_RENAMEALL,
SEL_HELP,
SEL_RUN,
SEL_RUNSCRIPT,
SEL_RUNARG,
#ifdef __linux__
SEL_LOCK,
#endif
SEL_CDQUIT,
SEL_QUIT,
};
/* Associate a pressed key to an action */
struct key {
int sym; /* Key pressed */
enum action act; /* Action */
char *run; /* Program to run or program option */
char *env; /* Environment variable to run */
};
/* Extension pattern and mime combination */
struct assoc {
char *regex; /* Regex to match on filename */
char *mime; /* File type */
};
static struct assoc assocs[] = {
{ "\\.(c|cpp|h|log|md|py|rb|sh|txt)$", "text" },
};
static struct key bindings[] = {
/* Back */
{ KEY_BACKSPACE, SEL_BACK, "", "" },
{ KEY_LEFT, SEL_BACK, "", "" },
{ 'h', SEL_BACK, "", "" },
{ CONTROL('H'), SEL_BACK, "", "" },
/* Inside */
{ KEY_ENTER, SEL_GOIN, "", "" },
{ '\r', SEL_GOIN, "", "" },
{ KEY_RIGHT, SEL_GOIN, "", "" },
{ 'l', SEL_GOIN, "", "" },
/* Next */
{ 'j', SEL_NEXT, "", "" },
{ KEY_DOWN, SEL_NEXT, "", "" },
{ CONTROL('N'), SEL_NEXT, "", "" },
/* Previous */
{ 'k', SEL_PREV, "", "" },
{ KEY_UP, SEL_PREV, "", "" },
{ CONTROL('P'), SEL_PREV, "", "" },
/* Page down */
{ KEY_NPAGE, SEL_PGDN, "", "" },
{ CONTROL('D'), SEL_PGDN, "", "" },
/* Page up */
{ KEY_PPAGE, SEL_PGUP, "", "" },
{ CONTROL('U'), SEL_PGUP, "", "" },
/* First entry */
{ KEY_HOME, SEL_HOME, "", "" },
{ 'g', SEL_HOME, "", "" },
{ CONTROL('A'), SEL_HOME, "", "" },
{ '^', SEL_HOME, "", "" },
/* Last entry */
{ KEY_END, SEL_END, "", "" },
{ 'G', SEL_END, "", "" },
{ CONTROL('E'), SEL_END, "", "" },
{ '$', SEL_END, "", "" },
/* Change dir */
{ 'c', SEL_CD, "", "" },
/* HOME */
{ '~', SEL_CDHOME, "", "" },
/* Initial directory */
{ '&', SEL_CDBEGIN, "", "" },
/* Last visited dir */
{ '-', SEL_CDLAST, "", "" },
/* Change dir using bookmark */
{ CONTROL('B'), SEL_CDBM, "", "" },
/* Mark a path to visit later */
{ 'b', SEL_PIN, "", "" },
/* Visit marked directory */
{ CONTROL('V'), SEL_VISIT, "", "" },
/* Filter */
{ '/', SEL_FLTR, "", "" },
/* Toggle filter mode */
{ KEY_IC, SEL_MFLTR, "", "" },
{ CONTROL('I'), SEL_MFLTR, "", "" },
/* Desktop search */
{ CONTROL('_'), SEL_SEARCH, "", "" },
/* Toggle hide .dot files */
{ '.', SEL_TOGGLEDOT, "", "" },
/* Detailed listing */
{ 'd', SEL_DETAIL, "", "" },
/* File details */
{ 'D', SEL_STATS, "", "" },
/* Show media info short, run is hacked */
{ 'm', SEL_MEDIA, NULL, "" },
/* Show media info full, run is hacked */
{ 'M', SEL_FMEDIA, "-f", "" },
/* Open dir in desktop file manager */
{ 'o', SEL_DFB, "", "" },
/* Create archive */
{ 'f', SEL_ARCHIVE, "", "" },
/* List archive */
{ 'F', SEL_LIST, "-l", "" },
/* Extract archive */
{ CONTROL('F'), SEL_EXTRACT, "-x", "" },
/* Toggle sort by size */
{ 's', SEL_FSIZE, "", "" },
/* Sort by total block count including dir contents */
{ 'S', SEL_BSIZE, "", "" },
{ CONTROL('J'), SEL_BSIZE, "", "" },
/* Toggle sort by time */
{ 't', SEL_MTIME, "", "" },
/* Redraw window */
{ CONTROL('L'), SEL_REDRAW, "", "" },
{ KEY_F(5), SEL_REDRAW, "", "" }, /* Undocumented */
/* Copy currently selected file path */
{ CONTROL('K'), SEL_COPY, "", "" },
{ ' ', SEL_COPY, "", "" },
/* Toggle copy multiple file paths */
{ CONTROL('Y'), SEL_COPYMUL, "", "" },
/* Toggle quote on while copy */
{ CONTROL('T'), SEL_QUOTE, "", "" },
/* Open in a custom application */
{ CONTROL('O'), SEL_OPEN, "", "" },
/* Create a new file */
{ 'n', SEL_NEW, "", "" },
/* Show rename prompt */
{ CONTROL('R'), SEL_RENAME, "", "" },
{ KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
/* Rename contents of current dir */
{ 'r', SEL_RENAMEALL, "", "" },
/* Show help */
{ '?', SEL_HELP, "", "" },
/* Run command */
{ '!', SEL_RUN, "sh", "SHELL" },
{ CONTROL(']'), SEL_RUN, "sh", "SHELL" },
/* Run a custom script */
{ 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
/* Run command with argument */
{ 'e', SEL_RUNARG, "", "VISUAL" },
{ 'p', SEL_RUNARG, "less", "PAGER" },
#ifdef __linux__
/* Lock screen */
{ 'L', SEL_LOCK, "", "" },
#endif
/* Change dir on quit */
{ 'Q', SEL_CDQUIT, "", "" },
{ CONTROL('G'), SEL_CDQUIT, "", "" },
/* Quit */
{ 'q', SEL_QUIT, "", "" },
{ CONTROL('X'), SEL_QUIT, "", "" },
};
|