Browse Source

lazy update

John ShaggyTwoDope Jenkins 4 years ago
parent
commit
a625d20e7d
1 changed files with 47 additions and 0 deletions
  1. 47
    0
      tree.sh

+ 47
- 0
tree.sh View File

@@ -0,0 +1,47 @@
1
+#!/bin/sh
2
+#######################################################
3
+#  UNIX TREE                                          #
4
+#  Version: 2.3                                       #
5
+#  File: ~/apps/tree/tree.sh                          #
6
+#                                                     #
7
+#  Displays Structure of Directory Hierarchy          #
8
+#  -------------------------------------------------  #
9
+#  This tiny script uses "ls", "grep", and "sed"      #
10
+#  in a single command to show the nesting of         #
11
+#  sub-directories.  The setup command for PATH       #
12
+#  works with the Bash shell (the Mac OS X default).  #
13
+#                                                     #
14
+#  Setup:                                             #
15
+#     $ cd ~/apps/tree                                #
16
+#     $ chmod u+x tree.sh                             #
17
+#     $ ln -s ~/apps/tree/tree.sh ~/bin/tree          #
18
+#     $ echo "PATH=~/bin:\${PATH}" >> ~/.profile      #
19
+#                                                     #
20
+#  Usage:                                             #
21
+#     $ tree [directory]                              #
22
+#                                                     #
23
+#  Examples:                                          #
24
+#     $ tree                                          #
25
+#     $ tree /etc/opt                                 #
26
+#     $ tree ..                                       #
27
+#                                                     #
28
+#  Public Domain Software -- Free to Use as You Like  #
29
+#  http://www.centerkey.com/tree  -  By Dem Pilafian  #
30
+#######################################################
31
+
32
+echo
33
+if [ "$1" != "" ]  #if parameter exists, use as base folder
34
+   then cd "$1"
35
+   fi
36
+pwd
37
+ls -R | grep ":$" |   \
38
+   sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
39
+# 1st sed: remove colons
40
+# 2nd sed: replace higher level folder names with dashes
41
+# 3rd sed: indent graph three spaces
42
+# 4th sed: replace first dash with a vertical bar
43
+if [ `ls -F -1 | grep "/" | wc -l` = 0 ]   # check if no folders
44
+   then echo "   -> no sub-directories"
45
+   fi
46
+echo
47
+exit

Loading…
Cancel
Save