Last active
August 10, 2023 17:08
-
-
Save marshki/8722437ed6d576d5371ab4df53c7ac8d to your computer and use it in GitHub Desktop.
Partially mimic the `tree` command via Bash in macOS, Synology Disk Station Manager (DSM), et al.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Faux "tree" function in macOS, Synology Disk Station Manager (DSM), et. al. | |
# Comparable in output to Steve Baker's "tree" utility: | |
# http://mama.indstate.edu/users/ice/tree/ | |
# | |
# Add function to: /Users/foo/.profile, or: .bash_profile, | |
# then refresh the profile with: source .profile or: source .bash_profile | |
# | |
# Inspired by this thread: https://superuser.com/questions/359723/mac-os-x-equivalent-of-the-ubuntu-tree-command | |
########################################################################## | |
# Recursive directory/file listing of present working directory (PWD), | |
# with summary count of directories and files. | |
# Argument: | |
# Directory of interest, | |
# e.g.: tree /Users/foo/foo_dir | |
# Output: | |
# Recursive directory/file listing of named directory, | |
# | |
# Argument: | |
# Directory of interest, with user-defined level of resursive depth, | |
# e.g.: tree /System/Library 2 | |
# Output: | |
# Recursive directory/file listing of named directory, stopping at | |
# user defined depth of recursion, e.g. 2 | |
########################################################################## | |
tree () { | |
[ -n "$2" ] && local depth="-maxdepth $2"; | |
find "${1:-.}" "${depth}" -print 2> /dev/null | sed -e 's;[^/]*/;|____;g;s;____|; |;g' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment