Skip to content

Instantly share code, notes, and snippets.

@nedmas
Created May 16, 2012 08:35
Show Gist options
  • Save nedmas/2708724 to your computer and use it in GitHub Desktop.
Save nedmas/2708724 to your computer and use it in GitHub Desktop.
A simple script to create directory hierarchies
#!/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