回答:
これは役立つかもしれません:フィルターとgitほぼ互換性のある方法で無視されたファイルをリストしますtree:
function tree-git-ignore {
# tree respecting gitignore
local ignored=$(git ls-files -ci --others --directory --exclude-standard)
local ignored_filter=$(echo "$ignored" \
| egrep -v "^#.*$|^[[:space:]]*$" \
| sed 's~^/~~' \
| sed 's~/$~~' \
| tr "\\n" "|")
tree --prune -I ".git|${ignored_filter: : -1}" "$@"
}
ツリーは-Iフラグをサポートしています。
-I pattern Do not list those files that match the wild-card pattern.
ツリーは、それに一致するすべてのファイル/ディレクトリを除外する単一のパターンをサポートします。
Gitの無視ファイルはもう少し複雑です。
除外は、複数のファイルから来ることができる $HOME/.config/git/ignore、の出力git config --get core.excludesfile、.gitignore(ディレクトリごと)、~/.gitignoreおよびより(参照しますman gitignore)。
別の問題は、treeサポートするパターンがgitの動作と異なることです(@Brad Uraniが指摘)。
しかし、私たちは近づきます...
tree -I "$(grep -hvE '^$|^#' {~/,,$(git rev-parse --show-toplevel)/}.gitignore|sed 's:/$::'|tr \\n '\|')"
または関数として:
function gtree {
git_ignore_files=("$(git config --get core.excludesfile)" .gitignore ~/.gitignore)
ignore_pattern="$(grep -hvE '^$|^#' "${git_ignore_files[@]}" 2>/dev/null|sed 's:/$::'|tr '\n' '\|')"
if git status &> /dev/null && [[ -n "${ignore_pattern}" ]]; then
tree -I "${ignore_pattern}" "${@}"
else
tree "${@}"
fi
}
gitコマンドを使用してファイルを検索するように回答を更新しました。何が返されるかは、設定によって異なります。
~/.gitignoreはシンボリックリンクだからだと思う。私はgit、何が無視されているかを伝えるために頼る方法を見つけようとしてきましたが、正しい組み合わせを見つけるためのすべての努力は、困難またはあいまいな状況に陥り続けます。
tree -Iすべてのグロブオプションを尊重しているように見える.gitignoreので、完璧な解決策はないと思います。昨夜私が思いついた最良の近似はecho "node_modules|tmp|_build" > ~/.treeignore、tree -I "$(cat ~/.treeignore)"
git ls-files。