Skip to content

techniques / tree-copy

tree-copy

Generates a visual ASCII directory tree with file icons, respecting .gitignore/.ignore rules, and copies output to clipboard.

utilfile

Paste this in your terminal. It saves the command as tree-copy.

Windows
cwm save -t util -t file -d "Generates visual ASCII directory tree to clipboard" tree-copy "& { `$root = (Get-Location).Path; `$rules = @('*.git*', '.git\*'); foreach (`$f in @('.gitignore', '.ignore')) { `$p = Join-Path `$root `$f; if (Test-Path `$p) { `$rules += Get-Content `$p | Where-Object { `$_ -match '\S' -and !`$_.StartsWith('#') } | ForEach-Object { `$clean = `$_ -replace '^/','' -replace '/+
,''; `"`$clean`", `"`$clean\*`", `"*`$clean`", `"*`$clean\*`" } } }; Split-Path `$root -Leaf; Get-ChildItem -Recurse | Where-Object { `$rel = `$_.FullName.Substring(`$root.Length + 1); `$skip = `$false; foreach (`$r in `$rules) { if (`$rel -like `$r) { `$skip = `$true; break } }; !`$skip } | Sort-Object FullName | ForEach-Object { `$rel = `$_.FullName.Substring(`$root.Length + 1); `$parts = `$rel -split '[/\\]'; `$indent = '| ' * (`$parts.Count - 1); `$icon = if (`$_.PSIsContainer) { '[DIR] ' } else { '[FILE] ' }; `$name = `$_.Name; Write-Output `"`$indent|-- `$icon`$name`" } } | Set-Clipboard; Write-Host 'Visual tree copied to clipboard!' -ForegroundColor Green"

Then run it

$ cwm get tree-copy -x