extensionsto key_binding
This commit is contained in:
15
config.h
15
config.h
@ -41,7 +41,8 @@ static binding key_binding[] = {
|
||||
|
||||
{ "G", jump_bottom, NULL, "jump to last file in dir" },
|
||||
{ "gg", jump_top, NULL, "jump to file 0" },
|
||||
{ "gh", jump_to_dir, "~/", "jump to ~/" },
|
||||
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" },
|
||||
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" },
|
||||
{ "gd", jump_to_dir, "/dev", "jump to /dev" },
|
||||
{ "ge", jump_to_dir, "/etc", "jump to /etc" },
|
||||
{ "gm", jump_to_dir, "/mnt", "jump to /mnt" },
|
||||
@ -49,12 +50,12 @@ static binding key_binding[] = {
|
||||
{ "gt", jump_to_dir, "/tmp", "jump to /tmp" },
|
||||
{ "gv", jump_to_dir, "/var", "jump to /var" },
|
||||
|
||||
{ "u7", not_implemented, "", "unzip 7z" },
|
||||
{ "ub", not_implemented, "", "unzip bz2" },
|
||||
{ "ur", not_implemented, "", "unzip rar" },
|
||||
{ "ut", not_implemented, "", "unzip tar" },
|
||||
{ "ut", not_implemented, "", "unzip gzip" },
|
||||
{ "uz", not_implemented, "", "unzip zip" },
|
||||
{ "u7", cmd_on_selected, "7z x", "unzip 7z" },
|
||||
{ "ub", cmd_on_selected, "tar -xvf", "unzip bz2" },
|
||||
{ "ur", cmd_on_selected, "unrar x", "unzip rar" },
|
||||
{ "ut", cmd_on_selected, "tar -xvf", "unzip tar" },
|
||||
{ "ut", cmd_on_selected, "gzip -d", "unzip gzip" },
|
||||
{ "uz", cmd_on_selected, "unzip ", "unzip zip" },
|
||||
|
||||
{ "on", order_by, sort_natural, "order natural" },
|
||||
{ "or", not_implemented, "", "order reverse" },
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <pthread.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
@ -37,6 +38,7 @@ extern char *input;
|
||||
unsigned int input_pass;
|
||||
int parsed_input_number;
|
||||
extern char *terminal_width_empty_line;
|
||||
extern char *start_path;
|
||||
|
||||
int read_string(WINDOW *win, int y, int x, char *str);
|
||||
int strcmp_offset(char *in0, char *in1, char offset);
|
||||
@ -461,22 +463,99 @@ void makefile(){
|
||||
void update(){
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
}
|
||||
void not_implemented(){
|
||||
mvaddstr(terminal_height-1, 0, input);
|
||||
mvaddstr(terminal_height-1, strlen(input), "\t");
|
||||
mvaddstr(terminal_height-1, strlen(input) + strlen("\t"), "is not yet implemented");
|
||||
void not_implemented(int passes, int index){
|
||||
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
||||
}
|
||||
void jump_to_dir(int passes, int index){
|
||||
if (strcmp((char*)key_binding[index].black_magic, "~/") || strcmp((char*)key_binding[index].black_magic, "$HOME")) {
|
||||
chdir(getenv("HOME"));
|
||||
}
|
||||
/* for some reason putting this in a else does not work */
|
||||
if ((char*)key_binding[index].black_magic) {
|
||||
chdir(getenv((char*)key_binding[index].black_magic+1));
|
||||
} else {
|
||||
chdir((char*)key_binding[index].black_magic);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
void order_by(int passes, int index){
|
||||
|
||||
order_func = key_binding[index].black_magic;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void cmd_on_selected(int passes, int index){
|
||||
unsigned int i = 0;
|
||||
unsigned int hits = 0;
|
||||
char *file_str = " ";
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
file_str = concat(file_str, "\"");
|
||||
file_str = concat(file_str, mid_content[i].file_name);
|
||||
file_str = concat(file_str, "\" ");
|
||||
hits++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hits) {
|
||||
btm_buffer = concat(key_binding[index].black_magic, file_str);
|
||||
} else {
|
||||
btm_buffer = concat(key_binding[index].black_magic, "\"");
|
||||
btm_buffer = concat(btm_buffer, file_current->file_name);
|
||||
btm_buffer = concat(btm_buffer, "\"");
|
||||
}
|
||||
|
||||
btm_buffer = concat(btm_buffer, "?");
|
||||
btm_buffer = concat(btm_buffer, "\n\n");
|
||||
btm_buffer = concat(btm_buffer, "(y/N)");
|
||||
|
||||
status = STATUS_UPDATE_SCREEN_0;
|
||||
werase(win_b);
|
||||
mvwin(win_b, terminal_height-6, 0);
|
||||
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
|
||||
|
||||
render_pass();
|
||||
|
||||
|
||||
timeout(-1); /* negative numbers block until enter is pressed */
|
||||
/* TODO(2025-07-06T07:22:49) fix fixed buffer size */
|
||||
char ch = wgetch(win_b);
|
||||
|
||||
if (ch == 'y' || ch == 'Y') {
|
||||
/* the second loop is used to add "./", wich is not being printed" */
|
||||
char *cmd;
|
||||
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
||||
if (hits) {
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
||||
cmd = concat(cmd, mid_content[i].file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
}
|
||||
}
|
||||
free(btm_buffer);
|
||||
btm_buffer = concat("completed: ", key_binding[index].black_magic);
|
||||
} else {
|
||||
free(btm_buffer);
|
||||
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
||||
cmd = concat(cmd, file_current->file_name);
|
||||
cmd = concat(cmd, "\"");
|
||||
system(cmd);
|
||||
mvaddstr(10,10, cmd);
|
||||
|
||||
}
|
||||
/*system(cmd);*/
|
||||
free(cmd);
|
||||
|
||||
} else {
|
||||
free(btm_buffer);
|
||||
btm_buffer = "cancled deletion";
|
||||
}
|
||||
|
||||
timeout(10);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||
|
||||
if (hits) {
|
||||
free(file_str);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ void delete();
|
||||
void makedir();
|
||||
void makefile();
|
||||
void update();
|
||||
void not_implemented();
|
||||
void not_implemented(int passes, int index);
|
||||
void jump_to_dir(int passes, int index);
|
||||
void order_by(int passes, int index);
|
||||
void cmd_on_selected(int passes, int index);
|
||||
|
3
main.c
3
main.c
@ -17,6 +17,7 @@ unsigned int temp_width = 0;
|
||||
unsigned int settings;
|
||||
unsigned int file_modifiers;
|
||||
unsigned int status;
|
||||
char *start_path;
|
||||
|
||||
WINDOW *win_t;
|
||||
WINDOW *win_b;
|
||||
@ -90,6 +91,7 @@ int main(){
|
||||
|
||||
}
|
||||
threading_free();
|
||||
free(start_path);
|
||||
|
||||
pthread_join(thread_l, NULL);
|
||||
pthread_join(thread_r, NULL);
|
||||
@ -178,5 +180,6 @@ void init() {
|
||||
colors_init();
|
||||
ESCDELAY = 10;
|
||||
|
||||
setenv("START_PATH", getcwd(NULL, 0), 0);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user