Skip to main content
4 of 10
updated to find exclude file using git commands
user avatar
user avatar

Tree supports the -I flag.

-I pattern
   Do not list those files that match the wild-card pattern.

For example,

tree -I "$( tr '\n' '\|' <  $( git config --get core.excludesfile ) )" /foo

For convenience you could put this into a function:

function tree {

    git_ignore_file=$( git config --get core.excludesfile )
    
    if [[ -f ${git_ignore_file} ]] ; then
        tree -I"$( tr '\n' '\|' < "${git_ignore_file}" )" "${@}"
    else 
        tree "${@}"
    fi
}

git config --get core.excludesfile will return one file in the following precedence: local (repo) > global (~/.gitconfig) > system (default?).

if you want to exclude them all then you can use the --get-all flag instead of --get.

user14755