2018-09-07 15:50:10 +00:00
|
|
|
/*
|
2018-10-04 19:08:57 +00:00
|
|
|
* BSD 2-Clause License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014-2016, Lazaros Koromilas <lostd@2f30.org>
|
|
|
|
* Copyright (c) 2014-2016, Dimitris Papastamos <sin@2f30.org>
|
|
|
|
* Copyright (c) 2016-2018, Arun Prakash Jana <engineerarun@gmail.com>
|
2018-09-07 15:50:10 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2018-10-04 19:08:57 +00:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
2018-09-07 15:50:10 +00:00
|
|
|
*
|
2018-10-04 19:08:57 +00:00
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
2018-09-07 15:50:10 +00:00
|
|
|
*
|
2018-10-04 19:08:57 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2018-09-07 15:50:10 +00:00
|
|
|
*/
|
|
|
|
|
2018-11-03 08:20:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <curses.h>
|
|
|
|
|
2017-06-20 04:56:31 +00:00
|
|
|
#define CONTROL(c) ((c) ^ 0x40)
|
2014-10-21 10:35:08 +00:00
|
|
|
|
2017-06-20 04:56:31 +00:00
|
|
|
/* Supported actions */
|
|
|
|
enum action {
|
2017-12-12 20:16:50 +00:00
|
|
|
SEL_BACK = 1,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_GOIN,
|
|
|
|
SEL_NEXT,
|
|
|
|
SEL_PREV,
|
|
|
|
SEL_PGDN,
|
|
|
|
SEL_PGUP,
|
|
|
|
SEL_HOME,
|
|
|
|
SEL_END,
|
|
|
|
SEL_CDHOME,
|
|
|
|
SEL_CDBEGIN,
|
|
|
|
SEL_CDLAST,
|
|
|
|
SEL_CDBM,
|
2017-09-01 14:27:36 +00:00
|
|
|
SEL_PIN,
|
2017-08-20 11:17:23 +00:00
|
|
|
SEL_VISIT,
|
2017-12-12 20:16:50 +00:00
|
|
|
SEL_FLTR,
|
|
|
|
SEL_MFLTR,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_TOGGLEDOT,
|
|
|
|
SEL_DETAIL,
|
|
|
|
SEL_STATS,
|
|
|
|
SEL_MEDIA,
|
|
|
|
SEL_FMEDIA,
|
2018-11-08 01:36:09 +00:00
|
|
|
SEL_LAUNCH,
|
2018-04-24 23:34:37 +00:00
|
|
|
SEL_ARCHIVE,
|
2017-09-27 14:49:42 +00:00
|
|
|
SEL_LIST,
|
|
|
|
SEL_EXTRACT,
|
2018-10-04 18:56:31 +00:00
|
|
|
SEL_FSIZE, /* file size */
|
|
|
|
SEL_ASIZE, /* apparent size */
|
|
|
|
SEL_BSIZE, /* block size */
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_MTIME,
|
|
|
|
SEL_REDRAW,
|
|
|
|
SEL_COPY,
|
2018-01-13 20:13:30 +00:00
|
|
|
SEL_COPYMUL,
|
2018-10-22 14:03:27 +00:00
|
|
|
SEL_COPYLIST,
|
2018-01-28 06:03:12 +00:00
|
|
|
SEL_QUOTE,
|
2017-12-25 10:25:53 +00:00
|
|
|
SEL_OPEN,
|
2017-09-10 07:35:25 +00:00
|
|
|
SEL_NEW,
|
2017-08-22 19:16:58 +00:00
|
|
|
SEL_RENAME,
|
2018-02-24 14:16:58 +00:00
|
|
|
SEL_RENAMEALL,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_HELP,
|
|
|
|
SEL_RUN,
|
2018-03-19 00:02:16 +00:00
|
|
|
SEL_RUNSCRIPT,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_RUNARG,
|
2018-03-30 15:53:28 +00:00
|
|
|
SEL_LOCK,
|
2017-12-12 20:16:50 +00:00
|
|
|
SEL_CDQUIT,
|
|
|
|
SEL_QUIT,
|
2017-06-20 04:56:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Associate a pressed key to an action */
|
|
|
|
struct key {
|
|
|
|
int sym; /* Key pressed */
|
|
|
|
enum action act; /* Action */
|
2017-09-27 14:49:42 +00:00
|
|
|
char *run; /* Program to run or program option */
|
2017-06-20 04:56:31 +00:00
|
|
|
char *env; /* Environment variable to run */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Extension pattern and mime combination */
|
|
|
|
struct assoc {
|
|
|
|
char *regex; /* Regex to match on filename */
|
|
|
|
char *mime; /* File type */
|
|
|
|
};
|
2015-02-04 12:32:16 +00:00
|
|
|
|
2017-04-23 17:42:54 +00:00
|
|
|
static struct assoc assocs[] = {
|
2018-03-03 04:00:03 +00:00
|
|
|
{ "\\.(c|cpp|h|log|md|py|rb|sh|txt)$", "text" },
|
2014-10-21 10:15:27 +00:00
|
|
|
};
|
2014-11-06 11:46:37 +00:00
|
|
|
|
2017-04-23 17:42:54 +00:00
|
|
|
static struct key bindings[] = {
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Back */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ KEY_BACKSPACE, SEL_BACK, "", "" },
|
2018-11-02 23:03:55 +00:00
|
|
|
{ 8 /* BS */, SEL_BACK, "", "" },
|
|
|
|
{ 127 /* DEL */, SEL_BACK, "", "" },
|
2017-04-03 17:03:46 +00:00
|
|
|
{ KEY_LEFT, SEL_BACK, "", "" },
|
|
|
|
{ 'h', SEL_BACK, "", "" },
|
|
|
|
{ CONTROL('H'), SEL_BACK, "", "" },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Inside */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ KEY_ENTER, SEL_GOIN, "", "" },
|
|
|
|
{ '\r', SEL_GOIN, "", "" },
|
|
|
|
{ KEY_RIGHT, SEL_GOIN, "", "" },
|
|
|
|
{ 'l', SEL_GOIN, "", "" },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Next */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ 'j', SEL_NEXT, "", "" },
|
|
|
|
{ KEY_DOWN, SEL_NEXT, "", "" },
|
|
|
|
{ CONTROL('N'), SEL_NEXT, "", "" },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Previous */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ 'k', SEL_PREV, "", "" },
|
|
|
|
{ KEY_UP, SEL_PREV, "", "" },
|
|
|
|
{ CONTROL('P'), SEL_PREV, "", "" },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Page down */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ KEY_NPAGE, SEL_PGDN, "", "" },
|
|
|
|
{ CONTROL('D'), SEL_PGDN, "", "" },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Page up */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ KEY_PPAGE, SEL_PGUP, "", "" },
|
|
|
|
{ CONTROL('U'), SEL_PGUP, "", "" },
|
2017-04-23 21:06:49 +00:00
|
|
|
/* First entry */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ KEY_HOME, SEL_HOME, "", "" },
|
2017-04-04 03:46:29 +00:00
|
|
|
{ 'g', SEL_HOME, "", "" },
|
2017-04-03 17:03:46 +00:00
|
|
|
{ CONTROL('A'), SEL_HOME, "", "" },
|
|
|
|
{ '^', SEL_HOME, "", "" },
|
2017-04-23 21:06:49 +00:00
|
|
|
/* Last entry */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ KEY_END, SEL_END, "", "" },
|
2017-04-04 03:46:29 +00:00
|
|
|
{ 'G', SEL_END, "", "" },
|
2017-04-03 17:03:46 +00:00
|
|
|
{ CONTROL('E'), SEL_END, "", "" },
|
|
|
|
{ '$', SEL_END, "", "" },
|
2017-04-08 08:16:03 +00:00
|
|
|
/* HOME */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ '~', SEL_CDHOME, "", "" },
|
2017-04-23 21:06:49 +00:00
|
|
|
/* Initial directory */
|
|
|
|
{ '&', SEL_CDBEGIN, "", "" },
|
2017-04-08 08:16:03 +00:00
|
|
|
/* Last visited dir */
|
2017-04-25 04:31:52 +00:00
|
|
|
{ '-', SEL_CDLAST, "", "" },
|
2017-06-11 04:15:50 +00:00
|
|
|
/* Change dir using bookmark */
|
2018-01-07 03:44:25 +00:00
|
|
|
{ CONTROL('B'), SEL_CDBM, "", "" },
|
2017-08-20 11:17:23 +00:00
|
|
|
/* Mark a path to visit later */
|
2018-01-17 14:02:22 +00:00
|
|
|
{ 'b', SEL_PIN, "", "" },
|
2017-08-20 11:17:23 +00:00
|
|
|
/* Visit marked directory */
|
|
|
|
{ CONTROL('V'), SEL_VISIT, "", "" },
|
2017-12-12 20:16:50 +00:00
|
|
|
/* Filter */
|
|
|
|
{ '/', SEL_FLTR, "", "" },
|
|
|
|
/* Toggle filter mode */
|
|
|
|
{ KEY_IC, SEL_MFLTR, "", "" },
|
2018-03-07 13:02:48 +00:00
|
|
|
{ CONTROL('I'), SEL_MFLTR, "", "" },
|
2016-02-25 14:54:41 +00:00
|
|
|
/* Toggle hide .dot files */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ '.', SEL_TOGGLEDOT, "", "" },
|
2017-03-29 20:21:52 +00:00
|
|
|
/* Detailed listing */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ 'd', SEL_DETAIL, "", "" },
|
2017-04-02 23:35:14 +00:00
|
|
|
/* File details */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ 'D', SEL_STATS, "", "" },
|
2017-07-02 18:27:41 +00:00
|
|
|
/* Show media info short, run is hacked */
|
|
|
|
{ 'm', SEL_MEDIA, NULL, "" },
|
|
|
|
/* Show media info full, run is hacked */
|
|
|
|
{ 'M', SEL_FMEDIA, "-f", "" },
|
2018-11-08 01:36:09 +00:00
|
|
|
/* Launch a GUI application */
|
|
|
|
{ 'o', SEL_LAUNCH, "", "" },
|
2018-04-24 23:34:37 +00:00
|
|
|
/* Create archive */
|
|
|
|
{ 'f', SEL_ARCHIVE, "", "" },
|
2017-09-27 14:49:42 +00:00
|
|
|
/* List archive */
|
2018-03-30 15:53:28 +00:00
|
|
|
{ 'F', SEL_LIST, "-l", "" },
|
2017-09-27 14:49:42 +00:00
|
|
|
/* Extract archive */
|
2018-03-30 15:53:28 +00:00
|
|
|
{ CONTROL('F'), SEL_EXTRACT, "-x", "" },
|
2017-03-29 20:21:52 +00:00
|
|
|
/* Toggle sort by size */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ 's', SEL_FSIZE, "", "" },
|
2018-10-04 18:56:31 +00:00
|
|
|
/* Sort by apparent size including dir contents */
|
|
|
|
{ 'S', SEL_ASIZE, "", "" },
|
2017-06-22 04:09:17 +00:00
|
|
|
/* Sort by total block count including dir contents */
|
2018-01-09 08:51:09 +00:00
|
|
|
{ CONTROL('J'), SEL_BSIZE, "", "" },
|
2015-02-05 15:53:50 +00:00
|
|
|
/* Toggle sort by time */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ 't', SEL_MTIME, "", "" },
|
2017-08-20 11:17:23 +00:00
|
|
|
/* Redraw window */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ CONTROL('L'), SEL_REDRAW, "", "" },
|
2017-09-10 07:35:25 +00:00
|
|
|
{ KEY_F(5), SEL_REDRAW, "", "" }, /* Undocumented */
|
2017-03-30 15:47:00 +00:00
|
|
|
/* Copy currently selected file path */
|
2017-04-03 17:03:46 +00:00
|
|
|
{ CONTROL('K'), SEL_COPY, "", "" },
|
2018-06-27 15:08:41 +00:00
|
|
|
{ ' ', SEL_COPY, "", "" },
|
2018-01-13 20:13:30 +00:00
|
|
|
/* Toggle copy multiple file paths */
|
|
|
|
{ CONTROL('Y'), SEL_COPYMUL, "", "" },
|
2018-10-22 14:03:27 +00:00
|
|
|
/* Show list of copied files */
|
|
|
|
{ 'y', SEL_COPYLIST, "", "" },
|
2018-01-28 06:03:12 +00:00
|
|
|
/* Toggle quote on while copy */
|
|
|
|
{ CONTROL('T'), SEL_QUOTE, "", "" },
|
2017-12-25 10:25:53 +00:00
|
|
|
/* Open in a custom application */
|
|
|
|
{ CONTROL('O'), SEL_OPEN, "", "" },
|
2017-09-10 07:35:25 +00:00
|
|
|
/* Create a new file */
|
|
|
|
{ 'n', SEL_NEW, "", "" },
|
2017-08-22 19:16:58 +00:00
|
|
|
/* Show rename prompt */
|
|
|
|
{ CONTROL('R'), SEL_RENAME, "", "" },
|
2017-09-10 07:35:25 +00:00
|
|
|
{ KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
|
2018-02-24 14:16:58 +00:00
|
|
|
/* Rename contents of current dir */
|
2018-03-19 00:02:16 +00:00
|
|
|
{ 'r', SEL_RENAMEALL, "", "" },
|
2017-04-03 17:03:46 +00:00
|
|
|
/* Show help */
|
|
|
|
{ '?', SEL_HELP, "", "" },
|
2015-03-12 14:12:01 +00:00
|
|
|
/* Run command */
|
2017-04-01 09:11:07 +00:00
|
|
|
{ '!', SEL_RUN, "sh", "SHELL" },
|
2018-03-30 15:23:25 +00:00
|
|
|
{ CONTROL(']'), SEL_RUN, "sh", "SHELL" },
|
2018-03-19 00:02:16 +00:00
|
|
|
/* Run a custom script */
|
|
|
|
{ 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
|
2015-03-12 14:12:01 +00:00
|
|
|
/* Run command with argument */
|
2018-04-08 00:43:33 +00:00
|
|
|
{ 'e', SEL_RUNARG, "", "VISUAL" },
|
2017-04-01 09:11:07 +00:00
|
|
|
{ 'p', SEL_RUNARG, "less", "PAGER" },
|
2018-03-30 15:53:28 +00:00
|
|
|
/* Lock screen */
|
|
|
|
{ 'L', SEL_LOCK, "", "" },
|
2017-12-12 20:16:50 +00:00
|
|
|
/* Change dir on quit */
|
|
|
|
{ 'Q', SEL_CDQUIT, "", "" },
|
2018-02-24 16:13:41 +00:00
|
|
|
{ CONTROL('G'), SEL_CDQUIT, "", "" },
|
2017-12-12 20:16:50 +00:00
|
|
|
/* Quit */
|
|
|
|
{ 'q', SEL_QUIT, "", "" },
|
2018-01-13 03:58:29 +00:00
|
|
|
{ CONTROL('X'), SEL_QUIT, "", "" },
|
2014-11-06 11:46:37 +00:00
|
|
|
};
|