Add keybindings config
This commit is contained in:
parent
addc8e2c9d
commit
8ae48c285b
2 changed files with 167 additions and 58 deletions
169
ccc.c
169
ccc.c
|
@ -17,6 +17,8 @@
|
||||||
#include "icons.h"
|
#include "icons.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
||||||
|
|
||||||
/* Keybindings */
|
/* Keybindings */
|
||||||
enum keys {
|
enum keys {
|
||||||
CTRLD = 0x04,
|
CTRLD = 0x04,
|
||||||
|
@ -36,14 +38,65 @@ enum keys {
|
||||||
PAGE_DOWN,
|
PAGE_DOWN,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum action {
|
||||||
|
ACT_QUIT = 1,
|
||||||
|
ACT_RELOAD,
|
||||||
|
ACT_BACK,
|
||||||
|
ACT_ENTER,
|
||||||
|
ACT_JUMP_UP,
|
||||||
|
ACT_JUMP_DOWN,
|
||||||
|
ACT_UP,
|
||||||
|
ACT_DOWN,
|
||||||
|
ACT_BOTTOM,
|
||||||
|
ACT_TOP,
|
||||||
|
ACT_HOME,
|
||||||
|
ACT_TRASH_DIR,
|
||||||
|
ACT_SORT,
|
||||||
|
ACT_SHOW_DIR_SIZE,
|
||||||
|
ACT_PREV_DIR,
|
||||||
|
ACT_SHOW_HELP,
|
||||||
|
ACT_HIDDEN_FILES,
|
||||||
|
ACT_FILE_DETAILS,
|
||||||
|
ACT_SHOW_ICONS,
|
||||||
|
ACT_CREATE_FILE,
|
||||||
|
ACT_CREATE_DIR,
|
||||||
|
ACT_RENAME_FILE,
|
||||||
|
ACT_GOTO_DIR,
|
||||||
|
ACT_TOGGLE_EXE,
|
||||||
|
ACT_START_SHELL,
|
||||||
|
ACT_COPY_FILENAME,
|
||||||
|
ACT_OPEN_FILE,
|
||||||
|
ACT_OPEN_FILE_DETACHED,
|
||||||
|
ACT_VIEW_FILE_ATTR,
|
||||||
|
ACT_SHOW_HIST,
|
||||||
|
ACT_FAV1,
|
||||||
|
ACT_FAV2,
|
||||||
|
ACT_FAV3,
|
||||||
|
ACT_FAV4,
|
||||||
|
ACT_FAV5,
|
||||||
|
ACT_FAV6,
|
||||||
|
ACT_FAV7,
|
||||||
|
ACT_FAV8,
|
||||||
|
ACT_FAV9,
|
||||||
|
ACT_MARK_FILE,
|
||||||
|
ACT_MARK_ALL,
|
||||||
|
ACT_DELETE,
|
||||||
|
ACT_MOVE,
|
||||||
|
ACT_COPY,
|
||||||
|
ACT_SYM_LINK,
|
||||||
|
ACT_BULK_RENAME,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int key;
|
int key;
|
||||||
|
enum action act;
|
||||||
} key;
|
} key;
|
||||||
|
|
||||||
#define PATH_MAX 4096 /* Max length of path */
|
#define PATH_MAX 4096 /* Max length of path */
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
int getsel(void);
|
||||||
void handle_sigwinch(int ignore);
|
void handle_sigwinch(int ignore);
|
||||||
void cleanup(void);
|
void cleanup(void);
|
||||||
void show_help(void);
|
void show_help(void);
|
||||||
|
@ -82,7 +135,7 @@ void bprintf(const char *fmt, ...);
|
||||||
/* global variables */
|
/* global variables */
|
||||||
unsigned int focus = 0;
|
unsigned int focus = 0;
|
||||||
long sel_file = 0;
|
long sel_file = 0;
|
||||||
int file_picker = 1;
|
int file_picker = 0;
|
||||||
int to_open_file = 0;
|
int to_open_file = 0;
|
||||||
char argv_cp[PATH_MAX];
|
char argv_cp[PATH_MAX];
|
||||||
char cwd[PATH_MAX];
|
char cwd[PATH_MAX];
|
||||||
|
@ -171,13 +224,13 @@ int main(int argc, char **argv)
|
||||||
sel_file = arraylist_search(files, argv_cp, 1);
|
sel_file = arraylist_search(files, argv_cp, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ch, run = 1;
|
int run = 1;
|
||||||
while (run) {
|
while (run) {
|
||||||
list_files();
|
list_files();
|
||||||
ch = readch();
|
int sel = getsel();
|
||||||
switch (ch) {
|
switch (sel) {
|
||||||
/* quit */
|
/* quit */
|
||||||
case 'q':
|
case ACT_QUIT:
|
||||||
if (write_last_d() == -1) {
|
if (write_last_d() == -1) {
|
||||||
/* prompt user so error message can be shown to user */
|
/* prompt user so error message can be shown to user */
|
||||||
readch();
|
readch();
|
||||||
|
@ -187,14 +240,12 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* reload */
|
/* reload */
|
||||||
case 'z':
|
case ACT_RELOAD:
|
||||||
change_dir(cwd, 0, 0);
|
change_dir(cwd, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go back */
|
/* go back */
|
||||||
case BACKSPACE:;
|
case ACT_BACK:;
|
||||||
case ARROW_LEFT:;
|
|
||||||
case 'h':;
|
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
strcpy(dir, cwd);
|
strcpy(dir, cwd);
|
||||||
/* get parent directory */
|
/* get parent directory */
|
||||||
|
@ -210,9 +261,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* enter directory/open a file */
|
/* enter directory/open a file */
|
||||||
case ENTER:;
|
case ACT_ENTER:;
|
||||||
case ARROW_RIGHT:;
|
|
||||||
case 'l':;
|
|
||||||
file c_file = files->items[sel_file];
|
file c_file = files->items[sel_file];
|
||||||
|
|
||||||
/* Check if it is directory or a regular file */
|
/* Check if it is directory or a regular file */
|
||||||
|
@ -237,47 +286,45 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* jump up */
|
/* jump up */
|
||||||
case CTRLU:
|
case ACT_JUMP_UP:
|
||||||
if ((sel_file - jump_num) > 0)
|
if ((sel_file - jump_num) > 0)
|
||||||
sel_file -= jump_num;
|
sel_file -= jump_num;
|
||||||
else
|
else
|
||||||
sel_file = 0;
|
sel_file = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go up */
|
|
||||||
case ARROW_UP:
|
|
||||||
case 'k':
|
|
||||||
if (sel_file > 0)
|
|
||||||
sel_file--;
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* jump down */
|
/* jump down */
|
||||||
case CTRLD:
|
case ACT_JUMP_DOWN:
|
||||||
if ((sel_file + jump_num) < (files->length - 1))
|
if ((sel_file + jump_num) < (files->length - 1))
|
||||||
sel_file += jump_num;
|
sel_file += jump_num;
|
||||||
else
|
else
|
||||||
sel_file = (files->length - 1);
|
sel_file = (files->length - 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* go up */
|
||||||
|
case ACT_UP:
|
||||||
|
if (sel_file > 0)
|
||||||
|
sel_file--;
|
||||||
|
break;
|
||||||
|
|
||||||
/* go down */
|
/* go down */
|
||||||
case ARROW_DOWN:
|
case ACT_DOWN:
|
||||||
case 'j':
|
|
||||||
if (sel_file < (files->length - 1))
|
if (sel_file < (files->length - 1))
|
||||||
sel_file++;
|
sel_file++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* jump to the bottom */
|
/* jump to the bottom */
|
||||||
case 'G':
|
case ACT_BOTTOM:
|
||||||
sel_file = (files->length - 1);
|
sel_file = (files->length - 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* jump to the top */
|
/* jump to the top */
|
||||||
case 'g':
|
case ACT_TOP:
|
||||||
sel_file = 0;
|
sel_file = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* '~' go to $HOME */
|
/* '~' go to $HOME */
|
||||||
case TILDE:;
|
case ACT_HOME:;
|
||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
if (!home) {
|
if (!home) {
|
||||||
wpprintw("$HOME not defined (Press any key to continue)");
|
wpprintw("$HOME not defined (Press any key to continue)");
|
||||||
|
@ -288,7 +335,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go to the trash dir */
|
/* go to the trash dir */
|
||||||
case 't':;
|
case ACT_TRASH_DIR:;
|
||||||
char *trash_dir = check_trash_dir();
|
char *trash_dir = check_trash_dir();
|
||||||
if (trash_dir) {
|
if (trash_dir) {
|
||||||
change_dir(trash_dir, 0, 0);
|
change_dir(trash_dir, 0, 0);
|
||||||
|
@ -297,92 +344,93 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* sort files */
|
/* sort files */
|
||||||
case 'u':
|
case ACT_SORT:
|
||||||
sort_files();
|
sort_files();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* show directories' sizes */
|
/* show directories' sizes */
|
||||||
case 'A':
|
case ACT_SHOW_DIR_SIZE:
|
||||||
dirs_size = !dirs_size;
|
dirs_size = !dirs_size;
|
||||||
change_dir(cwd, 0, 0);
|
change_dir(cwd, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go to previous dir */
|
/* go to previous dir */
|
||||||
case '-':
|
case ACT_PREV_DIR:
|
||||||
if (strlen(p_cwd) != 0)
|
if (strlen(p_cwd) != 0)
|
||||||
change_dir(p_cwd, 0, 0);
|
change_dir(p_cwd, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* show help */
|
/* show help */
|
||||||
case '?':
|
case ACT_SHOW_HELP:
|
||||||
show_help();
|
show_help();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* toggle hidden files */
|
/* toggle hidden files */
|
||||||
case '.':
|
case ACT_HIDDEN_FILES:
|
||||||
show_hidden = !show_hidden;
|
show_hidden = !show_hidden;
|
||||||
change_dir(cwd, 0, 0);
|
change_dir(cwd, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* toggle file details */
|
/* toggle file details */
|
||||||
case 'i':
|
case ACT_FILE_DETAILS:
|
||||||
show_details = !show_details;
|
show_details = !show_details;
|
||||||
change_dir(cwd, 0, 0);
|
change_dir(cwd, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case ACT_SHOW_ICONS:
|
||||||
show_icons = !show_icons;
|
show_icons = !show_icons;
|
||||||
change_dir(cwd, 0, 0);
|
change_dir(cwd, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case ACT_CREATE_FILE:
|
||||||
create_file();
|
create_file();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case ACT_CREATE_DIR:
|
||||||
create_dir();
|
create_dir();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case ACT_RENAME_FILE:
|
||||||
rename_file();
|
rename_file();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ':':
|
case ACT_GOTO_DIR:
|
||||||
goto_dir();
|
goto_dir();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'X':
|
case ACT_TOGGLE_EXE:
|
||||||
toggle_executable();
|
toggle_executable();
|
||||||
change_dir(cwd, 0, 0);
|
change_dir(cwd, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '!':
|
case ACT_START_SHELL:
|
||||||
start_shell();
|
start_shell();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'y':
|
case ACT_COPY_FILENAME:
|
||||||
yank_clipboard();
|
yank_clipboard();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case ACT_OPEN_FILE:
|
||||||
open_with();
|
open_with();
|
||||||
break;
|
break;
|
||||||
case 'O':
|
|
||||||
|
case ACT_OPEN_FILE_DETACHED:
|
||||||
open_detached();
|
open_detached();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'x':
|
case ACT_VIEW_FILE_ATTR:
|
||||||
view_file_attr();
|
view_file_attr();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'e':
|
case ACT_SHOW_HIST:
|
||||||
show_history();
|
show_history();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '1': case '2': case '3': case '4': case '5': case '6': case '7':
|
case ACT_FAV1: case ACT_FAV2: case ACT_FAV3: case ACT_FAV4: case ACT_FAV5:
|
||||||
case '8': case '9':;
|
case ACT_FAV6: case ACT_FAV7: case ACT_FAV8: case ACT_FAV9:;
|
||||||
char envname[9];
|
char envname[9];
|
||||||
snprintf(envname, 9, "CCC_FAV%d", ch - '0');
|
snprintf(envname, 9, "CCC_FAV%d", sel - ACT_FAV1 + 1);
|
||||||
char *fav = getenv(envname);
|
char *fav = getenv(envname);
|
||||||
if (fav && !strcmp(fav, "")) {
|
if (fav && !strcmp(fav, "")) {
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
|
@ -392,44 +440,44 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* mark one file */
|
/* mark one file */
|
||||||
case SPACE:
|
case ACT_MARK_FILE:
|
||||||
add_file_stat(files->items[sel_file].name, files->items[sel_file].path, 1);
|
add_file_stat(files->items[sel_file].name, files->items[sel_file].path, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* mark all files in directory */
|
/* mark all files in directory */
|
||||||
case 'a':
|
case ACT_MARK_ALL:
|
||||||
change_dir(cwd, sel_file, 2); /* reload current dir */
|
change_dir(cwd, sel_file, 2); /* reload current dir */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* mark actions: */
|
/* mark actions: */
|
||||||
/* delete */
|
/* delete */
|
||||||
case 'd':
|
case ACT_DELETE:
|
||||||
delete_files();
|
delete_files();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* move */
|
/* move */
|
||||||
case 'm':
|
case ACT_MOVE:
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* copy */
|
/* copy */
|
||||||
case 'c':
|
case ACT_COPY:
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* symbolic link */
|
/* symbolic link */
|
||||||
case 's':
|
case ACT_SYM_LINK:
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* bulk rename */
|
/* bulk rename */
|
||||||
case 'b':
|
case ACT_BULK_RENAME:
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -443,6 +491,17 @@ int main(int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getsel(void)
|
||||||
|
{
|
||||||
|
int c = readch();
|
||||||
|
for (int i = 0; i < LEN(keybindings); i++) {
|
||||||
|
if (c == keybindings[i].key) {
|
||||||
|
return keybindings[i].act;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void handle_sigwinch(int ignore)
|
void handle_sigwinch(int ignore)
|
||||||
{
|
{
|
||||||
get_window_size(&rows, &cols);
|
get_window_size(&rows, &cols);
|
||||||
|
|
56
config.h
56
config.h
|
@ -52,8 +52,58 @@ static char last_d[PATH_MAX] = "~/.cache/ccc/.ccc_d";
|
||||||
/* Will create this directory if doesn't exist! */
|
/* Will create this directory if doesn't exist! */
|
||||||
static char trash_dir[PATH_MAX] = "~/.cache/ccc/trash/";
|
static char trash_dir[PATH_MAX] = "~/.cache/ccc/trash/";
|
||||||
|
|
||||||
/*
|
|
||||||
key keybindings[] = {
|
key keybindings[] = {
|
||||||
|
{'q', ACT_QUIT},
|
||||||
|
{'z', ACT_RELOAD},
|
||||||
|
{BACKSPACE, ACT_BACK},
|
||||||
|
{ARROW_LEFT, ACT_BACK},
|
||||||
|
{'h', ACT_BACK},
|
||||||
|
{ENTER, ACT_ENTER},
|
||||||
|
{ARROW_RIGHT, ACT_ENTER},
|
||||||
|
{'l', ACT_ENTER},
|
||||||
|
{CTRLU, ACT_JUMP_UP},
|
||||||
|
{CTRLD, ACT_JUMP_DOWN},
|
||||||
|
{ARROW_DOWN, ACT_DOWN},
|
||||||
|
{ARROW_UP, ACT_UP},
|
||||||
|
{'k', ACT_UP},
|
||||||
|
{'j', ACT_DOWN},
|
||||||
|
{'G', ACT_BOTTOM},
|
||||||
|
{'g', ACT_TOP},
|
||||||
|
{'~', ACT_HOME},
|
||||||
|
{'t', ACT_TRASH_DIR},
|
||||||
|
{'u', ACT_SORT},
|
||||||
|
{'A', ACT_SHOW_DIR_SIZE},
|
||||||
|
{'-', ACT_PREV_DIR},
|
||||||
|
{'?', ACT_SHOW_HELP},
|
||||||
|
{'.', ACT_HIDDEN_FILES},
|
||||||
|
{'i', ACT_FILE_DETAILS},
|
||||||
|
{'w', ACT_SHOW_ICONS},
|
||||||
|
{'f', ACT_CREATE_FILE},
|
||||||
|
{'n', ACT_CREATE_DIR},
|
||||||
|
{'r', ACT_RENAME_FILE},
|
||||||
|
{':', ACT_GOTO_DIR},
|
||||||
|
{'X', ACT_TOGGLE_EXE},
|
||||||
|
{'!', ACT_START_SHELL},
|
||||||
|
{'y', ACT_COPY_FILENAME},
|
||||||
|
{'o', ACT_OPEN_FILE},
|
||||||
|
{'O', ACT_OPEN_FILE_DETACHED},
|
||||||
|
{'x', ACT_VIEW_FILE_ATTR},
|
||||||
|
{'e', ACT_SHOW_HIST},
|
||||||
|
{'1', ACT_FAV1},
|
||||||
|
{'2', ACT_FAV2},
|
||||||
|
{'3', ACT_FAV3},
|
||||||
|
{'4', ACT_FAV4},
|
||||||
|
{'5', ACT_FAV5},
|
||||||
|
{'6', ACT_FAV6},
|
||||||
|
{'7', ACT_FAV7},
|
||||||
|
{'8', ACT_FAV8},
|
||||||
|
{'9', ACT_FAV9},
|
||||||
|
{' ', ACT_MARK_FILE},
|
||||||
|
{'a', ACT_MARK_ALL},
|
||||||
|
{'d', ACT_DELETE},
|
||||||
|
{'m', ACT_MOVE},
|
||||||
|
{'c', ACT_COPY},
|
||||||
|
{'s', ACT_SYM_LINK},
|
||||||
|
{'b', ACT_BULK_RENAME},
|
||||||
|
};
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in a new issue