Compare commits
4 commits
d67e01086c
...
3fe500d761
Author | SHA1 | Date | |
---|---|---|---|
3fe500d761 | |||
34254a9fe4 | |||
5835f5b8f7 | |||
462ce7b792 |
1 changed files with 56 additions and 54 deletions
110
ccc.c
110
ccc.c
|
@ -152,7 +152,6 @@ int main(int argc, char **argv)
|
||||||
int ch, ch2;
|
int ch, ch2;
|
||||||
int run = 1;
|
int run = 1;
|
||||||
while (run) {
|
while (run) {
|
||||||
|
|
||||||
ch = read_key();
|
ch = read_key();
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/* quit */
|
/* quit */
|
||||||
|
@ -173,7 +172,7 @@ int main(int argc, char **argv)
|
||||||
/* go back */
|
/* go back */
|
||||||
case BACKSPACE:
|
case BACKSPACE:
|
||||||
case ARROW_LEFT:
|
case ARROW_LEFT:
|
||||||
case 'h':;
|
case 'h':
|
||||||
/* get parent directory */
|
/* get parent directory */
|
||||||
strcpy(p_cwd, cwd);
|
strcpy(p_cwd, cwd);
|
||||||
char *last_slash = strrchr(cwd, '/');
|
char *last_slash = strrchr(cwd, '/');
|
||||||
|
@ -191,29 +190,29 @@ int main(int argc, char **argv)
|
||||||
case ENTER:
|
case ENTER:
|
||||||
case ARROW_RIGHT:
|
case ARROW_RIGHT:
|
||||||
case 'l':
|
case 'l':
|
||||||
strcpy(p_cwd, cwd);
|
strcpy(p_cwd, cwd);
|
||||||
file c_file = files->items[sel_file];
|
file c_file = files->items[sel_file];
|
||||||
|
|
||||||
/* Check if it is directory or a regular file */
|
/* Check if it is directory or a regular file */
|
||||||
if (c_file.type == DRY) {
|
if (c_file.type == DRY) {
|
||||||
/* Change cwd to directory */
|
/* Change cwd to directory */
|
||||||
change_dir(c_file.path, 0, 0);
|
change_dir(c_file.path, 0, 0);
|
||||||
} else if (c_file.type == REG) {
|
} else if (c_file.type == REG) {
|
||||||
/* Write opened file to a file for file pickers */
|
/* Write opened file to a file for file pickers */
|
||||||
if (file_picker) {
|
if (file_picker) {
|
||||||
char *opened_file_path = memalloc(PATH_MAX);
|
char *opened_file_path = memalloc(PATH_MAX);
|
||||||
strcpy(opened_file_path, "~/.cache/ccc/opened_file");
|
strcpy(opened_file_path, "~/.cache/ccc/opened_file");
|
||||||
opened_file_path = replace_home(opened_file_path);
|
opened_file_path = replace_home(opened_file_path);
|
||||||
FILE *opened_file = fopen(opened_file_path, "w+");
|
FILE *opened_file = fopen(opened_file_path, "w+");
|
||||||
fprintf(opened_file, "%s\n", c_file.path);
|
fprintf(opened_file, "%s\n", c_file.path);
|
||||||
fclose(opened_file);
|
fclose(opened_file);
|
||||||
cleanup();
|
cleanup();
|
||||||
run = 0;
|
run = 0;
|
||||||
} else {
|
} else {
|
||||||
edit_file();
|
edit_file();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* jump up */
|
/* jump up */
|
||||||
case CTRLU:
|
case CTRLU:
|
||||||
|
@ -255,9 +254,9 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* jump to the bottom */
|
/* jump to the bottom */
|
||||||
case 'G':
|
case 'G':
|
||||||
sel_file = (files->length - 1);
|
sel_file = (files->length - 1);
|
||||||
list_files();
|
list_files();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* jump to the top */
|
/* jump to the top */
|
||||||
case 'g':
|
case 'g':
|
||||||
|
@ -369,34 +368,34 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* move */
|
/* move */
|
||||||
case 'm':
|
case 'm':
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* copy */
|
/* copy */
|
||||||
case 'c':
|
case 'c':
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* symbolic link */
|
/* symbolic link */
|
||||||
case 's':
|
case 's':
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* bulk rename */
|
/* bulk rename */
|
||||||
case 'b':
|
case 'b':
|
||||||
if (marked->length) {
|
if (marked->length) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,13 +996,20 @@ void edit_file(void)
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
char *filename = files->items[sel_file].path;
|
char *filename = files->items[sel_file].path;
|
||||||
/* 1 for space 1 for null */
|
|
||||||
int length = strlen(editor) + strlen(filename) + 2;
|
|
||||||
char command[length];
|
|
||||||
|
|
||||||
snprintf(command, length, "%s %s", editor, filename);
|
pid_t pid = fork();
|
||||||
system(command);
|
if (pid == 0) {
|
||||||
list_files();
|
/* Child process */
|
||||||
|
execlp(editor, editor, filename, NULL);
|
||||||
|
_exit(1); /* Exit if exec fails */
|
||||||
|
} else if (pid > 0) {
|
||||||
|
/* Parent process */
|
||||||
|
waitpid(pid, NULL, 0);
|
||||||
|
list_files();
|
||||||
|
} else {
|
||||||
|
/* Fork failed */
|
||||||
|
wpprintw("fork failed: %s", strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1242,10 +1248,6 @@ int read_key(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *f = fopen("/home/night/a", "a");
|
|
||||||
fprintf(f, "c: %d\n", c);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
if (c == '\033') {
|
if (c == '\033') {
|
||||||
char seq[3];
|
char seq[3];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue