Compare commits

...

4 Commits

Author SHA1 Message Date
nova
5a31f452ea implementation of cmd_on_selected 2026-06-04 20:32:32 +02:00
nova
daf43daa00 implementation of jump_to_dir 2026-06-04 20:03:10 +02:00
nova
cf03a230b6 implementation of open_with 2026-06-03 23:00:06 +02:00
nova
87bfdd1b86 rename_hovered, adjustments to makefile & makedir and its associated config 2026-06-01 23:46:38 +02:00
2 changed files with 93 additions and 16 deletions

View File

@@ -15,6 +15,9 @@
/* }}} */
static const char clipboard_cmd[] = "echo ^ | xsel -ib --trim"; /*used in yank_text*/
static const char rename_cmd[] = "mv"; /* as used in rename_hovered, makedir and makefile */
static const char makefile_cmd[] = "touch"; /*as of now both only do ``rename_cmd new_name``*/
static const char makedir_cmd[] = "mkdir";
static const mimetype mimetype_default_cmd[] = {
/* mimetype shell command
@@ -65,7 +68,7 @@ static const binding key_binding[] = {
{ "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 */
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* execute shell cmd on file, accounts for SETTINGS_COMMAND_FORK */
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered 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 */
@@ -120,9 +123,9 @@ static const char ui_btm_text_storage_left[] = "total free";
static const char ui_btm_current_dir_size[] = "sum of dir,";
static const char ui_open_with_text[] = "open "SETTINGS_COMMAND_REPLACE_STR" with:";
static const char ui_rename_text[] = "rename "SETTINGS_COMMAND_REPLACE_STR" to:";
static const char ui_mkdir_text[] = "mkdir:";
static const char ui_touch_text[] = "touch:";
static const char ui_delete_text[] = "delete: "SETTINGS_COMMAND_REPLACE_STR;
static const char ui_makefile_text[] = "makedir:";
static const char ui_makedir_text[] = "makefile:";
static const char ui_delete_text[] = "delete:";
/* {{{ */
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
@@ -131,6 +134,9 @@ static const unsigned long file_extension_default_count = sizeof(file_extension_
static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1;
#else
static const char clipboard_cmd[];
static const char rename_cmd[];
static const char makefile_cmd[];
static const char makedir_cmd[];
static const mimetype mimetype_default_cmd[];
static const extension file_extension_default_cmd[];
static const binding key_binding[];
@@ -140,9 +146,9 @@ static const unsigned long file_extension_default_count;
static const char size_unit[];
static const char size_unit_count;
static const char ui_open_with_text[];
static const char ui_makedir_text[];
static const char ui_makefile_text[];
static const char ui_rename_text[];
static const char ui_mkdir_text[];
static const char ui_touch_text[];
static const char ui_delete_text[];
#endif
/* }}} */

View File

@@ -281,10 +281,49 @@ void jump_top(){
status |= (STATUS_RUN_BACKEND);
}
void open_with(){
TODO;
wclear(win_b);
char *cmd;
char *str = malloc(INPUT_BUFFER_SIZE);
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file);
mvwprintw(win_b, 0, 0, parsed_ui_text);
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
if (str[0] == SETTINGS_COMMAND_FORK) {
cmd = parse_cmd(str+1, mid_dir.current_file);
pid_t pid = fork();
if (pid == 0 && setsid()) {
system(cmd);
status = STATUS_QUIT_PROGRAM;
exit(1);
}
} else {
cmd = parse_cmd(str, mid_dir.current_file);
if (system(cmd)) {
}
}
free(cmd);
}
free(parsed_ui_text);
free(str);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
}
void rename_hovered(){
TODO;
wclear(win_b);
file tmp;
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
mvwprintw(win_b, 0, 0, parsed_ui_text);
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) {
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file);
char *cmd1 = parse_cmd(cmd0, &tmp);
system(cmd1);
free(cmd0);
free(cmd1);
}
free(parsed_ui_text);
free(tmp.file_name);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void delete(){
TODO;
@@ -293,9 +332,9 @@ void makedir(){
wclear(win_b);
file tmp;
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
mvwprintw(win_b, 0, 0, ui_mkdir_text);
if (read_string(win_b, 0, strlen(ui_mkdir_text)+1, tmp.file_name) == 0) {
char *cmd = parse_cmd("mkdir ", &tmp);
mvwprintw(win_b, 0, 0, ui_makedir_text);
if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) {
char *cmd = parse_cmd(makedir_cmd, &tmp);
system(cmd);
free(cmd);
}
@@ -306,9 +345,9 @@ void makefile(){
wclear(win_b);
file tmp;
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
mvwprintw(win_b, 0, 0, ui_touch_text);
if (read_string(win_b, 0, strlen(ui_touch_text)+1, tmp.file_name) == 0) {
char *cmd = parse_cmd("touch ", &tmp);
mvwprintw(win_b, 0, 0, ui_makefile_text);
if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) {
char *cmd = parse_cmd(makefile_cmd, &tmp);
system(cmd);
free(cmd);
}
@@ -339,7 +378,33 @@ void not_implemented(unsigned long passes, int index){
TODO;
}
void jump_to_dir(unsigned long passes, int index){
TODO;
(void)passes;
unsigned long len;
char *c = strchr(key_binding[index].black_magic, '/');
if (c) {
len = c - (char*)key_binding[index].black_magic;
} else {
len = strlen(key_binding[index].black_magic);
}
char *to_env = malloc(len + 1);
memcpy(to_env, key_binding[index].black_magic, len);
to_env[len] = '\0';
char *env = getenv(to_env + 1); /*+1 to remove the '$' prefix, freeing env always segfaults*/
if (env) {
char *path = malloc(strlen(key_binding[index].black_magic) + strlen(env) + 1);
memcpy(path, env, strlen(env));
memcpy(path + strlen(env), key_binding[index].black_magic + len, strlen(key_binding[index].black_magic)+1);
change_dir(path);
free(path);
} else {
change_dir(key_binding[index].black_magic);
}
free(to_env);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
}
void order_by(unsigned long passes, int index){
(void)passes;
@@ -350,7 +415,13 @@ void order_by(unsigned long passes, int index){
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
}
void cmd_on_selected(unsigned long passes, int index){
TODO;
(void)passes;
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
system(cmd);
free(cmd);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
}
void yank_file_name(){
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);