Compare commits

..

2 Commits

Author SHA1 Message Date
nova
e42d55e66a implementation of yank_file_name and yank_file_path 2026-05-25 12:01:43 +02:00
nova
f6380ddeda small fix of strlen(offset+1) to strlen(offset)+1 2026-05-25 11:24:58 +02:00
4 changed files with 29 additions and 8 deletions

View File

@@ -124,8 +124,8 @@ char* parse_cmd(const char *cmd, file *f){
if (offset) { if (offset) {
pos[1]= ' '; pos[1]= ' ';
memcpy(pos + 1, offset+1, strlen(offset+1)); memcpy(pos + 1, offset+1, strlen(offset)+1);
pos[strlen(offset+1)] = '\0'; pos[strlen(offset)+1] = '\0';
} else { } else {
pos[1] = '\0'; pos[1] = '\0';
} }

View File

@@ -14,6 +14,8 @@
#include "interactions.h" #include "interactions.h"
/* }}} */ /* }}} */
static const char clipboard_cmd[] = "echo ^ | xsel -ib --trim"; /*used in yank_text*/
static const mimetype mimetype_default_cmd[] = { static const mimetype mimetype_default_cmd[] = {
/* mimetype shell command /* mimetype shell command
* ^ substring of "file --mime-type -b ./hovered" * ^ substring of "file --mime-type -b ./hovered"
@@ -67,8 +69,8 @@ static const binding key_binding[] = {
{ "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 */
{ "yn", yank_text, "name", "yank filename of hovered file" }, { "yn", yank_file_name, NULL, "yank filename of hovered file" },
{ "yp", yank_text, "path", "yank path of hovered file" }, { "yp", yank_file_path, NULL, "yank path of hovered file" },
{ "yy", yank_file, "copy", "copy/yank file/directory" }, { "yy", yank_file, "copy", "copy/yank file/directory" },
{ "dd", yank_file, "cut", "cut file/directory" }, { "dd", yank_file, "cut", "cut file/directory" },
{ "pp", paste, NULL, "paste" }, { "pp", paste, NULL, "paste" },
@@ -114,7 +116,6 @@ static const binding key_binding[] = {
static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */ static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
static const char ui_btm_text_storage_left[] = "total free"; 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_btm_current_dir_size[] = "sum of dir,";
static const char ui_open_with_text_0[] = "open"; /*ui_open_with_text_0 \"selected_file\" ui_open_with_text_1*/ static const char ui_open_with_text_0[] = "open"; /*ui_open_with_text_0 \"selected_file\" ui_open_with_text_1*/

View File

@@ -23,6 +23,7 @@ extern unsigned int terminal_width;
extern unsigned int status; extern unsigned int status;
extern char *start_path; extern char *start_path;
extern char *global_path;
extern char *input; extern char *input;
extern time_t seed; extern time_t seed;
@@ -349,8 +350,26 @@ void order_by(unsigned long passes, int index){
void cmd_on_selected(unsigned long passes, int index){ void cmd_on_selected(unsigned long passes, int index){
TODO; TODO;
} }
void yank_text(unsigned long passes, int index){ void yank_file_name(){
TODO; char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
system(cmd);
free(cmd);
status |= (STATUS_RUN_BACKEND);
}
void yank_file_path(){
file *tmp = malloc(sizeof(file));
tmp->file_name = malloc(strlen(global_path)+1+strlen(mid_dir.current_file->file_name)+1);
memcpy(tmp->file_name, global_path, strlen(global_path));
memcpy(tmp->file_name+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
tmp->file_name[strlen(global_path)] = '/'; /*no +1 is needed*/
char *cmd = parse_cmd(clipboard_cmd, tmp);
system(cmd);
free(cmd);
free(tmp->file_name);
free(tmp);
status |= (STATUS_RUN_BACKEND);
} }
void yank_file(unsigned long passes, int index){ void yank_file(unsigned long passes, int index){
TODO; TODO;

View File

@@ -26,7 +26,8 @@ void not_implemented(unsigned long passes, int index);
void jump_to_dir(unsigned long passes, int index); void jump_to_dir(unsigned long passes, int index);
void order_by(unsigned long passes, int index); void order_by(unsigned long passes, int index);
void cmd_on_selected(unsigned long passes, int index); void cmd_on_selected(unsigned long passes, int index);
void yank_text(unsigned long passes, int index); void yank_file_name();
void yank_file_path();
void yank_file(unsigned long passes, int index); void yank_file(unsigned long passes, int index);
void paste(); void paste();
void search(); void search();