Created
November 21, 2012 17:46
-
-
Save Diftraku/4126413 to your computer and use it in GitHub Desktop.
Simple tree -d reproduction using bash
This file contains hidden or 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
#!/bin/bash | |
if [ $# -lt 1 ] ; then | |
$1="~/"; | |
fi | |
# print the header | |
echo "."; | |
echo "|-- $1"; | |
parent="$1"; | |
padding=""; | |
recurse() { | |
for i in "$1"/*; do | |
if [ -d "$i" ]; then | |
cur_dir=$(echo "$i" | sed "s/$parent\///g"); | |
this=$(echo "$cur_dir" | sed "s/$2\///g"); | |
if [ "$2" == "" ]; then | |
padding=" "; | |
else | |
padding=" |"; | |
fi | |
echo "$padding |-- $this"; | |
#echo "$i" | |
recurse "$i" "$this"; | |
fi | |
done | |
} | |
recurse $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment