Created
May 16, 2012 08:35
-
-
Save nedmas/2708724 to your computer and use it in GitHub Desktop.
A simple script to create directory hierarchies
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 | |
CONFIGDIR="$HOME/.skeleton" | |
WORKINGDIR=$(pwd) | |
if [ $# -lt 1 ] | |
then | |
echo "Usage : $0 [pattern]" | |
exit | |
fi | |
FILENAME="$CONFIGDIR/$1" | |
if [ -f $FILENAME ] | |
then | |
PREVDEPTH=0 | |
PREVDIR=$WORKINGDIR | |
while read LINE | |
do | |
if [ $LINE ] | |
then | |
DEPTH=0 | |
DIR=$LINE | |
while [[ $DIR =~ ^\- ]] | |
do | |
DIR="${DIR:1:${#DIR}}" | |
DEPTH=$(($DEPTH+1)) | |
done | |
if [ $DEPTH -lt $PREVDEPTH ] | |
then | |
cd .. | |
fi | |
if [ $DEPTH -gt $PREVDEPTH ] | |
then | |
cd $PREVDIR | |
fi | |
mkdir $DIR | |
PREVDEPTH=$DEPTH | |
PREVDIR=$DIR | |
fi | |
done < $FILENAME | |
else | |
echo "Error : No pattern matching $1" | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment