implementation of jump_to_dir
This commit is contained in:
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);
|
||||||
|
|
||||||
|
@@ -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