CLI tools for quickly exploring the directory structure.
They were tested to work on macOS and Ubuntu in ZSH.
A script that piggy bags on the output of ls
by adding colors on top
of it. It allows to gray out unimportant files and to associate some
colors with certain file extensions.
You can customize the colors by editing the color_definitions.py file
Additionally, if you are not on macOS, you would have to modify the
ls
command as it has different parameters depending on the system.
To do so, open the dir_explorer/list_files.py
file and modify the ls
variable to a command that should be used as a basis. The command should
have the flags necessary to output the files in the long format.
This tool does not have any dependencies.
The only think you would want to do is to add this to your .bashrc/.zshrc file:
alias l="python3 ~/path/to/dir_explorer/dir_explorer/list_files.py"
Additionally, you could customize the ls
variable in
dir_explorer/list_files.py
to customize the default arguments that
get passed to the ls
command. By default, it calls ls
command on
Linux and gls
on macOS.
Remember to change ~/path/to/dir_explorer/
to an actual path.
Then you can just press l
in the terminal, hit ENTER, and look in awe at
all the colors!
And just like with regular ls
command, you can provide a directory name as the
second parameter. You can even use a wildcard or multiple directories. Example:
l ~/Downloads/*.png ~/Documents/
Or display files recursively:
l -R ~/Downloads
list_view.py
aims to provide an experience similar to Finder's list
view right in your terminal. It is most useful for when you need to
explore several directories and quickly move between levels as you
search for the thing you are looking for.
You can customize the colors by editing the color_definitions.py file.
Additionally, you can set the environmental variable EDITOR
to a CLI editor
you want to use for opening text files
Create a virtual environment:
python -m venv venv
If you choose to omit the creation of virtual environment, then you would have
to change the location of python executable in dir_explorer/list_view
.
Run pip install:
./venv/bin/pip install -r requirements.txt
Then, add the f
bash function that is defined in
./dir_explorer/list_view
to your ~/.zshrc
. Alternativelly, you can
source that file directly.
Don't forget to change the script_dir
variable to the location of
./dir_explorer/list_view
Then you can call f
or f <some path>
to display a directory in a list
view.
Controls:
Up / Down Arrow
- navigate Up / DownLeft / Right Arrow
- open parent / child directory
Instead of the arrow keys, you can also use WSAD
or HJKL
.
Next, you can cd
to the selected directory by pressing the Space key
.
For opening files, you can use E
to open it in the text editor, O
for
opening it in the default application, or Space bar to use the best application
for that file type.
Additionally, macOS users can press the P
key to quickly preview the file or
directory.
After that, feel free to modify the dir_explorer/color_definitions.py
as you see fit. That file defines the colors to use for each file type.
For color codes in modern terminals, see this nice article.
The color_definitions.py
file contains a dictionary
color_definitions
that associates a human-friendly label with one of
the 255 colors.
Then, in known_file_extensions
, file extensions are assigned a certain
color.
Also, for extensions like .zshrc
, .eslitrc
and other rc
files,
there is a useful known_file_extension_endings
dictionary that defines
colors for files whose extensions end with a given string. Finally,
there is a known_file_names
dictionary for when you need to associate
an entire file name with a color.