mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
Compare commits
3 Commits
fa544204ba
...
df726e2f32
Author | SHA1 | Date | |
---|---|---|---|
![]() |
df726e2f32 | ||
![]() |
140457e4b7 | ||
![]() |
23654741bc |
2
config.h
2
config.h
@@ -91,7 +91,7 @@ static const binding key_binding[] = {
|
|||||||
{ "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" },
|
||||||
{ "oe", not_implemented, NULL, "order extension" },
|
{ "oe", order_by, sort_extension, "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" },
|
||||||
{ "or", order_by, sort_random, "order random" },
|
{ "or", order_by, sort_random, "order random" },
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
||||||
#define STATUS_USER_ROOT 64
|
#define STATUS_USER_ROOT 64
|
||||||
#define STATUS_INPUT_MATCH 128
|
#define STATUS_INPUT_MATCH 128
|
||||||
|
#define STATUS_DELTA_TIME 256
|
||||||
|
|
||||||
#define SETTINGS_HAS_COLOR 1
|
#define SETTINGS_HAS_COLOR 1
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -751,12 +752,13 @@ void yank_file(unsigned long passes, int index){
|
|||||||
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
if (yank_files.status & YANK_IS_USED) {
|
if (yank_files.status & YANK_IS_USED) {
|
||||||
free(yank_files.path);
|
|
||||||
for (i = 0; i < yank_files.count; i++) {
|
for (i = 0; i < yank_files.count; i++) {
|
||||||
free(yank_files.list[i]);
|
free(yank_files.list[i]);
|
||||||
}
|
}
|
||||||
free(yank_files.list);
|
free(yank_files.list);
|
||||||
|
free(yank_files.path);
|
||||||
yank_files.count = 0;
|
yank_files.count = 0;
|
||||||
|
yank_files.status = 0;
|
||||||
}
|
}
|
||||||
yank_files.path=getcwd(NULL, 0);
|
yank_files.path=getcwd(NULL, 0);
|
||||||
yank_files.count = 0;
|
yank_files.count = 0;
|
||||||
@@ -773,7 +775,7 @@ void yank_file(unsigned long passes, int index){
|
|||||||
strcpy(*yank_files.list, mid_content[selected_file_current].file_name);
|
strcpy(*yank_files.list, mid_content[selected_file_current].file_name);
|
||||||
} else {
|
} else {
|
||||||
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
||||||
for (i = 0; i < mid_file_count && i < yank_files.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) {
|
||||||
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
||||||
strcpy(*yank_files.list, mid_content[i].file_name);
|
strcpy(*yank_files.list, mid_content[i].file_name);
|
||||||
@@ -797,32 +799,41 @@ void paste(){
|
|||||||
/*TODO(2025-08-14T22:10:44) escape path*/
|
/*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 -r -i ", yank_files.path);
|
cmd = concat("false | cp -riv ", yank_files.path);
|
||||||
} else {
|
} else {
|
||||||
cmd = concat("mv ", yank_files.path);
|
cmd = concat("mv ", yank_files.path);
|
||||||
}
|
}
|
||||||
cmd = concat(cmd, "/");
|
cmd = concat(cmd, "/");
|
||||||
cmd = concat(cmd, *yank_files.list);
|
cmd = concat(cmd, *yank_files.list);
|
||||||
cmd = concat(cmd, " ./");
|
cmd = concat(cmd, " ./");
|
||||||
mvprintw(i, 0, cmd);
|
cmd = concat(cmd, *yank_files.list);
|
||||||
if (system(cmd) != 0) {
|
cmd = concat(cmd, " 2>&1");
|
||||||
cmd = concat(cmd, *yank_files.list);
|
char *line = malloc(255);
|
||||||
char *line = NULL;
|
FILE *cmd_open;
|
||||||
size_t size = 0;
|
while (1) {
|
||||||
FILE *cmd_open;
|
cmd_open = popen(cmd, "r");
|
||||||
while (1) {
|
if (fgets(line, 255, cmd_open) == 0) {
|
||||||
cmd_open = popen(cmd, "r");
|
break;
|
||||||
int val = getline(&line, &size, cmd_open);
|
|
||||||
|
|
||||||
if (pclose(cmd_open) == 0) {
|
|
||||||
break;
|
|
||||||
} else if (val == 0 || val == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cmd = concat(cmd, "_");
|
|
||||||
}
|
}
|
||||||
|
if (strstr(line, "are the same file")) {
|
||||||
|
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||||
|
cmd = concat(cmd, "_");
|
||||||
|
cmd = concat(cmd, " 2>&1");
|
||||||
|
} else if ((strstr(line, "overwrite"))) {
|
||||||
|
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
||||||
|
cmd = concat(cmd, "_");
|
||||||
|
cmd = concat(cmd, " 2>&1");
|
||||||
|
} else if ((strstr(line, "No such file or directory"))) {
|
||||||
|
pclose(cmd_open);
|
||||||
|
break;
|
||||||
|
} else if (pclose(cmd_open) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pclose(cmd_open);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(cmd);
|
||||||
|
|
||||||
yank_files.list++;
|
yank_files.list++;
|
||||||
}
|
}
|
||||||
yank_files.list -= yank_files.count;
|
yank_files.list -= yank_files.count;
|
||||||
|
4
main.c
4
main.c
@@ -81,7 +81,7 @@ int main(){
|
|||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
if (threading) {
|
if (threading) {
|
||||||
status &= ~(STATUS_RELOAD_DIRECTORY);
|
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
||||||
threading = 0;
|
threading = 0;
|
||||||
}
|
}
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
@@ -101,7 +101,7 @@ int main(){
|
|||||||
time(&dt);
|
time(&dt);
|
||||||
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
||||||
time(&t);
|
time(&t);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
55
sorting.c
55
sorting.c
@@ -144,13 +144,13 @@ int sort_type(const void *file0, const void *file1){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((file*)file0)->file_type == ((file*)file1)->file_type) {
|
if (((file*)file0)->file_type > ((file*)file1)->file_type) {
|
||||||
/*somehow relying on the else below, occasionaly trips either one of the checked for conditions*/
|
|
||||||
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
|
||||||
} else if (((file*)file0)->file_type > ((file*)file1)->file_type) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else if (((file*)file0)->file_type < ((file*)file1)->file_type) {
|
||||||
return 1;
|
return 1;
|
||||||
|
} else {
|
||||||
|
return sort_natural(file0, file1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int sort_size(const void *file0, const void *file1){
|
int sort_size(const void *file0, const void *file1){
|
||||||
|
|
||||||
@@ -161,10 +161,43 @@ int sort_size(const void *file0, const void *file1){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((file*)file0)->file_size == ((file*)file1)->file_size) {
|
if (((file*)file0)->file_size > ((file*)file1)->file_size) {
|
||||||
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
|
||||||
} else if (((file*)file0)->file_size > ((file*)file1)->file_size) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else if (((file*)file0)->file_size < ((file*)file1)->file_size) {
|
||||||
return 1;
|
return 1;
|
||||||
|
} else {
|
||||||
|
return sort_natural(file0, file1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int sort_extension(const void *file0, const void *file1){
|
||||||
|
|
||||||
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *extension0 = strrchr(((file*)file0)->file_name, '.');
|
||||||
|
char *extension1 = strrchr(((file*)file1)->file_name, '.');
|
||||||
|
|
||||||
|
if (extension0 && extension1) {
|
||||||
|
if ((strcmp(extension0, extension1)) == 0) {
|
||||||
|
return sort_natural(file0, file1);
|
||||||
|
} else {
|
||||||
|
file f0;
|
||||||
|
file f1;
|
||||||
|
memcpy(&f0, file0, sizeof(file));
|
||||||
|
memcpy(&f1, file1, sizeof(file));
|
||||||
|
f0.file_name = extension0;
|
||||||
|
f1.file_name = extension1;
|
||||||
|
return sort_natural(&f0, &f1);
|
||||||
|
}
|
||||||
|
} else if (extension0 != NULL && extension1 == NULL) {
|
||||||
|
return 1;
|
||||||
|
} else if (extension0 == NULL && extension1 != NULL) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return sort_natural(file0, file1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -183,7 +183,7 @@ void *thread_rgt(){
|
|||||||
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 {
|
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) {
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < rgt_file_count; i++) {
|
for (i = 0; i < rgt_file_count; i++) {
|
||||||
|
Reference in New Issue
Block a user