Compare commits
4 commits
ff79dbcd64
...
addc8e2c9d
Author | SHA1 | Date | |
---|---|---|---|
addc8e2c9d | |||
6f9c5ac5ed | |||
c50af43b7b | |||
5da3b3b6be |
4 changed files with 138 additions and 10 deletions
22
README.md
22
README.md
|
@ -44,6 +44,9 @@ right: go to child dir
|
||||||
enter: go to child dir/open file
|
enter: go to child dir/open file
|
||||||
backspace: go to parent dir
|
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 top
|
||||||
G: go to bottom
|
G: go to bottom
|
||||||
|
|
||||||
|
@ -74,14 +77,13 @@ space: mark file
|
||||||
a: mark all files in directory
|
a: mark all files in directory
|
||||||
d: trash
|
d: trash
|
||||||
|
|
||||||
|
[1-9]: favourites/bookmarks (see customizing)
|
||||||
|
|
||||||
?: show help
|
?: show help
|
||||||
q: exit with last dir written to file
|
q: exit with last dir written to file
|
||||||
ctrl+c exit without writing last dir
|
ctrl+c exit without writing last dir
|
||||||
|
|
||||||
TO BE DONE:
|
TO BE DONE:
|
||||||
o: open file with
|
|
||||||
O: open file with a GUI program detached from file manager
|
|
||||||
|
|
||||||
/: search
|
/: search
|
||||||
|
|
||||||
c: copy
|
c: copy
|
||||||
|
@ -91,7 +93,6 @@ b: bulk rename
|
||||||
|
|
||||||
p: execute paste/move/delete/bulk_rename
|
p: execute paste/move/delete/bulk_rename
|
||||||
|
|
||||||
[1-9]: favourites/bookmarks (see customization)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
@ -115,6 +116,19 @@ c() {
|
||||||
cd "$(cat "${XDG_CACHE_HOME:=${HOME}/.cache}/ccc/.ccc_d")"
|
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
|
## Using `ccc` in neovim as a file picker
|
||||||
See [ccc.nvim](https://github.com/night0721/ccc.nvim)
|
See [ccc.nvim](https://github.com/night0721/ccc.nvim)
|
||||||
|
|
||||||
|
|
39
ccc.1
39
ccc.1
|
@ -24,6 +24,9 @@ right: go to child dir
|
||||||
enter: go to child dir/open file
|
enter: go to child dir/open file
|
||||||
backspace: go to parent dir
|
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 top
|
||||||
G: go to bottom
|
G: go to bottom
|
||||||
|
|
||||||
|
@ -54,10 +57,11 @@ space: mark file
|
||||||
a: mark all files in directory
|
a: mark all files in directory
|
||||||
d: trash
|
d: trash
|
||||||
|
|
||||||
|
[1-9]: favourites/bookmarks (see customizing)
|
||||||
|
|
||||||
?: show help
|
?: show help
|
||||||
q: exit with last dir written to file
|
q: exit with last dir written to file
|
||||||
ctrl+c exit without writing last dir
|
ctrl+c exit without writing last dir
|
||||||
|
|
||||||
.
|
.
|
||||||
.fi
|
.fi
|
||||||
.
|
.
|
||||||
|
@ -66,5 +70,38 @@ ctrl+c exit without writing last dir
|
||||||
.nf
|
.nf
|
||||||
|
|
||||||
Various settings can be changed in config.h file located in the program's directory.
|
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
|
.fi
|
||||||
|
|
85
ccc.c
85
ccc.c
|
@ -71,6 +71,8 @@ void start_shell(void);
|
||||||
void yank_clipboard(void);
|
void yank_clipboard(void);
|
||||||
void view_file_attr(void);
|
void view_file_attr(void);
|
||||||
void show_history(void);
|
void show_history(void);
|
||||||
|
void open_with(void);
|
||||||
|
void open_detached(void);
|
||||||
void wpprintw(const char *fmt, ...);
|
void wpprintw(const char *fmt, ...);
|
||||||
void move_cursor(int row, int col);
|
void move_cursor(int row, int col);
|
||||||
int readch(void);
|
int readch(void);
|
||||||
|
@ -363,7 +365,12 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
|
open_with();
|
||||||
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
|
open_detached();
|
||||||
|
break;
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
view_file_attr();
|
view_file_attr();
|
||||||
break;
|
break;
|
||||||
|
@ -372,6 +379,18 @@ int main(int argc, char **argv)
|
||||||
show_history();
|
show_history();
|
||||||
break;
|
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 */
|
/* mark one file */
|
||||||
case SPACE:
|
case SPACE:
|
||||||
add_file_stat(files->items[sel_file].name, files->items[sel_file].path, 1);
|
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) {
|
if (files->length != 0) {
|
||||||
arraylist_free(files);
|
arraylist_free(files);
|
||||||
}
|
}
|
||||||
if (marked->length != 0) {
|
free(marked->items);
|
||||||
arraylist_free(marked);
|
free(marked);
|
||||||
}
|
|
||||||
/* Restore old terminal settings */
|
/* Restore old terminal settings */
|
||||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &oldt);
|
tcsetattr(STDIN_FILENO, TCSAFLUSH, &oldt);
|
||||||
bprintf("\033[2J\033[?1049l\033[?25h");
|
bprintf("\033[2J\033[?1049l\033[?25h");
|
||||||
|
@ -1302,6 +1320,67 @@ void show_history(void)
|
||||||
readch();
|
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
|
* Print line to the panel
|
||||||
*/
|
*/
|
||||||
|
|
2
file.c
2
file.c
|
@ -24,7 +24,6 @@ void arraylist_free(ArrayList *list)
|
||||||
if (list->items[i].stats != NULL)
|
if (list->items[i].stats != NULL)
|
||||||
free(list->items[i].stats);
|
free(list->items[i].stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(list->items);
|
free(list->items);
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +56,6 @@ void arraylist_remove(ArrayList *list, long index)
|
||||||
free(list->items[index].name);
|
free(list->items[index].name);
|
||||||
free(list->items[index].path);
|
free(list->items[index].path);
|
||||||
free(list->items[index].stats);
|
free(list->items[index].stats);
|
||||||
free(list->items[index].icon);
|
|
||||||
*/
|
*/
|
||||||
for (long i = index; i < list->length - 1; i++)
|
for (long i = index; i < list->length - 1; i++)
|
||||||
list->items[i] = list->items[i + 1];
|
list->items[i] = list->items[i + 1];
|
||||||
|
|
Loading…
Reference in a new issue