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