Last active
December 22, 2018 05:45
-
-
Save anamba/4b30076c6f9869b041d592c4347d8e11 to your computer and use it in GitHub Desktop.
Bash script to symlink a shard into lib to make development easier
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 | |
# | |
# Usage: link_local_shard ../myshard | |
# | |
# Run from target project root. Deletes existing dir in lib (presumably | |
# added by shards) and replaces with a symlink to the path you provide. | |
# | |
if [ ! -d ./lib ]; then | |
echo "Must run from project root dir." | |
exit 1 | |
fi | |
shard_dir=${1%/} # remove trailing slash | |
shard_name=${shard_dir##*/} | |
if [[ $shard_dir != ./* ]] && [[ $shard_dir != ../* ]]; then | |
echo "Path to shard must start with ./ or ../" | |
exit 1 | |
fi | |
if [ ! -d $shard_dir ]; then | |
echo "Specified shard dir does not exist." | |
exit 1 | |
fi | |
if [[ $shard_name == '' ]]; then | |
echo "Shard name was blank." | |
exit 1 | |
fi | |
echo | |
echo 'About to run the following commands:' | |
echo | |
echo " rm -rf './lib/${shard_name}'" | |
echo " ln -s '../${shard_dir}' './lib/${shard_name}'" | |
echo | |
echo -n 'If everything looks good, hit ENTER to continue (or Ctrl-C to abort)... ' | |
read | |
rm -rf -- "./lib/${shard_name}" && | |
ln -v -s -- "../${shard_dir}" "./lib/${shard_name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment