use ~ to go to home
This commit is contained in:
parent
b8a51aef02
commit
b93b1bcda1
1 changed files with 32 additions and 15 deletions
47
ccc.c
47
ccc.c
|
@ -24,6 +24,7 @@ typedef struct {
|
||||||
} WIN_STRUCT;
|
} WIN_STRUCT;
|
||||||
|
|
||||||
/* functions' definitions */
|
/* functions' definitions */
|
||||||
|
void change_dir();
|
||||||
void list_files(const char *path);
|
void list_files(const char *path);
|
||||||
int get_directory_size(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
|
int get_directory_size(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
|
||||||
long add_file_stat(char *filename);
|
long add_file_stat(char *filename);
|
||||||
|
@ -57,7 +58,8 @@ int main(int argc, char** argv)
|
||||||
die("ccc: No tty detected. ccc requires an interactive shell to run.\n");
|
die("ccc: No tty detected. ccc requires an interactive shell to run.\n");
|
||||||
|
|
||||||
/* initialize screen, don't print special chars,
|
/* initialize screen, don't print special chars,
|
||||||
* make ctrl + c work, don't show cursor */
|
* make ctrl + c work, don't show cursor
|
||||||
|
* enable arrow keys */
|
||||||
initscr();
|
initscr();
|
||||||
noecho();
|
noecho();
|
||||||
cbreak();
|
cbreak();
|
||||||
|
@ -96,7 +98,7 @@ int main(int argc, char** argv)
|
||||||
die("ccc: Terminal size needs to be at least 80x24\n");
|
die("ccc: Terminal size needs to be at least 80x24\n");
|
||||||
}
|
}
|
||||||
ch = getch();
|
ch = getch();
|
||||||
printf("%d ",ch);
|
/* printf("%d ",ch); */
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/* quit */
|
/* quit */
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -105,24 +107,18 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
/* reload */
|
/* reload */
|
||||||
case '.':
|
case '.':
|
||||||
clear_files();
|
change_dir();
|
||||||
list_files(cwd);
|
|
||||||
current_selection = 0;
|
|
||||||
highlight_current_line();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* go back by backspace or h or left arrow */
|
/* go back by backspace or h or left arrow */
|
||||||
case 127:
|
case 127:
|
||||||
case 260:
|
case 260:
|
||||||
case 'h':
|
case 'h':;
|
||||||
clear_files();
|
|
||||||
/* get parent directory */
|
/* get parent directory */
|
||||||
char *last_slash = strrchr(cwd, '/');
|
char *last_slash = strrchr(cwd, '/');
|
||||||
if (last_slash != NULL) {
|
if (last_slash != NULL) {
|
||||||
*last_slash = '\0';
|
*last_slash = '\0';
|
||||||
list_files(cwd);
|
change_dir();
|
||||||
current_selection = 0;
|
|
||||||
highlight_current_line();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -136,10 +132,7 @@ int main(int argc, char** argv)
|
||||||
if (strncmp(file->type, "DIR", 3) == 0) {
|
if (strncmp(file->type, "DIR", 3) == 0) {
|
||||||
/* change cwd to directory */
|
/* change cwd to directory */
|
||||||
strcpy(cwd, file->path);
|
strcpy(cwd, file->path);
|
||||||
clear_files();
|
change_dir();
|
||||||
list_files(cwd);
|
|
||||||
current_selection = 0;
|
|
||||||
highlight_current_line();
|
|
||||||
} else if (strncmp(file->type, "REG", 3) == 0) {
|
} else if (strncmp(file->type, "REG", 3) == 0) {
|
||||||
edit_file();
|
edit_file();
|
||||||
}
|
}
|
||||||
|
@ -208,6 +201,19 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* ~ to go home */
|
||||||
|
case 126:;
|
||||||
|
char *home = getenv("HOME");
|
||||||
|
if (home == NULL) {
|
||||||
|
wclear(panel);
|
||||||
|
wprintw(panel, "$HOME is not defined");
|
||||||
|
wrefresh(panel);
|
||||||
|
} else {
|
||||||
|
strcpy(cwd, home);
|
||||||
|
change_dir();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
/* mark files by space */
|
/* mark files by space */
|
||||||
case 32:
|
case 32:
|
||||||
;
|
;
|
||||||
|
@ -234,6 +240,17 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change directory in window
|
||||||
|
*/
|
||||||
|
void change_dir()
|
||||||
|
{
|
||||||
|
clear_files();
|
||||||
|
list_files(cwd);
|
||||||
|
current_selection = 0;
|
||||||
|
highlight_current_line();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the provided directory and list all files to window 0
|
* Read the provided directory and list all files to window 0
|
||||||
* ep->d_name -> filename
|
* ep->d_name -> filename
|
||||||
|
|
Loading…
Reference in a new issue