diff options
author | WlodekM <[email protected]> | 2025-02-15 15:07:08 +0200 |
---|---|---|
committer | WlodekM <[email protected]> | 2025-02-15 15:07:08 +0200 |
commit | caefa5d56294e1c9b0f4fa3503ffb1eff5a2f8ed (patch) | |
tree | d41d795b18b459625486eb8b401a69b7e5cd6a4f /progs/ls | |
parent | 6f22816a9a00e4d62a1f7106edf6ba8225b7901a (diff) |
ls colorse
Diffstat (limited to 'progs/ls')
-rw-r--r-- | progs/ls/ls.c | 12 |
1 files changed, 11 insertions, 1 deletions
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); } |