Unix/Linux Folder Tree
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
#!/bin/bash | |
##################################################### | |
# Unix/Linux Folder Tree v2.9 # | |
# # | |
# Displays structure of folder hierarchy # | |
# ------------------------------------------------- # | |
# This tiny script uses "ls", "grep", and "sed" # | |
# in a single command to show the nesting of # | |
# subfolders. # | |
# # | |
# Setup: # | |
# $ mkdir -p ~/apps/tree # | |
# Save "tree.sh" into the "~/apps/tree" folder # | |
# $ cd ~/apps/tree # | |
# $ chmod +x tree.sh # | |
# $ ln -s tree.sh /usr/local/bin/tree # | |
# $ which tree # | |
# # | |
# Usage: # | |
# $ tree [FOLDER] # | |
# # | |
# Examples: # | |
# $ tree # | |
# $ tree /usr/local/etc # | |
# $ tree .. # | |
# # | |
# WTFPL ~ https://centerkey.com/tree ~ Dem Pilafian # | |
##################################################### | |
echo | |
test -n "$1" && cd "$1" #if parameter exists, use as base folder | |
pwd | |
ls -R | grep "^[.]/" | sed -e "s/:$//" -e "s/[^\/]*\//--/g" -e "s/^/ |/" | |
# Transformations: | |
# grep --> select folders (filter out files) | |
# 1st sed --> remove trailing colon | |
# 2nd sed --> replace higher level folder names with dashes | |
# 3rd sed --> indent graph and add leading vertical bar | |
topFolders=$(ls -F -1 | grep "/" | wc -l) | |
test $topFolders -ne 0 || echo " --> no subfolders" | |
echo |
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
#!/bin/bash | |
###################################### | |
# Install: Unix/Linux Folder Tree # | |
# WTFPL ~ https://centerkey.com/tree # | |
###################################### | |
# To run this installer: | |
# $ curl -s https://centerkey.com/tree/install-tree.sh | bash | |
echo | |
echo "Install: Unix/Linux Folder Tree" | |
echo "===============================" | |
mkdir -p ~/apps/tree | |
cd ~/apps/tree | |
echo "Install folder:" | |
pwd | |
curl --remote-name https://centerkey.com/tree/tree.sh | |
grep "Tree v" tree.sh | |
chmod +x tree.sh | |
slink=/usr/local/bin/tree | |
test -f $slink && echo "slink already exists... not changing" | |
test -f $slink || ln -sv ~/apps/tree/tree.sh $slink | |
echo "Installed:" | |
readlink $slink | |
echo "In path:" | |
which tree | |
echo |
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
#!/bin/bash | |
########################## | |
# Unix/Linux Folder Tree # | |
########################## | |
# To make this file runnable: | |
# $ chmod +x *.sh.command | |
banner="Publish tree.sh" | |
projectHome=$(cd $(dirname $0); pwd) | |
apacheCfg=/usr/local/etc/httpd | |
apacheLog=/usr/local/var/log/httpd/error_log | |
webDocRoot=$(grep ^DocumentRoot $apacheCfg/httpd.conf | awk -F'"' '{ print $2 }') | |
displayIntro() { | |
cd $projectHome | |
echo | |
echo $banner | |
echo $(echo $banner | sed s/./=/g) | |
pwd | |
chmod +x tree.sh | |
ls -l tree.sh | |
echo | |
} | |
publishWebFiles() { | |
cd $projectHome | |
publishFolder=$webDocRoot/centerkey.com/tree | |
publish() { | |
echo "Publishing:" | |
echo $publishFolder | |
cp -v tree.sh $publishFolder | |
cp -v x-install-tree.sh $publishFolder/install-tree.sh | |
echo | |
} | |
test -w $publishFolder && publish | |
} | |
launchBrowser() { | |
cd $projectHome | |
url=https://centerkey.com/tree/ | |
test -w $publishFolder && url=http://localhost/centerkey.com/tree/ | |
echo "Opening:" | |
echo $url | |
sleep 2 | |
open $url | |
echo | |
} | |
displayIntro | |
publishWebFiles | |
launchBrowser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment