Compare commits

..

4 commits

4 changed files with 138 additions and 10 deletions

View file

@ -44,6 +44,9 @@ right: go to child dir
enter: go to child dir/open file
backspace: go to parent dir
o: open file with
O: open file with a GUI program detached from file manager
g: go to top
G: go to bottom
@ -74,14 +77,13 @@ space: mark file
a: mark all files in directory
d: trash
[1-9]: favourites/bookmarks (see customizing)
?: show help
q: exit with last dir written to file
ctrl+c exit without writing last dir
TO BE DONE:
o: open file with
O: open file with a GUI program detached from file manager
/: search
c: copy
@ -91,7 +93,6 @@ b: bulk rename
p: execute paste/move/delete/bulk_rename
[1-9]: favourites/bookmarks (see customization)
```
# Dependencies
@ -115,6 +116,19 @@ c() {
cd "$(cat "${XDG_CACHE_HOME:=${HOME}/.cache}/ccc/.ccc_d")"
}
```
## Environment variables
```sh
export CCC_LAST_D=~/.cache/ccc/.ccc_d
export CCC_FAV1=~/projects
export CCC_FAV2=~/.bashrc
export CCC_FAV3=~/Pictures/Wallpapers/
export CCC_FAV4=/usr/share
export CCC_FAV5=/
export CCC_FAV6=
export CCC_FAV7=
export CCC_FAV8=
export CCC_FAV9=
```
## Using `ccc` in neovim as a file picker
See [ccc.nvim](https://github.com/night0721/ccc.nvim)

39
ccc.1
View file

@ -24,6 +24,9 @@ right: go to child dir
enter: go to child dir/open file
backspace: go to parent dir
o: open file with
O: open file with a GUI program detached from file manager
g: go to top
G: go to bottom
@ -54,10 +57,11 @@ space: mark file
a: mark all files in directory
d: trash
[1-9]: favourites/bookmarks (see customizing)
?: show help
q: exit with last dir written to file
ctrl+c exit without writing last dir
.
.fi
.
@ -66,5 +70,38 @@ ctrl+c exit without writing last dir
.nf
Various settings can be changed in config.h file located in the program's directory.
.
.fi
.
.SH "CD on Exit for POSIX Shell"
.
.nf
# Add this to your .bashrc, .zshrc or equivalent.
# Run 'ccc' with 'c' or whatever you decide to name the function.
c() {
ccc "$@"
cd "$(cat "${XDG_CACHE_HOME:=${HOME}/.cache}/ccc/.ccc_d")"
}
.
.fi
.
.SH "Environment variables"
.
.nf
export CCC_LAST_D=~/.cache/ccc/.ccc_d
export CCC_FAV1=~/projects
export CCC_FAV2=~/.bashrc
export CCC_FAV3=~/Pictures/Wallpapers/
export CCC_FAV4=/usr/share
export CCC_FAV5=/
export CCC_FAV6=
export CCC_FAV7=
export CCC_FAV8=
export CCC_FAV9=
.
.fi

85
ccc.c
View file

@ -71,6 +71,8 @@ void start_shell(void);
void yank_clipboard(void);
void view_file_attr(void);
void show_history(void);
void open_with(void);
void open_detached(void);
void wpprintw(const char *fmt, ...);
void move_cursor(int row, int col);
int readch(void);
@ -363,7 +365,12 @@ int main(int argc, char **argv)
break;
case 'o':
open_with();
break;
case 'O':
open_detached();
break;
case 'x':
view_file_attr();
break;
@ -372,6 +379,18 @@ int main(int argc, char **argv)
show_history();
break;
case '1': case '2': case '3': case '4': case '5': case '6': case '7':
case '8': case '9':;
char envname[9];
snprintf(envname, 9, "CCC_FAV%d", ch - '0');
char *fav = getenv(envname);
if (fav && !strcmp(fav, "")) {
char dir[PATH_MAX];
strcpy(dir, fav);
change_dir(dir, 0, 0);
}
break;
/* mark one file */
case SPACE:
add_file_stat(files->items[sel_file].name, files->items[sel_file].path, 1);
@ -440,9 +459,8 @@ void cleanup(void)
if (files->length != 0) {
arraylist_free(files);
}
if (marked->length != 0) {
arraylist_free(marked);
}
free(marked->items);
free(marked);
/* Restore old terminal settings */
tcsetattr(STDIN_FILENO, TCSAFLUSH, &oldt);
bprintf("\033[2J\033[?1049l\033[?25h");
@ -1302,6 +1320,67 @@ void show_history(void)
readch();
}
void open_with(void)
{
char *input = get_panel_string("open with: ");
if (!input) {
return;
}
pid_t pid = fork();
if (pid == 0) {
/* Child process */
if (marked->length > 0) {
char *args[marked->length + 2];
args[0] = input;
for (int i = 0; i < marked->length; i++) {
args[i + 1] = marked->items[i].name;
}
args[marked->length + 1] = NULL;
execvp(input, args);
} else {
execlp(input, input, files->items[sel_file].name, NULL);
}
_exit(1); /* Exit if exec fails */
} else if (pid > 0) {
/* Parent process */
waitpid(pid, NULL, 0);
} else {
/* Fork failed */
wpprintw("fork failed: %s", strerror(errno));
}
}
void open_detached(void)
{
char *input = get_panel_string("open with (detached): ");
if (!input) {
return;
}
pid_t pid = fork();
if (pid == 0) {
/* Child process */
if (marked->length > 0) {
char *args[marked->length + 3];
args[0] = "nohup";
args[1] = input;
for (int i = 0; i < marked->length; i++) {
args[i + 2] = marked->items[i].name;
}
args[marked->length + 1] = NULL;
execvp("nohup", args);
} else {
execlp("nohup", "nohup", input, files->items[sel_file].name, NULL);
}
_exit(1); /* Exit if exec fails */
} else if (pid > 0) {
/* Parent process */
waitpid(pid, NULL, 0);
} else {
/* Fork failed */
wpprintw("fork failed: %s", strerror(errno));
}
}
/*
* Print line to the panel
*/

2
file.c
View file

@ -24,7 +24,6 @@ void arraylist_free(ArrayList *list)
if (list->items[i].stats != NULL)
free(list->items[i].stats);
}
free(list->items);
free(list);
}
@ -57,7 +56,6 @@ void arraylist_remove(ArrayList *list, long index)
free(list->items[index].name);
free(list->items[index].path);
free(list->items[index].stats);
free(list->items[index].icon);
*/
for (long i = index; i < list->length - 1; i++)
list->items[i] = list->items[i + 1];