merge feature
This commit is contained in:
commit
4dcc886a15
3 changed files with 77 additions and 37 deletions
12
README.md
12
README.md
|
@ -19,7 +19,7 @@ Consider this project incomplete and WIP!
|
|||
| Marking and marking operations | | |
|
||||
| Other operations on files | | |
|
||||
| Image previews | | |
|
||||
| Help | | |
|
||||
| Help | X | |
|
||||
| History | | |
|
||||
| Bookmarks | | |
|
||||
| Bulk rename | | |
|
||||
|
@ -55,9 +55,9 @@ j: scroll down
|
|||
k: scroll up
|
||||
l: go to child dir
|
||||
|
||||
left: go to parent dir
|
||||
down: scroll down
|
||||
up: scroll up
|
||||
left: go to parent dir
|
||||
down: scroll down
|
||||
up: scroll up
|
||||
right: go to child dir
|
||||
|
||||
enter: go to child dir/open file
|
||||
|
@ -78,8 +78,12 @@ i: toggle file details
|
|||
X: toggle executable
|
||||
|
||||
A: show directory disk usage/block size
|
||||
|
||||
f: new file
|
||||
|
||||
space: mark file
|
||||
a: mark all files in directory
|
||||
d: trash
|
||||
|
||||
?: show help
|
||||
q: exit with last dir written to file
|
||||
|
|
31
ccc.1
31
ccc.1
|
@ -11,30 +11,45 @@ ccc is a rewrite of fff file manager in C aiming for usefulness and speed. The f
|
|||
.
|
||||
.nf
|
||||
|
||||
h: go to parent dir
|
||||
j: scroll down
|
||||
k: scroll up
|
||||
h: go to parent dir
|
||||
l: go to child dir
|
||||
|
||||
down: scroll down
|
||||
up: scroll up
|
||||
left: go to parent dir
|
||||
left: go to parent dir
|
||||
down: scroll down
|
||||
up: scroll up
|
||||
right: go to child dir
|
||||
|
||||
enter: go to child dir/open file
|
||||
backspace: go to parent dir
|
||||
|
||||
g: go to top
|
||||
gg: go to top
|
||||
G: go to bottom
|
||||
|
||||
t: go to trash
|
||||
~: go to home
|
||||
ctrl+u: jump up
|
||||
ctrl+d: jump down
|
||||
|
||||
t: go to trash dir
|
||||
~: go to home dir
|
||||
-: go to previous dir
|
||||
z: refresh current dir
|
||||
|
||||
i: toggle file details
|
||||
X: toggle executable
|
||||
|
||||
A: show directory disk usage/block size
|
||||
|
||||
f: new file
|
||||
|
||||
space: mark file
|
||||
a: mark all files in directory
|
||||
d: trash
|
||||
|
||||
?: show help
|
||||
q: exit with last dir written to file
|
||||
ctrl+c exit without writing last dir
|
||||
|
||||
q: exit
|
||||
.
|
||||
.fi
|
||||
.
|
||||
|
|
71
ccc.c
71
ccc.c
|
@ -32,6 +32,7 @@ void highlight_current_line();
|
|||
void show_file_content();
|
||||
void edit_file();
|
||||
void toggle_executable();
|
||||
void replace_home(char *str);
|
||||
int write_last_d();
|
||||
void create_file();
|
||||
void delete_files();
|
||||
|
@ -42,6 +43,7 @@ void draw_border_title(WINDOW *window, bool active);
|
|||
/* global variables */
|
||||
unsigned int focus = 0;
|
||||
long current_selection = 0;
|
||||
bool file_picker = false;
|
||||
bool to_open_file = false;
|
||||
bool dirs_size = DIRS_SIZE;
|
||||
bool show_hidden = SHOW_HIDDEN;
|
||||
|
@ -63,8 +65,12 @@ unsigned long total_dir_size;
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc == 2) {
|
||||
if (strcmp(argv[1], "-h") == 0)
|
||||
if (argc == 3) {
|
||||
if (strncmp(argv[2], "-p", 2) == 0)
|
||||
file_picker = true;
|
||||
}
|
||||
if (argc <= 3 && argc != 1) {
|
||||
if (strncmp(argv[1], "-h", 2) == 0)
|
||||
die("Usage: ccc filename");
|
||||
|
||||
struct stat st;
|
||||
|
@ -182,12 +188,24 @@ int main(int argc, char** argv)
|
|||
case 'l':
|
||||
strcpy(p_cwd, cwd);
|
||||
file c_file = files->items[current_selection];
|
||||
|
||||
/* check if it is directory or a regular file */
|
||||
if (strncmp(c_file.type, "DIR", 3) == 0) {
|
||||
/* change cwd to directory */
|
||||
change_dir(c_file.path, 0, 0);
|
||||
} else if (strncmp(c_file.type, "REG", 3) == 0) {
|
||||
edit_file();
|
||||
/* write opened file to a file for file pickers */
|
||||
if (file_picker) {
|
||||
char *opened_file_path = memalloc(PATH_MAX * sizeof(char));strcpy(opened_file_path, "~/.cache/ccc/opened_file");
|
||||
replace_home(opened_file_path);
|
||||
FILE *opened_file = fopen(opened_file_path, "w+");
|
||||
fprintf(opened_file, "%s\n", c_file.path);
|
||||
fclose(opened_file);
|
||||
endwin();
|
||||
return 0;
|
||||
} else {
|
||||
edit_file();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -380,7 +398,7 @@ void show_help()
|
|||
{
|
||||
wclear(directory_content);
|
||||
wclear(preview_content);
|
||||
wprintw(directory_content,"h: go to parent dir\nj: scroll down\nk: scroll up\nl: go to child dir\n\nleft: go to parent dir\ndown: scroll down\nup: scroll up\nright: go to child dir\n\nenter: go to child dir/open file\nbackspace: go to parent dir\n\ngg: go to top\nG: go to bottom\n\nctrl+u: jump up\nctrl+d: jump down\n\nt: go to trash dir\n~: go to home dir\n-: go to previous dir\nz: refresh current dir\n\ni: toggle file details\nX: toggle executable\n\nA: show directory disk usage/block size\nspace: mark file\na: mark all files in directory\n\n?: show help\nq: exit with last dir written to file\nctrl+c exit without writing last dir");
|
||||
wprintw(directory_content,"h: go to parent dir\nj: scroll down\nk: scroll up\nl: go to child dir\n\nleft: go to parent dir\ndown: scroll down\nup: scroll up\nright: go to child dir\n\nenter: go to child dir/open file\nbackspace: go to parent dir\n\ngg: go to top\nG: go to bottom\n\nctrl+u: jump up\nctrl+d: jump down\n\nt: go to trash dir\n~: go to home dir\n-: go to previous dir\nz: refresh current dir\n\ni: toggle file details\nX: toggle executable\n\nA: show directory disk usage/block size\n\nf: new file\n\nspace: mark file\na: mark all files in directory\nd: trash\n\n?: show help\nq: exit with last dir written to file\nctrl+c exit without writing last dir");
|
||||
wpprintw("Visit https://github.com/piotr-marendowski/ccc or use 'man ccc' for help");
|
||||
wrefresh(directory_content);
|
||||
wrefresh(preview_content);
|
||||
|
@ -402,6 +420,7 @@ char *check_trash_dir()
|
|||
char *trash_dir;
|
||||
#ifdef TRASH_DIR
|
||||
trash_dir = TRASH_DIR;
|
||||
strcpy(path, trash_dir);
|
||||
#endif
|
||||
|
||||
/* check if there is trash_dir */
|
||||
|
@ -412,16 +431,7 @@ char *check_trash_dir()
|
|||
/* if trash_dir has ~ then make it $HOME */
|
||||
/* use path as trash_dir */
|
||||
if (trash_dir[0] == '~') {
|
||||
char *home = getenv("HOME");
|
||||
if (home == NULL) {
|
||||
wpprintw("$HOME is not defined, can't read the trash directory");
|
||||
return NULL;
|
||||
}
|
||||
/* replace ~ with home */
|
||||
snprintf(path, PATH_MAX, "%s%s", home, trash_dir + 1);
|
||||
}
|
||||
else {
|
||||
strcpy(path, trash_dir);
|
||||
replace_home(path);
|
||||
}
|
||||
|
||||
/* if has access to trash_dir */
|
||||
|
@ -878,6 +888,19 @@ void toggle_executable()
|
|||
|
||||
}
|
||||
|
||||
void replace_home(char *str)
|
||||
{
|
||||
char *home = getenv("HOME");
|
||||
if (home == NULL) {
|
||||
wpprintw("$HOME is not defined");
|
||||
return;
|
||||
}
|
||||
char *after_tilde = estrdup(str + 1);
|
||||
/* replace ~ with home */
|
||||
snprintf(str, PATH_MAX, "%s%s", home, after_tilde);
|
||||
free(after_tilde);
|
||||
}
|
||||
|
||||
int write_last_d()
|
||||
{
|
||||
#ifdef LAST_D
|
||||
|
@ -890,27 +913,25 @@ int write_last_d()
|
|||
wpprintw("Cannot get CCC_LAST_D variable, is it defined?");
|
||||
return -1;
|
||||
} else {
|
||||
char *last_ddup = memalloc(PATH_MAX * sizeof(char));
|
||||
char *home = getenv("HOME");
|
||||
if (home == NULL) {
|
||||
wpprintw("$HOME is not defined");
|
||||
return -1;
|
||||
if (last_d[0] == '~') {
|
||||
replace_home(last_d);
|
||||
}
|
||||
/* replace ~ with home */
|
||||
snprintf(last_ddup, PATH_MAX, "%s%s", home, last_d + 1);
|
||||
|
||||
char *last_d_dir = strrchr(last_d, '/');
|
||||
char *last_ddup = estrdup(last_d);
|
||||
|
||||
char *last_d_dir = strrchr(last_ddup, '/');
|
||||
if (last_d_dir != NULL) {
|
||||
*last_d_dir = '\0'; /* truncate string */
|
||||
}
|
||||
mkdir_p(last_d);
|
||||
FILE *last_d_file = fopen(last_ddup, "w");
|
||||
mkdir_p(last_ddup);
|
||||
FILE *last_d_file = fopen(last_d, "w");
|
||||
if (last_d_file == NULL) {
|
||||
wpprintw("Cannot open last directory file");
|
||||
return -1;
|
||||
}
|
||||
fwrite(cwd, strlen(cwd), sizeof(char), last_d_file);
|
||||
fclose(last_d_file);
|
||||
free(last_ddup);
|
||||
free(last_d);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue