When collaborating with AI tools for code assistance, it's beneficial to provide them with an overview of your project's directory structure, excluding files specified in .gitignore
. This ensures that the AI has relevant context without being cluttered by unnecessary or ignored files. This gist sets up the ability to use git lsf
to list all relevant files and git lsfwd
to list files specific to the current working directory in a way that respects .gitignore
exclusions.
You can create a Git alias named lsf
to list all tracked and untracked files, excluding those ignored by Git. To set up this alias, execute the following command:
git config --global alias.lsf '!git ls-files --cached --others --exclude-standard'
For files specific to the current working directory, create a custom script named git-lsfwd
in your local PATH
. This script ensures files listed are relative to the current directory within the repository.
-
Create the script in
~/.local/bin
:mkdir -p ~/.local/bin touch ~/.local/bin/git-lsfwd
Edit
~/.local/bin/git-lsfwd
and save:#!/bin/bash git lsf | grep "^$(pwd | sed "s|$(git rev-parse --show-toplevel)/||")"
-
Make the script executable:
chmod +x ~/.local/bin/git-lsfwd
-
Ensure
~/.local/bin
is in yourPATH
. Add this line to your shell configuration file (e.g.,~/.bashrc
,~/.zshrc
):export PATH=$HOME/.local/bin:$PATH
Once the script is in place, test it:
git lsfwd
This command lists all files in the current directory context that are tracked or untracked, excluding those ignored by .gitignore
.
Consider the following project structure:
my_project/
├── .gitignore
├── src/
│ ├── main.py
│ └── utils.py
├── data/
│ ├── raw_data.csv
│ └── processed_data.csv
├── README.md
└── notes.txt
And a .gitignore
file with the following content:
# Ignore data directory
data/
# Ignore notes
notes.txt
Run:
git lsf
Output:
src/main.py
src/utils.py
README.md
Navigate to a subdirectory (e.g., src/
) and run:
git lsfwd
Output:
main.py
utils.py
- Efficiency: Quickly gather a filtered view of your project files.
- Focus: Supply relevant directory-specific context to AI tools.
- Convenience: Automate context gathering with minimal setup.