-
-
Save allanfreitas/82f416c5136cf0959e843cb940029e43 to your computer and use it in GitHub Desktop.
externalize.sh
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 -e | |
function externalize_git { | |
if [ ! -d "$git_repos_repo_full_path" ]; then | |
mkdir -p "$git_repos_repo_full_path" | |
mv .git "${git_repos_repo_full_path}"/.git | |
git --git-dir="${git_repos_repo_full_path}/.git" --work-tree=. init && echo "gitdir: ${git_repos_repo_full_path}/.git" > .git | |
else | |
echo "Directory $git_repos_repo_full_path already exists!" | |
fi | |
} | |
function move_and_link { | |
mkdir -p `dirname "${git_repos_repo_full_path}"/"$1"` | |
mv "$1" "${git_repos_repo_full_path}"/"$1" | |
ln -s "${git_repos_repo_full_path}"/"$1" "$1" | |
} | |
function externalize_node { | |
if [ ! -d "$git_repos_repo_full_path" ]; then | |
echo "Directory $git_repos_repo_full_path doesn't exist!" | |
else | |
move_and_link "node_modules" | |
fi | |
} | |
function externalize_ruby { | |
if [ ! -d "$git_repos_repo_full_path" ]; then | |
echo "Directory $git_repos_repo_full_path doesn't exist!" | |
else | |
move_and_link "tmp" | |
move_and_link "log" | |
move_and_link "public/assets" | |
fi | |
} | |
if [[ "$#" == "0" ]]; then | |
echo "Wrong number of arguments. Provide type of externalization: git|npm|ruby" | |
else | |
current_dir=${PWD##*/} | |
current_full_path=$PWD | |
developer_full_path=$HOME/Developer | |
developer_full_path_length=${#developer_full_path} | |
relative_path=${current_full_path:$developer_full_path_length+1} | |
git_repos_repo_full_path=$HOME/git-repos/"${relative_path}" | |
if [[ "$1" == "git" ]]; then | |
externalize_git | |
elif [[ "$1" == "ruby" ]]; then | |
externalize_ruby | |
elif [[ "$1" == "npm" ]]; then | |
externalize_node | |
else | |
echo "Wront externalization parameter. Valid options include: git|npm|ruby" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment