Skip to content

Instantly share code, notes, and snippets.

@zachshallbetter
Created June 2, 2023 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachshallbetter/657b6ef90d62047396b9bb18d5311876 to your computer and use it in GitHub Desktop.
Save zachshallbetter/657b6ef90d62047396b9bb18d5311876 to your computer and use it in GitHub Desktop.
Structured directory overview shell script

show_structure.sh

This is a shell script that provides a structured overview of your directory, excluding directories listed in .gitignore and any file or directory starting with a dot. The structure is printed up to three levels deep (-L 3).

Dependencies

This script uses the tree and rg (ripgrep) commands. If these are not installed on your system, you can install them with the following commands:

On Ubuntu/Debian:

sudo apt-get install tree ripgrep

On MacOS (using Homebrew):

brew install tree ripgrep

Usage

To use this script, you need to make it executable. You can do this by running the following command in your terminal:

chmod +x show_structure.sh

Then, you can run the script with:

./show_structure.sh

The script will print a tree-like structure of your directory up to three levels deep, excluding directories listed in your .gitignore and any file or directory starting with a dot.


Please adapt the installation commands if you are using a different package manager or operating system.

#!/bin/bash
# Exclude directories listed in .gitignore and any file or directory starting with a dot
tree -L 3 -I "$(rg --files -0 | tr '\\0' '\\n' | sed 's/^/.\//'),.*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment