-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlstree.sh
executable file
·81 lines (78 loc) · 1.7 KB
/
lstree.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
#######################################################
# UNIX TREE # # Version: 2.3 # # File: ~/apps/tree/tree.sh
#
#
#
# Displays Structure of Directory Hierarchy
#
# -------------------------------------------------
#
# This tiny script uses "ls", "grep", and "sed"
#
# in a single command to show the nesting of # # sub-directories. The setup command for PATH # # works with the Bash shell (the Mac OS X default).
#
#
# SR Setup (for Ubuntu):
#
# echo echo "PATH=/home/sean/sourcecode/sean/bitbucket/unix-programming-tools:${PATH}" >> ~/.bashrc
#
# cd /home/sean/sourcecode/sean/bitbucket/unix-programming-tools
# ln -s lstree.sh lstree
#
#
# ORIGINAL Setup:
#
# $ cd ~/apps/tree
#
# $ chmod u+x tree.sh
#
# $ ln -s ~/apps/tree/tree.sh ~/bin/tree
#
# $ echo "PATH=~/bin:\${PATH}" >> ~/.profile
#
#
# Usage:
#
# $ tree [directory]
#
#
#
# Examples:
#
# $ tree
#
# $ tree /etc/opt
#
# $ tree ..
#
#
#
# Public Domain Software -- Free to Use as You Like
#
# http://www.centerkey.com/tree - By Dem Pilafian
#
#######################################################
echo
#if parameter exists, use as base folder
if [ "$1" != "" ]; then
cd "$1"
fi
#if [ -n "$BASH_VERSION" ]; then
# # include .bashrc if it exists
# if [ -f "$HOME/.bashrc" ]; then
# . "$HOME/.bashrc"
# fi
#fi
pwd
ls -R | grep ":$" | \
sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep "/" | wc -l` = 0 ] # check if no folders
then echo " -> no sub-directories"
fi
echo
exit