Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vfonic
Created November 24, 2015 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vfonic/0e6daa9a077281d7bbad to your computer and use it in GitHub Desktop.
Save vfonic/0e6daa9a077281d7bbad to your computer and use it in GitHub Desktop.
#!/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
@vfonic
Copy link
Author

vfonic commented Nov 24, 2015

I use this script to move and link directories with a lot of small files for which OneDrive chokes on.

This works for me, YMMV.

@Yerrak
Copy link

Yerrak commented Feb 16, 2016

Like it! (Sad, that one need to use scripts like this to make OneDrive sync properly ...)
As far as I can see, you need to run this 'manually' if you created new folders?
Did you find any approach to handle this automatically, eg. having a file watcher for your OneDrive folder or something similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment