Skip to content

Instantly share code, notes, and snippets.

@Ipstenu
Last active July 1, 2017 23:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ipstenu/f378eaf3779546d385ca7836bc87abc7 to your computer and use it in GitHub Desktop.
Save Ipstenu/f378eaf3779546d385ca7836bc87abc7 to your computer and use it in GitHub Desktop.
For use with Local by Flywheel (Pressmatic) Volumes Addon to create symlinks for better IDE integration
#! /bin/bash
# Usage:
#
# local-sync.sh sitename -- add symlinks
# local-sync.sh sitename delete -- delete all symlinks, synced folders, or other
#
# The value for sitename must match the folder you have for the site.
#
# Requires Local by Flywheel Volumes Add-on
# https://github.com/getflywheel/local-addon-volumes
#
# You MUST add each item in your plugins, mu_plugins, and themes in as a local addon path.
# Yes it sucks
if [[ $1 = 'lezwatchtv' ]];then
plugins=(
'repositories/lwtv-plugin'
'repositories/lwcom-plugin'
'wordpress/plugins-git/bury-your-queers'
)
mu_plugins=(
'repositories/lezwatch-mu-plugins'
)
themes=(
'repositories/lwtv-genesis'
'repositories/lwcom-2017'
)
elif [[ $1 = 'plugins' ]];then
plugins=(
'wordpress/plugins-git/light-fingered-fish'
'wordpress/plugins-git/impostercide'
)
mu_plugins=(
)
themes=(
)
elif [[ $1 = 'dreamhost' ]];then
plugins=(
'wordpress/plugins-git/dreamobjects'
'wordpress/plugins-git/dreamspeed-cdn'
'wordpress/plugins-git/varnish-http-purge'
)
mu_plugins=(
)
themes=(
)
else
echo "There is no site named $1 to sync."
exit 1
fi
devsites=(
$1
)
# Change these to your setup.
# By default, Local is installed in /Users/YOURNAME/Local Site
devsource="/Users/mika/Development"
local_path="/Users/mika/Sites/Local Sites"
# You probably won't need to change these, unless WP is in a subfolder
docker_plugin_path="app/public/wp-content/plugins"
docker_mu_plugin_path="app/public/wp-content/mu-plugins"
docker_theme_path="app/public/wp-content/themes"
# Do not edit below this line
if [[ -n $2 && "delete" == $2 ]]; then
delete=true
else
delete=false
fi
for site in ${devsites[@]}; do
# Copy Plugins
for plugin in ${plugins[@]}; do
# if file exists then delete
if [[ -e "$local_path"/${site}/${docker_plugin_path}/${plugin##*/} ]]; then
rm -r "$local_path"/${site}/${docker_plugin_path}/${plugin##*/}
fi
# if not file exists AND not delete, make symlink
if [[ ! -e "$local_path"/${site}/${docker_plugin_path}/${plugin##*/} && $delete = false ]]; then
echo ${plugin##*/} 'symlink created'
ln -s $devsource/${plugin} "$local_path"/${site}/${docker_plugin_path}
fi
done
# Copy Themes
for theme in ${themes[@]}; do
# if file exists then delete
if [[ -e "$local_path"/${site}/${docker_theme_path}/${theme##*/} ]]; then
rm -r "$local_path"/${site}/${docker_theme_path}/${theme##*/}
fi
# if not file exists AND not delete, make symlink
if [[ ! -e "$local_path"/${site}/${docker_theme_path}/${theme##*/} && $delete = false ]]; then
echo ${theme##*/} 'symlink created'
ln -s $devsource/${theme} "$local_path"/${site}/${docker_theme_path}
fi
done
# Copy MU Plugins
for mu_plugin in ${mu_plugins[@]}; do
# if file exists then delete
if [[ -e "$local_path"/${site}/${docker_mu_plugin_path} ]]; then
rm -r "$local_path"/${site}/${docker_mu_plugin_path}
fi
# if not file exists AND not delete, make symlink
if [[ ! -e "$local_path"/${site}/${docker_mu_plugin_path} && $delete = false ]]; then
echo 'MU-Plugins symlink created'
ln -s $devsource/${mu_plugin} "$local_path"/${site}/${docker_mu_plugin_path}
fi
done
done
@afragen
Copy link

afragen commented Mar 15, 2017

Shouldn't the my-plugins section use ${docker_mu_plugin_path} and not be hard coded?

Very clever. I like passing site name as parameter.

@malayladu
Copy link

@Ipstenu.

Thanks a lot for the script.

It helped me to complete my integration. (Flywheel, Netbeans & Git)

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