mirror of
https://gittea.dev/nova/th.git
synced 2025-10-22 02:40:15 -04:00
Compare commits
3 Commits
7b563894f7
...
37d82bebf8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
37d82bebf8 | ||
![]() |
8b02e8e4e6 | ||
![]() |
7526a9e6e5 |
81
config.h
81
config.h
@@ -35,53 +35,56 @@ static const binding key_binding[] = {
|
|||||||
* not possible: gg, ggg
|
* not possible: gg, ggg
|
||||||
* trying to use ggg will always fail as it will execute gg first instead, resetting the input buffer, thus never reaching ggg */
|
* trying to use ggg will always fail as it will execute gg first instead, resetting the input buffer, thus never reaching ggg */
|
||||||
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
/* blackmagic holds a modifier of an action, either as string or as function pointer depending on the action */
|
||||||
{ "q", quit_program, NULL, "quit" },
|
{ "q", quit_program, NULL, "quit" },
|
||||||
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
{ " ", toggle_selection, NULL, "toggle file selection" }, /* on hovered file/directory */
|
||||||
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
|
||||||
{ "/", not_implemented, NULL, "search" },
|
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" },
|
||||||
|
{ "/", not_implemented, NULL, "search" },
|
||||||
|
|
||||||
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
|
{ "h", move_left, NULL, "move left" }, /* moves one dir up */
|
||||||
{ "t", move_down, NULL, "move down" },
|
{ "t", move_down, NULL, "move down" },
|
||||||
{ "n", move_up, NULL, "move up" },
|
{ "n", move_up, NULL, "move up" },
|
||||||
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||||
|
|
||||||
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
|
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
|
||||||
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||||
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
||||||
* this means that it does not delete the hovered files if files are already selected */
|
* this means that it does not delete the hovered files if files are already selected */
|
||||||
|
|
||||||
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||||
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
{ "gg", jump_top, NULL, "jump to first file in dir" },
|
||||||
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
||||||
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
||||||
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
{ "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" },
|
||||||
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||||
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
|
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||||
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
|
||||||
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
{ "go", jump_to_dir, "/opt", "jump to /opt" },
|
||||||
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||||
|
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||||
|
|
||||||
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
||||||
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
||||||
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
|
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
|
||||||
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
|
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
|
||||||
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
|
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
|
||||||
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
||||||
|
|
||||||
{ "on", order_by, sort_natural, "order natural" },
|
{ "on", order_by, sort_natural, "order natural" },
|
||||||
{ "or", not_implemented, "", "order reverse" },
|
{ "or", not_implemented, "", "order reverse" },
|
||||||
{ "oe", not_implemented, "", "order extension" },
|
{ "oe", not_implemented, "", "order extension" },
|
||||||
{ "os", order_by, sort_size, "order size" },
|
{ "os", order_by, sort_size, "order size" },
|
||||||
{ "ot", order_by, sort_type, "order type" },
|
{ "ot", order_by, sort_type, "order type" },
|
||||||
{ "oz", order_by, sort_random, "order random" },
|
{ "oz", order_by, sort_random, "order random" },
|
||||||
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
{ "oa", order_by, sort_alpha, "order alphabetically" },
|
||||||
|
|
||||||
{ "mk", makedir, NULL, "create directory" },
|
{ "mk", makedir, NULL, "create directory" },
|
||||||
{ "mf", makefile, NULL, "create file" },
|
{ "mf", makefile, NULL, "create file" },
|
||||||
|
|
||||||
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
|
{ "a", toggle_hidden_files, NULL, "toggle hidden files" },
|
||||||
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace/delete key */
|
{ "\x7F", toggle_hidden_files, NULL, "toggle hidden files" }, /* backspace key */
|
||||||
};
|
};
|
||||||
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
||||||
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
||||||
static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension);
|
static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension);
|
||||||
|
|
||||||
|
@@ -77,16 +77,15 @@ void user_interactions() {
|
|||||||
memset(input, 0, 255);
|
memset(input, 0, 255);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
timeout(100); /* blocking timeout of getch() */
|
timeout(100); /* blocking timeout of getch() */
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
}
|
}
|
||||||
binding_pass = 0;
|
binding_pass = 0;
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void (*func_ptr)(int, int);
|
void (*func_ptr)(int, int);
|
||||||
int number_length = 0;
|
unsigned long number_length = 0;
|
||||||
|
|
||||||
if (!binding_pass) {
|
if (!binding_pass) {
|
||||||
parsed_input_number = 0;
|
parsed_input_number = 0;
|
||||||
@@ -94,7 +93,6 @@ void user_interactions() {
|
|||||||
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
parsed_input_number = (parsed_input_number * 10) + (*input - '0');
|
||||||
input++;
|
input++;
|
||||||
number_length++;
|
number_length++;
|
||||||
mvaddch(terminal_height-5, 5, number_length+48);
|
|
||||||
}
|
}
|
||||||
input -= number_length;
|
input -= number_length;
|
||||||
binding_pass = 1;
|
binding_pass = 1;
|
||||||
@@ -109,7 +107,7 @@ void user_interactions() {
|
|||||||
func_ptr = key_binding[i].func;
|
func_ptr = key_binding[i].func;
|
||||||
func_ptr(parsed_input_number, i);
|
func_ptr(parsed_input_number, i);
|
||||||
|
|
||||||
} else if (strncmp(input+number_length, key_binding[i].key, cmp_len) == 0) {
|
} else if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
||||||
binding_matches++;
|
binding_matches++;
|
||||||
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
|
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "\t\t\t");
|
||||||
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "%s\t%s", key_binding[i].key, key_binding[i].comment);
|
mvwprintw(stdscr, terminal_height-binding_matches-1, 0, "%s\t%s", key_binding[i].key, key_binding[i].comment);
|
||||||
@@ -121,7 +119,7 @@ void user_interactions() {
|
|||||||
mvaddstr(terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
mvaddstr(terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
|
||||||
attroff(A_UNDERLINE);
|
attroff(A_UNDERLINE);
|
||||||
status &= ~STATUS_INPUT_MATCH;
|
status &= ~STATUS_INPUT_MATCH;
|
||||||
} else {
|
} else if (number_length != strlen(input)) {
|
||||||
memset(input, 0, 255);
|
memset(input, 0, 255);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
binding_pass = 0;
|
binding_pass = 0;
|
||||||
@@ -249,6 +247,7 @@ void move_right(){
|
|||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
}
|
}
|
||||||
|
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
||||||
match = 1;
|
match = 1;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
break;
|
break;
|
||||||
@@ -269,6 +268,7 @@ void move_right(){
|
|||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
}
|
}
|
||||||
|
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -519,11 +519,56 @@ void not_implemented(int passes, int index){
|
|||||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
||||||
}
|
}
|
||||||
void jump_to_dir(int passes, int index){
|
void jump_to_dir(int passes, int index){
|
||||||
if ((char*)key_binding[index].black_magic) {
|
char *ch = (char*)key_binding[index].black_magic;
|
||||||
if (chdir(getenv((char*)key_binding[index].black_magic+1)) != 0) {
|
char slash = 0;
|
||||||
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
|
unsigned int env_len = 0;
|
||||||
|
while (*ch != '\0') {
|
||||||
|
if (*ch == '/') {
|
||||||
|
slash = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
env_len++;
|
||||||
|
ch++;
|
||||||
|
}
|
||||||
|
char *env_str = NULL;
|
||||||
|
char *env_parsed = NULL;
|
||||||
|
char *path = NULL;
|
||||||
|
ch = (char*)key_binding[index].black_magic;
|
||||||
|
if (*ch == '/') {
|
||||||
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
|
strcpy(path, (char*)key_binding[index].black_magic);
|
||||||
|
} else if (slash) {
|
||||||
|
env_str = malloc(env_len * sizeof(char));
|
||||||
|
memcpy(env_str, (char*)key_binding[index].black_magic +1, env_len);
|
||||||
|
env_str[env_len-1] = '\0';
|
||||||
|
env_parsed = getenv(env_str);
|
||||||
|
if (env_parsed) {
|
||||||
|
path = concat(env_parsed, (char*)key_binding[index].black_magic + env_len);
|
||||||
|
} else {
|
||||||
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
|
strcpy(path, (char*)key_binding[index].black_magic);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
env_parsed = getenv((char*)key_binding[index].black_magic +1);
|
||||||
|
if (env_parsed) {
|
||||||
|
path = malloc(strlen(env_parsed)+1);
|
||||||
|
strcpy(path, env_parsed);
|
||||||
|
} else {
|
||||||
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
|
strcpy(path, (char*)key_binding[index].black_magic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (chdir(path) != 0) {
|
||||||
|
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*env_parsed shall not be modified (read: free'd) - the man page*/
|
||||||
|
if (env_str) {
|
||||||
|
free(env_str);
|
||||||
|
}
|
||||||
|
if(path) {
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void order_by(int passes, int index){
|
void order_by(int passes, int index){
|
||||||
|
Reference in New Issue
Block a user