Skip to content

Instantly share code, notes, and snippets.

@Diftraku
Created November 21, 2012 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diftraku/4126413 to your computer and use it in GitHub Desktop.
Save Diftraku/4126413 to your computer and use it in GitHub Desktop.
Simple tree -d reproduction using bash
#!/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