open file with argument
This commit is contained in:
parent
93c1e5f8c2
commit
da2e1ee144
3 changed files with 23 additions and 8 deletions
11
ccc.c
11
ccc.c
|
@ -40,6 +40,7 @@ void draw_border_title(WINDOW *window, bool active);
|
|||
/* global variables */
|
||||
unsigned int focus = 0;
|
||||
long current_selection = 0;
|
||||
bool to_open_file = false;
|
||||
bool dirs_size = DIRS_SIZE;
|
||||
bool show_hidden = SHOW_HIDDEN;
|
||||
bool file_details = SHOW_DETAILS;
|
||||
|
@ -73,6 +74,9 @@ int main(int argc, char** argv)
|
|||
perror("ccc");
|
||||
die("Error from chdir");
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
to_open_file = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* check if it is interactive shell */
|
||||
|
@ -117,7 +121,12 @@ int main(int argc, char** argv)
|
|||
getcwd(cwd, PATH_MAX);
|
||||
p_cwd = memalloc(PATH_MAX * sizeof(char));
|
||||
start_ccc();
|
||||
|
||||
populate_files(cwd, 0);
|
||||
if (to_open_file) {
|
||||
current_selection = arraylist_search(files, argv[1], true);
|
||||
highlight_current_line();
|
||||
}
|
||||
|
||||
int ch, ch2;
|
||||
while (1) {
|
||||
|
@ -735,7 +744,7 @@ void highlight_current_line()
|
|||
char *line = get_line(files, i, file_details);
|
||||
int color = files->items[i].color;
|
||||
/* check is file marked for action */
|
||||
bool is_marked = arraylist_includes(marked, files->items[i].path);
|
||||
bool is_marked = arraylist_search(marked, files->items[i].path, false) != -1;
|
||||
if (is_marked) {
|
||||
/* show file is selected */
|
||||
wattron(directory_content, COLOR_PAIR(7));
|
||||
|
|
16
file.c
16
file.c
|
@ -34,15 +34,21 @@ void arraylist_free(ArrayList *list)
|
|||
list->length = 0;
|
||||
}
|
||||
|
||||
bool arraylist_includes(ArrayList *list, char *path)
|
||||
long arraylist_search(ArrayList *list, char *path, bool bname)
|
||||
{
|
||||
for (int i = 0; i < list->length; i++) {
|
||||
if (strcmp(list->items[i].path, path) == 0) {
|
||||
return true;
|
||||
for (long i = 0; i < list->length; i++) {
|
||||
if (!bname && strcmp(list->items[i].path, path) == 0) {
|
||||
return i;
|
||||
}
|
||||
if (bname) {
|
||||
char *fbname = basename(list->items[i].path);
|
||||
if (fbname != NULL && strcmp(fbname, path) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void arraylist_remove(ArrayList *list, long index)
|
||||
|
|
2
file.h
2
file.h
|
@ -19,7 +19,7 @@ typedef struct ArrayList {
|
|||
|
||||
ArrayList *arraylist_init(size_t capacity);
|
||||
void arraylist_free(ArrayList *list);
|
||||
bool arraylist_includes(ArrayList *list, char *path);
|
||||
long arraylist_search(ArrayList *list, char *path, bool bname);
|
||||
void arraylist_remove(ArrayList *list, long index);
|
||||
void arraylist_add(ArrayList *list, char *filepath, char *stats, char *type, wchar_t *icon, int color, bool marked, bool force);
|
||||
char *get_line(ArrayList *list, long index, bool detail);
|
||||
|
|
Loading…
Reference in a new issue