From caefa5d56294e1c9b0f4fa3503ffb1eff5a2f8ed Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sat, 15 Feb 2025 15:07:08 +0200 Subject: ls colorse --- progs/ls/ls.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'progs/ls/ls.c') diff --git a/progs/ls/ls.c b/progs/ls/ls.c index 976e8c9..cdac6e8 100644 --- a/progs/ls/ls.c +++ b/progs/ls/ls.c @@ -42,7 +42,17 @@ int main(int argc, char *argv[]) { //TODO - sort if (d) { while ((dir = readdir(d)) != NULL) { - printf("%s\n", dir->d_name); + struct stat path_stat; + char path[256] = {0}; + joinPath(path, dirp, dir->d_name); + stat(path, &path_stat); + if (S_ISDIR(path_stat.st_mode)) { + printf("\e[94m%s\e[0m\n", dir->d_name); + } else if (!access(path, X_OK)) { + printf("\e[92m%s\e[0m\n", dir->d_name); + } else { + printf("%s\n", dir->d_name); + } } closedir(d); } -- cgit 1.4.1-2-gfad0