From 4ba777c4070a4e069adf01a2a166d836efa840c3 Mon Sep 17 00:00:00 2001 From: BerkinAKKAYA Date: Sat, 27 Mar 2021 21:42:00 +0000 Subject: [PATCH] Add Extension Exclusion Functionality --- README.md | 1 + src/ls.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fafce2a..d775b17 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - Colored output with icons - Fully customizable (see `config.py`) - Under 150 lines of code + - Hide Unwanted Extensions (Source Maps or Movie Subtitles, for example) ![SS1](https://github.com/BerkinAKKAYA/pythonls/blob/main/SS.jpg?raw=true) ![SS2](https://github.com/BerkinAKKAYA/pythonls/blob/main/SS.png?raw=true) diff --git a/src/ls.py b/src/ls.py index 8ff3b8a..d7dcdce 100755 --- a/src/ls.py +++ b/src/ls.py @@ -6,6 +6,7 @@ directoriesToList = list(filter(lambda x: x[0] != "-", args)) or ["."] depth = 1 sortBy = "fileType" +exclude = [] for arg in args: splitted = arg.split("=") @@ -26,6 +27,10 @@ if splitted[0] in ["-n", "--name"]: sortBy = "name" + if splitted[0] in ["-x", "--exclude"]: + exclude = splitted[1].split(",") + exclude = list(map(lambda ext: ext.strip(), exclude)) + def ToFullPath(path): result = path @@ -86,7 +91,9 @@ def PrintDirectory(path, indent=0, depth=1): # Print Files for file in files: extension = file.split(".")[-1] if "." in file else "" - PrintItem(extension, file, indent) + + if extension not in exclude: + PrintItem(extension, file, indent) for directory in directoriesToList: if depth < 1: