Skip to content

Instantly share code, notes, and snippets.

@rnkn
Last active August 29, 2015 14:20
Show Gist options
  • Save rnkn/da91a859b6924a4511fe to your computer and use it in GitHub Desktop.
Save rnkn/da91a859b6924a4511fe to your computer and use it in GitHub Desktop.
A simple Bash script for project folder structuring
#! /bin/bash
#
# Scaffold creates a project directory structure like...
# ~
# |-- Desktop
# |-- Developer
# | `-- project
# |-- Documents
# | `-- project
# |-- Downloads
# |-- Movies
# | `-- project
# |-- Music
# | `-- project
# |-- Pictures
# | `-- project
# |-- Sites
# | `-- project
# `-- project_home
# `-- project
# |-- Desktop -> ~/Desktop
# |-- Developer -> ~/Developer/project
# |-- Documents -> ~/Documents/project
# |-- Downloads -> ~/Downloads
# |-- Movies -> ~/Movies/project
# |-- Pictures -> ~/Pictures/project
# `-- Sites -> ~/Sites/project
#
# source this from your ~/.bash_profile with...
# $ echo "source ~/PATH/TO/scaffold.sh" >> ~/.bash_profile
function scaffold {
local project_home="$HOME/Projects"
local project=${PWD##*/}
local folders=("Developer"
"Documents"
"Movies"
"Music"
"Pictures"
"Sites")
local links=("Desktop"
"Downloads")
for folder in ${folders[*]}
do
if [[ "$PWD" == $HOME/$folder* ]]
then
echo "Usage: cannot create scaffolding within linked folders"
return 1
fi
done
for folder in ${links[*]}
do
if [[ "$PWD" == $HOME/$folder* ]]
then
echo "Usage: cannot create scaffolding within linked folders"
return 1
fi
done
for folder in ${folders[*]}
do
local src="$HOME/$folder/$project"
local dest="$project_home/$project/$folder"
read -n 1 -p "Create and link $src -> $dest? [Y/n] " response
if [[ $response == n || N ]]
then
echo -e "\nSkipping"
else
mkdir -pv "$dest"
ln -shv "$src" "$dest"
fi
done
for folder in ${links[*]}
do
local src="$HOME/$folder"
local dest="$project_home/$project/$folder"
read -n 1 -p "Link $src -> $dest? [Y/n] " response
if [[ $response == n || N ]]
then
echo -e "\nSkipping"
else
ln -shv "$src" "$dest"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment