diff options
Diffstat (limited to 'fm.c')
| -rw-r--r-- | fm.c | 50 |
1 files changed, 47 insertions, 3 deletions
@@ -14,6 +14,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> @@ -80,6 +81,36 @@ fm_file_items_realloc(file_list *l) l->items = xrealloc(l->items, sizeof(file_item) * l->cap); } +void +get_permission(mode_t mode, char *str) +{ + if (S_ISDIR(mode)) + str[0] = 'd'; /* Directory */ + else if (S_ISLNK(mode)) + str[0] = 'l'; /* Link */ + else if (S_ISCHR(mode)) + str[0] = 'c'; /* Charcter devices */ + else if (S_ISBLK(mode)) + str[0] = 'b'; /* Block devices */ + else if (S_ISFIFO(mode)) + str[0] = 'p'; /* FIFO */ + else if (S_ISSOCK(mode)) + str[0] = 's'; /* Socket */ + else + str[0] = '-'; /* Files */ + + str[1] = (mode & S_IRUSR) ? 'r' : '-'; + str[2] = (mode & S_IWUSR) ? 'w' : '-'; + str[3] = (mode & S_IXUSR) ? 'x' : '-'; + str[4] = (mode & S_IRGRP) ? 'r' : '-'; + str[5] = (mode & S_IWGRP) ? 'w' : '-'; + str[6] = (mode & S_IXGRP) ? 'x' : '-'; + str[7] = (mode & S_IROTH) ? 'r' : '-'; + str[8] = (mode & S_IWOTH) ? 'w' : '-'; + str[9] = (mode & S_IXOTH) ? 'x' : '-'; + str[10] = '\0'; +} + file_list * fm_getdir(file_list *list, const char *path) { @@ -100,6 +131,8 @@ fm_getdir(file_list *list, const char *path) } struct dirent *d; + struct stat st; + char filepath[PATH_MAX]; while ((d = readdir(dir)) != NULL) { if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) continue; @@ -117,6 +150,15 @@ fm_getdir(file_list *list, const char *path) new_list->items[new_list->count].is_dir = false; } + memset(filepath, 0, sizeof(filepath)); + snprintf(filepath, sizeof(filepath), "%s/%s", path, d->d_name); + + if (lstat(filepath, &st) == 0) { + get_permission( + st.st_mode, + new_list->items[new_list->count].permission); + } + new_list->count++; } @@ -414,9 +456,11 @@ create_status_bar_win(terminal *t) } void -draw_status_bar(window *bar_win, const char *cwd) +draw_status_bar(window *bar_win, const char *cwd, char permission[11]) { werase(bar_win->win); - - mvwprintw(bar_win->win, bar_win->height - 1, 0, "%s", cwd); + wattron(bar_win->win, COLOR_PAIR(COLOR_PAIR_FM_STATUS_BAR)); + mvwprintw(bar_win->win, bar_win->height - 1, 0, "%s %s", cwd, + permission); + wattroff(bar_win->win, COLOR_PAIR(COLOR_PAIR_FM_STATUS_BAR)); } |
