mirror of
https://gittea.dev/nova/th.git
synced 2026-01-30 16:50:10 -05:00
Compare commits
9 Commits
be9436570c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f1de78283 | ||
|
|
f3a39b0df0 | ||
|
|
8734fa6ae4 | ||
|
|
66f3f3bef6 | ||
|
|
393864c80f | ||
|
|
217884d920 | ||
|
|
3a891388ed | ||
|
|
0bdb4a1a0a | ||
|
|
ddcf4d4105 |
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
|||||||
CC := gcc
|
CC := gcc
|
||||||
CFLAGS := -Wall -Wextra -O2 -flto=auto
|
CFLAGS := -Wall -Wextra -O2 -flto=auto
|
||||||
CURSES := $(shell pkg-config --libs ncurses)
|
CURSES := $(shell pkg-config --libs ncursesw)
|
||||||
CFLAGS_DEBUG := $(CFLAGS) -g
|
CFLAGS_DEBUG := $(CFLAGS) -g
|
||||||
CFLAGS_PROFILE := $(CFLAGS) -pg
|
CFLAGS_PROFILE := $(CFLAGS) -pg
|
||||||
GDB := gdb --tui ./th
|
GDB := gdb --tui ./th
|
||||||
|
|||||||
68
backend.c
68
backend.c
@@ -1,14 +1,42 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
char* concat(const char *s1, const char *s2){
|
#define concat(out, s1, s2, _free) { \
|
||||||
const size_t len1 = strlen(s1);
|
concat## _free(out, s1, s2); \
|
||||||
const size_t len2 = strlen(s2);
|
|
||||||
char *result = malloc(len1 + len2 + 1);
|
|
||||||
memcpy(result, s1, len1);
|
|
||||||
memcpy(result + len1, s2, len2 + 1);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define concat0(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
|
||||||
|
#define concat1(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s1); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
#define concat2(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s2); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
#define concat3(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s1); \
|
||||||
|
free(s2); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
|
||||||
char* smartstrcasestr(const char *haystack, const char *needle){
|
char* smartstrcasestr(const char *haystack, const char *needle){
|
||||||
char smart = 0;
|
char smart = 0;
|
||||||
char *ret;
|
char *ret;
|
||||||
@@ -52,3 +80,29 @@ char* smartstrcasestr(const char *haystack, const char *needle){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* parse_cmd_char(const char *cmd, const char *path){
|
||||||
|
char *index = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
if (index) {
|
||||||
|
out = malloc(strlen(cmd) + 1 + strlen(path) + 1);
|
||||||
|
char *o = out;
|
||||||
|
memcpy(out, cmd, index - cmd);
|
||||||
|
o += index-cmd;
|
||||||
|
*o = '\"';
|
||||||
|
o++;
|
||||||
|
memcpy(o, path, strlen(path));
|
||||||
|
o += strlen(path);
|
||||||
|
*o = '\"';
|
||||||
|
memcpy(o+1, index + 1, strlen(index+1));
|
||||||
|
*(o+strlen(index+1)+1) = '\0';
|
||||||
|
return out;
|
||||||
|
} else {
|
||||||
|
concat(out, cmd, " ./\"", 0);
|
||||||
|
concat(out, out, path, 1);
|
||||||
|
concat(out, out, "\"", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,5 +5,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char* concat(const char *s1, const char *s2);
|
/*char* concat(const char *s1, const char *s2);*/
|
||||||
char* smartstrcasestr(const char *haystack, const char *needle);
|
char* smartstrcasestr(const char *haystack, const char *needle);
|
||||||
|
char* parse_cmd_char(const char *cmd, const char *path);
|
||||||
|
|
||||||
|
|||||||
30
config.h
30
config.h
@@ -2,6 +2,8 @@
|
|||||||
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */
|
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */
|
||||||
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */
|
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */
|
||||||
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
||||||
|
#define SETTINGS_COMMAND_REPLACE_STR "%" /* if a command in any cmd inside this fle contains this string, it will be replaced with the hovered/selected file name
|
||||||
|
* as of right now, this character cannot be escaped; i.e ``command\% --arg`` will parse into ``command\path_of_hovered_file --arg``*/
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
#ifndef CONFIG_GUARD
|
#ifndef CONFIG_GUARD
|
||||||
@@ -19,25 +21,25 @@ static const mimetype mimetype_default_cmd[] = {
|
|||||||
* file --mime-type -b ./image.gif
|
* file --mime-type -b ./image.gif
|
||||||
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
||||||
* we need to define "gif" before "image" */
|
* we need to define "gif" before "image" */
|
||||||
{ "text", "$EDITOR" },
|
{ "text", "$EDITOR" },
|
||||||
{ "gif", "mpv --loop-file=\"inf\"" },
|
{ "gif", "nohup mpv --loop-file=\"inf\" % >/dev/null 2>&1 &" },
|
||||||
{ "image", "feh" },
|
{ "image", "feh % >/dev/null 2>&1 &" },
|
||||||
{ "video", "mpv" },
|
{ "video", "nohup mpv % >/dev/null 2>&1 &" },
|
||||||
{ "audio", "mpv" },
|
{ "audio", "mpv" },
|
||||||
{ "pdf", "zathura" },
|
{ "pdf", "zathura" },
|
||||||
};
|
};
|
||||||
static const extension file_extension_default_cmd[] = {
|
static const extension file_extension_default_cmd[] = {
|
||||||
/* extension shell command
|
/* extension shell command
|
||||||
* similar to mimetype_default_cmd, however it searches for exact string matches
|
* similar to mimetype_default_cmd, however it searches for exact string matches
|
||||||
* and is checked before mimetype_default_cmd */
|
* and is checked before mimetype_default_cmd */
|
||||||
{ ".exe", "wine"},
|
{ ".exe", "wine"},
|
||||||
{ ".cbz", "mcomix"},
|
{ ".cbz", "mcomix % &"},
|
||||||
{ ".cbr", "mcomix"},
|
{ ".cbr", "mcomix % &"},
|
||||||
{ ".json", "$EDITOR"},
|
{ ".json", "$EDITOR"},
|
||||||
{ ".csv", "$EDITOR"},
|
{ ".csv", "$EDITOR"},
|
||||||
};
|
};
|
||||||
static const binding key_binding[] = {
|
static const binding key_binding[] = {
|
||||||
/*key action blackmagic comment*/
|
/*key action blackmagic comment*/
|
||||||
/*you cannot add bindings that include other bindings in its entirety
|
/*you cannot add bindings that include other bindings in its entirety
|
||||||
* possible: mk, mf
|
* possible: mk, mf
|
||||||
* not possible: gg, ggg
|
* not possible: gg, ggg
|
||||||
@@ -111,6 +113,11 @@ static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this define
|
|||||||
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
|
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_1[] = "with:";
|
||||||
|
static const char ui_rename_text_0[] = "rename"; /*ui_rename_text_0 \"selected_file\" ui_rename_text_1*/
|
||||||
|
static const char ui_rename_text_1[] = "to:";
|
||||||
|
static const char ui_delete_text[] = "delete:";
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);
|
||||||
@@ -127,5 +134,10 @@ static const unsigned long mimetype_default_count;
|
|||||||
static const unsigned long file_extension_default_count;
|
static const unsigned long file_extension_default_count;
|
||||||
static const char size_unit[];
|
static const char size_unit[];
|
||||||
static const char size_unit_count;
|
static const char size_unit_count;
|
||||||
|
static const char ui_open_with_text_0[];
|
||||||
|
static const char ui_open_with_text_1[];
|
||||||
|
static const char ui_rename_text_0[];
|
||||||
|
static const char ui_rename_text_1[];
|
||||||
|
static const char ui_delete_text[];
|
||||||
#endif
|
#endif
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
34
dir.c
34
dir.c
@@ -83,11 +83,7 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
dir_content[i].file_size = file->st_size;
|
dir_content[i].file_size = file->st_size;
|
||||||
dir_content[i].permissions = file->st_mode;
|
dir_content[i].permissions = file->st_mode;
|
||||||
|
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISLNK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR;
|
|
||||||
dir_content[i].color_pair = COLOR_DIR;
|
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
|
||||||
} else if (S_ISLNK(file->st_mode)) {
|
|
||||||
stat(full_path, file);
|
stat(full_path, file);
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
||||||
@@ -97,6 +93,10 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
||||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
dir_content[i].color_pair = COLOR_SYMLINK;
|
||||||
}
|
}
|
||||||
|
} else if (S_ISDIR(file->st_mode)) {
|
||||||
|
dir_content[i].file_type = FILE_TYPE_DIR;
|
||||||
|
dir_content[i].color_pair = COLOR_DIR;
|
||||||
|
dir_content[i].file_size = get_dir_size(full_path);
|
||||||
} else if (file->st_mode & S_IXUSR) {
|
} else if (file->st_mode & S_IXUSR) {
|
||||||
dir_content[i].file_type = FILE_TYPE_EXEC;
|
dir_content[i].file_type = FILE_TYPE_EXEC;
|
||||||
dir_content[i].color_pair = COLOR_EXEC;
|
dir_content[i].color_pair = COLOR_EXEC;
|
||||||
@@ -139,18 +139,13 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
}
|
}
|
||||||
free(full_path);
|
free(full_path);
|
||||||
free(file);
|
free(file);
|
||||||
|
free(entry[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(dir_content, *dir_file_count, sizeof(file), order_func);
|
qsort(dir_content, *dir_file_count, sizeof(file), order_func);
|
||||||
|
|
||||||
for (i = 0; i < *dir_file_count; i++) {
|
free(entry);
|
||||||
free(entry[i]);
|
|
||||||
}
|
|
||||||
if (entry != NULL) {
|
|
||||||
free(entry);
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +254,7 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
file_name[printable_size + strlen(extension)-1] = '\0';
|
file_name[printable_size + strlen(extension)-1] = '\0';
|
||||||
file_name[printable_size - 2] = '~';
|
file_name[printable_size - 2] = '~';
|
||||||
} else {
|
} else {
|
||||||
file_name = malloc(printable_size-1);
|
file_name = malloc(printable_size);
|
||||||
memcpy(file_name, dir_content[i].file_name, printable_size);
|
memcpy(file_name, dir_content[i].file_name, printable_size);
|
||||||
file_name[printable_size-2] = '~';
|
file_name[printable_size-2] = '~';
|
||||||
file_name[printable_size-1] = '\0';
|
file_name[printable_size-1] = '\0';
|
||||||
@@ -320,6 +315,7 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
} else {
|
} else {
|
||||||
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
|
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
|
||||||
}
|
}
|
||||||
|
free(file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(bg);
|
free(bg);
|
||||||
@@ -327,13 +323,11 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
|
|
||||||
char update_selected_file(){
|
char update_selected_file(){
|
||||||
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */
|
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */
|
||||||
if (mid_content->file_name[0] == '\0') { /* only happens if the current path is either empty or inaccessible */
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (selected_file_current >= mid_file_count) {
|
if (selected_file_current >= mid_file_count) {
|
||||||
selected_file_current = mid_file_count-1;
|
selected_file_current = mid_file_count-1;
|
||||||
}
|
}
|
||||||
if (selected_file_current != selected_file_last) {
|
if (selected_file_current != selected_file_last && selected_file_last <= mid_file_count) {
|
||||||
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -344,7 +338,7 @@ char update_selected_file(){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
void dir_set_selected_file_current(unsigned long selected_file_current){
|
void dir_set_selected_file_current(unsigned long selected_file_current){
|
||||||
if (mid_content->file_name[0] != '\0') {
|
if (mid_content->file_name) {
|
||||||
current_dir->selected_file_current = selected_file_current;
|
current_dir->selected_file_current = selected_file_current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,7 +378,9 @@ void dir_init(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void recursive_delete(file current_file){
|
void recursive_delete(file current_file){
|
||||||
if (current_file.file_type & FILE_TYPE_DIR) {
|
if (S_ISLNK(current_file.permissions)) {
|
||||||
|
remove(current_file.file_name);
|
||||||
|
} else if (current_file.file_type & FILE_TYPE_DIR ) {
|
||||||
unsigned int file_modifiers_tmp = file_modifiers;
|
unsigned int file_modifiers_tmp = file_modifiers;
|
||||||
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ char* get_mimetype(char *path){
|
|||||||
FILE *cmd_open = popen(cmd, "r");
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
free(cmd);
|
||||||
if (getline(&line, &size, cmd_open) != -1){
|
if (getline(&line, &size, cmd_open) != -1){
|
||||||
pclose(cmd_open);
|
pclose(cmd_open);
|
||||||
return line;
|
return line;
|
||||||
@@ -85,8 +86,9 @@ char* text(char *path, unsigned long *file_size){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* generic(char *path){
|
char* generic(char *path){
|
||||||
char *cmd = concat("file ./\"", path);
|
char *cmd;
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, "file ./\"", path, 0);
|
||||||
|
concat(cmd, cmd, "\"", 1);
|
||||||
|
|
||||||
FILE *cmd_open = popen(cmd, "r");
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
|||||||
208
interactions.c
208
interactions.c
@@ -181,7 +181,7 @@ void move_down(unsigned long passes){
|
|||||||
selected_file_current += passes;
|
selected_file_current += passes;
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
@@ -198,9 +198,10 @@ void move_up(unsigned long passes){
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
void move_left(unsigned long passes){
|
void move_left(unsigned long passes){
|
||||||
@@ -216,7 +217,9 @@ void move_left(unsigned long passes){
|
|||||||
selected_file_current = dir_get_selected_file_current();
|
selected_file_current = dir_get_selected_file_current();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
update_selected_file();
|
||||||
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void move_right(){
|
void move_right(){
|
||||||
if (mid_content->file_name[0] == '\0') {
|
if (mid_content->file_name[0] == '\0') {
|
||||||
@@ -236,9 +239,10 @@ void move_right(){
|
|||||||
if (extension != NULL) {
|
if (extension != NULL) {
|
||||||
for (i = 0; i < file_extension_default_count; i++) {
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
||||||
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
|
char *cmd;
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, file_extension_default_cmd[i].command, " ./\'", 0);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(cmd, cmd, "\'", 1);
|
||||||
|
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
@@ -246,7 +250,7 @@ void move_right(){
|
|||||||
}
|
}
|
||||||
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
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_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,17 +259,12 @@ void move_right(){
|
|||||||
for (i = 0; i < mimetype_default_count; i++) {
|
for (i = 0; i < mimetype_default_count; i++) {
|
||||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||||
|
|
||||||
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
|
char *cmd = parse_cmd_char(mimetype_default_cmd[i].command, mid_content[selected_file_current].file_name);
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
|
||||||
cmd = concat(cmd, "\"");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 */
|
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_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -274,11 +273,11 @@ void move_right(){
|
|||||||
free(mime);
|
free(mime);
|
||||||
}
|
}
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void toggle_hidden_files(){
|
void toggle_hidden_files(){
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void toggle_selection(){
|
void toggle_selection(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
@@ -293,15 +292,15 @@ void jump_bottom(){
|
|||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0 - 1;
|
selected_file_current = 0 - 1;
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
void jump_top(){
|
void jump_top(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
selected_file_current = 0;
|
selected_file_current = 0;
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
}
|
}
|
||||||
@@ -315,8 +314,11 @@ void open_with(){
|
|||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
btm_buffer = concat("open \"", mid_content[selected_file_current].file_name);
|
concat(btm_buffer, ui_open_with_text_0, " \'", 0);
|
||||||
btm_buffer = concat(btm_buffer, "\" with:");
|
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(btm_buffer, btm_buffer, "\' ", 1);
|
||||||
|
concat(btm_buffer, btm_buffer, ui_open_with_text_1, 1);
|
||||||
|
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
@@ -328,17 +330,20 @@ void open_with(){
|
|||||||
|
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
char *cmd = concat(str, " ./\"");
|
char *cmd;
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, str, " ./\'", 0);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(cmd, cmd, "\'", 1);
|
||||||
|
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
endwin();
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
FAIL("open_with", "creating subcommand failed unhandled");
|
FAIL("open_with", "creating subcommand failed unhandled");
|
||||||
}
|
}
|
||||||
|
initscr();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -358,8 +363,10 @@ void rename_hovered(){
|
|||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
||||||
|
|
||||||
btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name);
|
concat(btm_buffer, ui_rename_text_0, " \'", 0);
|
||||||
btm_buffer = concat(btm_buffer, "\" to:");
|
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
||||||
|
concat(btm_buffer, btm_buffer, "\' ", 1);
|
||||||
|
concat(btm_buffer, btm_buffer, ui_rename_text_1, 1);
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
window_btm(win_b, 1);
|
||||||
|
|
||||||
@@ -370,10 +377,11 @@ void rename_hovered(){
|
|||||||
|
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
char *cmd = concat("mv ./\"", mid_content[selected_file_current].file_name);
|
char *cmd;
|
||||||
cmd = concat(cmd, "\" ./\"");
|
concat(cmd, "mv ./\'", mid_content[selected_file_current].file_name, 0);
|
||||||
cmd = concat(cmd, str);
|
concat(cmd, cmd, "\' ./\'", 1);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, str, 1);
|
||||||
|
concat(cmd, cmd, "\'", 1);
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
FAIL("rename_hovered", "mv or creating subcommand failed");
|
FAIL("rename_hovered", "mv or creating subcommand failed");
|
||||||
@@ -397,53 +405,33 @@ void delete(){
|
|||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int hits = 0;
|
unsigned int hits = 0;
|
||||||
char *file_str = " ";
|
char *file_str = "";
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
file_str = concat(file_str, "\"");
|
concat(file_str, file_str, "\'", 0);
|
||||||
file_str = concat(file_str, mid_content[i].file_name);
|
concat(file_str, file_str, mid_content[i].file_name, 1);
|
||||||
file_str = concat(file_str, "\" ");
|
concat(file_str, file_str, "\' ", 1);
|
||||||
hits++;
|
hits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
if (strlen(file_str) < (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION-1) * (terminal_width/3)) {
|
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width);
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||||
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3));
|
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
||||||
memset(btm_buffer, ' ', (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)));
|
|
||||||
|
|
||||||
memcpy(btm_buffer, "delete: ",strlen("delete: "));
|
memcpy(btm_buffer, ui_delete_text ,strlen(ui_delete_text));
|
||||||
if (hits) {
|
|
||||||
memcpy(btm_buffer + strlen("delete: "), file_str, strlen(file_str));
|
|
||||||
} else {
|
|
||||||
btm_buffer[strlen("delete: ")] = '"';
|
|
||||||
memcpy(btm_buffer + strlen("delete: ") + sizeof(char), mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)-1);
|
|
||||||
btm_buffer[strlen("delete: ") + sizeof(char) + strlen(mid_content[selected_file_current].file_name)] = '"';
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3) - (terminal_width/3)) , "(y/N)", strlen("(y/N)"));
|
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
||||||
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * (terminal_width/3)] = '\0';
|
/*lets hope im never gonna need to format something like this ever again*/
|
||||||
|
memcpy(btm_buffer + strlen(ui_delete_text)+1, file_str,
|
||||||
|
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
||||||
|
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
||||||
|
strlen(file_str)));
|
||||||
|
|
||||||
} else {
|
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width - terminal_width) , "(y/N)", strlen("(y/N)"));
|
||||||
/*since more data is present than can be represented using div3, we do the uncool thing*/
|
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width-1] = '\0';
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width);
|
|
||||||
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
|
||||||
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
|
||||||
|
|
||||||
memcpy(btm_buffer, "delete: ",strlen("delete: "));
|
|
||||||
|
|
||||||
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
|
||||||
/*lets hope im never gonna need to format something like this ever again*/
|
|
||||||
memcpy(btm_buffer + strlen("delete: "), file_str,
|
|
||||||
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
|
||||||
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
|
||||||
strlen(file_str)));
|
|
||||||
|
|
||||||
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width - terminal_width) , "(y/N)", strlen("(y/N)"));
|
|
||||||
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -497,7 +485,7 @@ void makedir(){
|
|||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
btm_buffer = concat(btm_buffer, str);
|
concat(btm_buffer, btm_buffer, str, 0);
|
||||||
mode_t mask = umask(0);
|
mode_t mask = umask(0);
|
||||||
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
|
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
|
||||||
umask(mask);
|
umask(mask);
|
||||||
@@ -527,7 +515,7 @@ void makefile(){
|
|||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
btm_buffer = concat(btm_buffer, str);
|
concat(btm_buffer, btm_buffer, str, 0);
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
fp = fopen(str, "w");
|
fp = fopen(str, "w");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -590,7 +578,7 @@ void jump_to_dir(unsigned long passes, int index){
|
|||||||
env_str[env_len-1] = '\0';
|
env_str[env_len-1] = '\0';
|
||||||
env_parsed = getenv(env_str);
|
env_parsed = getenv(env_str);
|
||||||
if (env_parsed) {
|
if (env_parsed) {
|
||||||
path = concat(env_parsed, (char*)key_binding[index].black_magic + env_len);
|
concat(path, env_parsed, (char*)key_binding[index].black_magic + env_len, 0);
|
||||||
} else {
|
} else {
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
path = malloc(strlen((char*)key_binding[index].black_magic));
|
||||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
||||||
@@ -636,29 +624,30 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
|
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
char *btm_buffer_tmp = btm_buffer;
|
||||||
|
btm_buffer = "";
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int hits = 0;
|
unsigned int hits = 0;
|
||||||
char *file_str = " ";
|
char *file_str = "";
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
file_str = concat(file_str, "\"");
|
concat(file_str, file_str, "\'", 0);
|
||||||
file_str = concat(file_str, mid_content[i].file_name);
|
concat(file_str, file_str, mid_content[i].file_name, 1);
|
||||||
file_str = concat(file_str, "\" ");
|
concat(file_str, file_str, "\' ", 1);
|
||||||
hits++;
|
hits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hits) {
|
if (hits) {
|
||||||
btm_buffer = concat(key_binding[index].black_magic, file_str);
|
concat(btm_buffer, key_binding[index].black_magic, file_str, 2);
|
||||||
} else {
|
} else {
|
||||||
btm_buffer = concat(key_binding[index].black_magic, "\"");
|
concat(btm_buffer, key_binding[index].black_magic, "\'", 0);
|
||||||
btm_buffer = concat(btm_buffer, mid_content[selected_file_current].file_name);
|
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
||||||
btm_buffer = concat(btm_buffer, "\"");
|
concat(btm_buffer, btm_buffer, "\'", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
btm_buffer = concat(btm_buffer, "?");
|
concat(btm_buffer, btm_buffer, "?", 1);
|
||||||
btm_buffer = concat(btm_buffer, "\n\n");
|
concat(btm_buffer, btm_buffer, "\n\n", 1);
|
||||||
btm_buffer = concat(btm_buffer, "(y/N)");
|
concat(btm_buffer, btm_buffer, "(y/N)", 1);
|
||||||
|
|
||||||
werase(win_b);
|
werase(win_b);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
mvwin(win_b, terminal_height-6, 0);
|
||||||
@@ -674,13 +663,14 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
/* the second loop is used to add "./", wich is not being printed" */
|
/* the second loop is used to add "./", wich is not being printed" */
|
||||||
char *cmd = malloc(sizeof(char));
|
char *cmd = malloc(sizeof(char));
|
||||||
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
||||||
|
endwin();
|
||||||
if (hits) {
|
if (hits) {
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
free(cmd);
|
free(cmd);
|
||||||
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
concat(cmd, (char*)key_binding[index].black_magic, " \'", 0);
|
||||||
cmd = concat(cmd, mid_content[i].file_name);
|
concat(cmd, cmd, mid_content[i].file_name, 1);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, "\'", 1);
|
||||||
if (system(cmd) != 0) {
|
if (system(cmd) != 0) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
}
|
}
|
||||||
@@ -688,9 +678,9 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
free(cmd);
|
free(cmd);
|
||||||
cmd = concat((char*)key_binding[index].black_magic, " \"");
|
concat(cmd, (char*)key_binding[index].black_magic, " \'", 0);
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
cmd = concat(cmd, "\"");
|
concat(cmd, cmd, "\'", 1);
|
||||||
if (system(cmd) != 0) {
|
if (system(cmd) != 0) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
}
|
}
|
||||||
@@ -699,6 +689,7 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
}
|
}
|
||||||
/*system(cmd);*/
|
/*system(cmd);*/
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
initscr();
|
||||||
|
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
@@ -706,9 +697,6 @@ void cmd_on_selected(unsigned long passes, int index){
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
if (hits) {
|
|
||||||
free(file_str);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
void yank_text(unsigned long passes, int index){
|
void yank_text(unsigned long passes, int index){
|
||||||
@@ -716,16 +704,16 @@ void yank_text(unsigned long passes, int index){
|
|||||||
char *cmd;
|
char *cmd;
|
||||||
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
|
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
|
||||||
char *path=getcwd(NULL, 0);
|
char *path=getcwd(NULL, 0);
|
||||||
cmd = concat("echo \"", path);
|
concat(cmd, "echo \'", path, 0);
|
||||||
cmd = concat(cmd, "/");
|
concat(cmd, cmd, "/", 1);
|
||||||
cmd = concat(cmd, mid_content[selected_file_current].file_name);
|
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
||||||
cmd = concat(cmd, "\" | ");
|
concat(cmd, cmd, "\' | ", 1);
|
||||||
cmd = concat(cmd, clipboard_cmd);
|
concat(cmd, cmd, clipboard_cmd, 1);
|
||||||
free(path);
|
free(path);
|
||||||
} else {
|
} else {
|
||||||
cmd = concat("echo \"", mid_content[selected_file_current].file_name);
|
concat(cmd, "echo \'", mid_content[selected_file_current].file_name, 0);
|
||||||
cmd = concat(cmd, "\" | ");
|
concat(cmd, cmd, "\' | ", 1);
|
||||||
cmd = concat(cmd, clipboard_cmd);
|
concat(cmd, cmd, clipboard_cmd, 1);
|
||||||
}
|
}
|
||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
@@ -781,18 +769,16 @@ void yank_file(unsigned long passes, int index){
|
|||||||
void paste(){
|
void paste(){
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
for (i = 0; i < yank_files.count; i++) {
|
for (i = 0; i < yank_files.count; i++) {
|
||||||
/*TODO(2025-08-14T22:10:44) escape path*/
|
|
||||||
char *cmd;
|
char *cmd;
|
||||||
if (yank_files.status & YANK_COPY) {
|
if (yank_files.status & YANK_COPY) {
|
||||||
cmd = concat("false | cp -ri ", yank_files.path);
|
concat(cmd, "false | cp -ri \'", yank_files.path, 0);
|
||||||
} else {
|
} else {
|
||||||
cmd = concat("mv ", yank_files.path);
|
concat(cmd, "mv \'", yank_files.path, 0);
|
||||||
}
|
}
|
||||||
cmd = concat(cmd, "/");
|
concat(cmd, cmd, "/", 1);
|
||||||
cmd = concat(cmd, *yank_files.list);
|
concat(cmd, cmd, *yank_files.list, 1);
|
||||||
cmd = concat(cmd, " ./");
|
concat(cmd, cmd, "\' ./", 1);
|
||||||
cmd = concat(cmd, *yank_files.list);
|
concat(cmd, cmd, " 2>&1", 1);
|
||||||
cmd = concat(cmd, " 2>&1");
|
|
||||||
char *line = malloc(INPUT_BUFFER_SIZE);
|
char *line = malloc(INPUT_BUFFER_SIZE);
|
||||||
FILE *cmd_open;
|
FILE *cmd_open;
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -802,12 +788,12 @@ void paste(){
|
|||||||
}
|
}
|
||||||
if (strstr(line, "are the same file")) {
|
if (strstr(line, "are the same file")) {
|
||||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||||
cmd = concat(cmd, "_");
|
concat(cmd, cmd, "_", 1);
|
||||||
cmd = concat(cmd, " 2>&1");
|
concat(cmd, cmd, " 2>&1", 1);
|
||||||
} else if ((strstr(line, "overwrite"))) {
|
} else if ((strstr(line, "overwrite"))) {
|
||||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||||
cmd = concat(cmd, "_");
|
concat(cmd, cmd, "_", 1);
|
||||||
cmd = concat(cmd, " 2>&1");
|
concat(cmd, cmd, " 2>&1", 1);
|
||||||
} else if ((strstr(line, "No such file or directory"))) {
|
} else if ((strstr(line, "No such file or directory"))) {
|
||||||
pclose(cmd_open);
|
pclose(cmd_open);
|
||||||
break;
|
break;
|
||||||
@@ -886,7 +872,7 @@ void search(){
|
|||||||
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
dir_set_selected_file_current(selected_file_current);
|
current_dir->selected_file_current = selected_file_current;
|
||||||
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
|
|
||||||
|
|||||||
2
main.c
2
main.c
@@ -37,7 +37,6 @@ char *terminal_width_empty_line; /* used in user_interactions */
|
|||||||
void render_pass();
|
void render_pass();
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
init();
|
init();
|
||||||
@@ -92,6 +91,7 @@ int main(){
|
|||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
|
free(global_path);
|
||||||
global_path = getcwd(NULL, 0);
|
global_path = getcwd(NULL, 0);
|
||||||
pthread_cond_signal(&cond_top);
|
pthread_cond_signal(&cond_top);
|
||||||
pthread_cond_signal(&cond_mid);
|
pthread_cond_signal(&cond_mid);
|
||||||
|
|||||||
18
sorting.c
18
sorting.c
@@ -118,19 +118,13 @@ int sort_random(const void *file0, const void *file1){
|
|||||||
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
time_t num = (time_t)&seed;
|
time_t num = ((time_t)&sort_random)^((time_t)sort_natural);
|
||||||
time_t i;
|
int i = 1;
|
||||||
for (i = num%2; i < 6+(((time_t)&seed)%2); i++){
|
for (; i < 6; i++) {
|
||||||
num ^= *seed;
|
num += *seed;
|
||||||
if (num%2) {
|
num ^= num << ((((time_t)&seed)%6)+i);
|
||||||
num ^= (time_t)#
|
num ^= num >> ((((time_t)&num)%9)+i);
|
||||||
num ^= num << (i + (((time_t)&seed)%5));
|
|
||||||
} else {
|
|
||||||
num ^= (time_t)&seed;
|
|
||||||
num ^= num >> (i + (((time_t)&num)%5));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
num ^= getpid();
|
|
||||||
|
|
||||||
return ((num%3) - 1);
|
return ((num%3) - 1);
|
||||||
|
|
||||||
|
|||||||
57
threading.c
57
threading.c
@@ -93,9 +93,7 @@ void *thread_mid(){
|
|||||||
mid_file_count = 0;
|
mid_file_count = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&mutex_selection);
|
|
||||||
update_selected_file();
|
update_selected_file();
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btm_status = local_status;
|
btm_status = local_status;
|
||||||
@@ -157,20 +155,11 @@ void *thread_rgt(){
|
|||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
char *path;
|
char *path = mid_content[selected_file_current].file_name;
|
||||||
if (mid_file_count != 0) {
|
memcpy(&file_current, &mid_content[selected_file_current], sizeof(file));
|
||||||
path = malloc(strlen(mid_content[selected_file_current].file_name) + 1);
|
|
||||||
memcpy(path, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)+1);
|
|
||||||
} else {
|
|
||||||
path = malloc(sizeof(char));
|
|
||||||
path[0] = '\0';
|
|
||||||
}
|
|
||||||
file_current.file_type = mid_content[selected_file_current].file_type;
|
|
||||||
file_current.file_size = mid_content[selected_file_current].file_size;
|
|
||||||
file_current.status = mid_content[selected_file_current].status;
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
if (mid_content[selected_file_current].permissions & S_IRUSR) {
|
if (file_current.permissions & S_IRUSR) {
|
||||||
if (file_current.file_type &= FILE_TYPE_DIR) {
|
if (file_current.file_type &= FILE_TYPE_DIR) {
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
@@ -185,14 +174,20 @@ void *thread_rgt(){
|
|||||||
free(rgt_content);
|
free(rgt_content);
|
||||||
|
|
||||||
rgt_file_count = get_dir_size(path);
|
rgt_file_count = get_dir_size(path);
|
||||||
rgt_content = malloc(rgt_file_count * sizeof(file));
|
if (rgt_file_count) { /* fails if dir empty */
|
||||||
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
|
rgt_content = malloc(rgt_file_count * sizeof(file));
|
||||||
get_dir_content(path, &rgt_file_count, rgt_content);
|
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
|
||||||
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
get_dir_content(path, &rgt_file_count, rgt_content);
|
||||||
|
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
||||||
|
|
||||||
free(rgt_buffer);
|
free(rgt_buffer);
|
||||||
rgt_buffer = malloc(sizeof(char));
|
rgt_buffer = malloc(sizeof(char));
|
||||||
rgt_buffer[0] = '\0';
|
rgt_buffer[0] = '\0';
|
||||||
|
} else { /* the hovered dir is empty */
|
||||||
|
rgt_content = malloc(sizeof(file));
|
||||||
|
rgt_content->file_type = 0;
|
||||||
|
rgt_content->permissions = mid_content[selected_file_current].permissions;
|
||||||
|
}
|
||||||
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) {
|
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) {
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
@@ -225,8 +220,9 @@ void *thread_rgt(){
|
|||||||
rgt_buffer = malloc(sizeof(char));
|
rgt_buffer = malloc(sizeof(char));
|
||||||
rgt_buffer[0] = '\0';
|
rgt_buffer[0] = '\0';
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
free(path);
|
free(path);
|
||||||
|
*/
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
}
|
}
|
||||||
@@ -282,6 +278,9 @@ void *thread_btm(){
|
|||||||
|
|
||||||
free(ui_btm_right_block);
|
free(ui_btm_right_block);
|
||||||
|
|
||||||
|
if(path) {
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
path = getcwd(NULL, 0);
|
path = getcwd(NULL, 0);
|
||||||
struct statvfs fs;
|
struct statvfs fs;
|
||||||
statvfs(path, &fs);
|
statvfs(path, &fs);
|
||||||
@@ -338,15 +337,15 @@ void *thread_btm(){
|
|||||||
if (buffer_width != terminal_width) {
|
if (buffer_width != terminal_width) {
|
||||||
buffer_width = terminal_width;
|
buffer_width = terminal_width;
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = malloc(buffer_width);
|
btm_buffer = malloc(buffer_width+1);
|
||||||
memset(btm_buffer, ' ', buffer_width/2);
|
|
||||||
}
|
}
|
||||||
memset(btm_buffer + (buffer_width/2), ' ', buffer_width/2);
|
memset(btm_buffer, ' ', buffer_width);
|
||||||
btm_buffer[buffer_width] = '\0';
|
btm_buffer[buffer_width] = '\0';
|
||||||
|
|
||||||
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
||||||
|
|
||||||
btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-';
|
btm_buffer[0] = (S_ISLNK(mid_content[selected_file_current].permissions)) ? 'l':
|
||||||
|
(S_ISDIR(mid_content[selected_file_current].permissions) ? 'd': '-');
|
||||||
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
|
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
|
||||||
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
|
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
|
||||||
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';
|
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';
|
||||||
@@ -378,13 +377,11 @@ void threading_init(){
|
|||||||
|
|
||||||
mid_content->file_type = 0;
|
mid_content->file_type = 0;
|
||||||
mid_content->file_size = 0;
|
mid_content->file_size = 0;
|
||||||
mid_content->file_name = malloc(sizeof(char));
|
mid_content->file_name = "";
|
||||||
mid_content->file_name[0] = '\0';
|
|
||||||
|
|
||||||
rgt_content->file_type = 0;
|
rgt_content->file_type = 0;
|
||||||
rgt_content->file_size = 0;
|
rgt_content->file_size = 0;
|
||||||
rgt_content->file_name = malloc(sizeof(char));
|
rgt_content->file_name = "";
|
||||||
rgt_content->file_name[0] = '\0';
|
|
||||||
|
|
||||||
|
|
||||||
volatile char vol; /* needed to make sure higher optimization steps dont move these around */
|
volatile char vol; /* needed to make sure higher optimization steps dont move these around */
|
||||||
|
|||||||
Reference in New Issue
Block a user