Compare commits

..

No commits in common. "32f08816be819e878d4218860b59e113fbd39ff8" and "addc8e2c9d5f09a5a8d2a126bf5060948b1f33f1" have entirely different histories.

3 changed files with 59 additions and 167 deletions

1
TODO
View file

@ -1 +1,2 @@
keybinding in config with struct and enum
cli help page documentation cli help page documentation

169
ccc.c
View file

@ -17,8 +17,6 @@
#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,
@ -38,65 +36,14 @@ 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);
@ -135,7 +82,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 = 0; int file_picker = 1;
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];
@ -224,13 +171,13 @@ int main(int argc, char **argv)
sel_file = arraylist_search(files, argv_cp, 1); sel_file = arraylist_search(files, argv_cp, 1);
} }
int run = 1; int ch, run = 1;
while (run) { while (run) {
list_files(); list_files();
int sel = getsel(); ch = readch();
switch (sel) { switch (ch) {
/* quit */ /* quit */
case ACT_QUIT: case 'q':
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();
@ -240,12 +187,14 @@ int main(int argc, char **argv)
break; break;
/* reload */ /* reload */
case ACT_RELOAD: case 'z':
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
/* go back */ /* go back */
case ACT_BACK:; case BACKSPACE:;
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 */
@ -261,7 +210,9 @@ int main(int argc, char **argv)
break; break;
/* enter directory/open a file */ /* enter directory/open a file */
case ACT_ENTER:; case 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 */
@ -286,45 +237,47 @@ int main(int argc, char **argv)
break; break;
/* jump up */ /* jump up */
case ACT_JUMP_UP: case CTRLU:
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 ACT_JUMP_DOWN: case CTRLD:
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 ACT_DOWN: case ARROW_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 ACT_BOTTOM: case 'G':
sel_file = (files->length - 1); sel_file = (files->length - 1);
break; break;
/* jump to the top */ /* jump to the top */
case ACT_TOP: case 'g':
sel_file = 0; sel_file = 0;
break; break;
/* '~' go to $HOME */ /* '~' go to $HOME */
case ACT_HOME:; case TILDE:;
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)");
@ -335,7 +288,7 @@ int main(int argc, char **argv)
break; break;
/* go to the trash dir */ /* go to the trash dir */
case ACT_TRASH_DIR:; case 't':;
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);
@ -344,93 +297,92 @@ int main(int argc, char **argv)
break; break;
/* sort files */ /* sort files */
case ACT_SORT: case 'u':
sort_files(); sort_files();
break; break;
/* show directories' sizes */ /* show directories' sizes */
case ACT_SHOW_DIR_SIZE: case 'A':
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 ACT_PREV_DIR: case '-':
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 ACT_SHOW_HELP: case '?':
show_help(); show_help();
break; break;
/* toggle hidden files */ /* toggle hidden files */
case ACT_HIDDEN_FILES: case '.':
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 ACT_FILE_DETAILS: case 'i':
show_details = !show_details; show_details = !show_details;
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
case ACT_SHOW_ICONS: case 'w':
show_icons = !show_icons; show_icons = !show_icons;
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
case ACT_CREATE_FILE: case 'f':
create_file(); create_file();
break; break;
case ACT_CREATE_DIR: case 'n':
create_dir(); create_dir();
break; break;
case ACT_RENAME_FILE: case 'r':
rename_file(); rename_file();
break; break;
case ACT_GOTO_DIR: case ':':
goto_dir(); goto_dir();
break; break;
case ACT_TOGGLE_EXE: case 'X':
toggle_executable(); toggle_executable();
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break; break;
case ACT_START_SHELL: case '!':
start_shell(); start_shell();
break; break;
case ACT_COPY_FILENAME: case 'y':
yank_clipboard(); yank_clipboard();
break; break;
case ACT_OPEN_FILE: case 'o':
open_with(); open_with();
break; break;
case 'O':
case ACT_OPEN_FILE_DETACHED:
open_detached(); open_detached();
break; break;
case ACT_VIEW_FILE_ATTR: case 'x':
view_file_attr(); view_file_attr();
break; break;
case ACT_SHOW_HIST: case 'e':
show_history(); show_history();
break; break;
case ACT_FAV1: case ACT_FAV2: case ACT_FAV3: case ACT_FAV4: case ACT_FAV5: case '1': case '2': case '3': case '4': case '5': case '6': case '7':
case ACT_FAV6: case ACT_FAV7: case ACT_FAV8: case ACT_FAV9:; case '8': case '9':;
char envname[9]; char envname[9];
snprintf(envname, 9, "CCC_FAV%d", sel - ACT_FAV1 + 1); snprintf(envname, 9, "CCC_FAV%d", ch - '0');
char *fav = getenv(envname); char *fav = getenv(envname);
if (fav && !strcmp(fav, "")) { if (fav && !strcmp(fav, "")) {
char dir[PATH_MAX]; char dir[PATH_MAX];
@ -440,44 +392,44 @@ int main(int argc, char **argv)
break; break;
/* mark one file */ /* mark one file */
case ACT_MARK_FILE: case SPACE:
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 ACT_MARK_ALL: case 'a':
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 ACT_DELETE: case 'd':
delete_files(); delete_files();
break; break;
/* move */ /* move */
case ACT_MOVE: case 'm':
if (marked->length) { if (marked->length) {
; ;
} }
break; break;
/* copy */ /* copy */
case ACT_COPY: case 'c':
if (marked->length) { if (marked->length) {
; ;
} }
break; break;
/* symbolic link */ /* symbolic link */
case ACT_SYM_LINK: case 's':
if (marked->length) { if (marked->length) {
; ;
} }
break; break;
/* bulk rename */ /* bulk rename */
case ACT_BULK_RENAME: case 'b':
if (marked->length) { if (marked->length) {
; ;
} }
@ -491,17 +443,6 @@ 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);

View file

@ -52,58 +52,8 @@ 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},
};
}
*/