Skip to content

Instantly share code, notes, and snippets.

@t-mw
Last active February 4, 2018 12:50
Show Gist options
  • Save t-mw/77afa699aaec87b3e709218513a7daad to your computer and use it in GitHub Desktop.
Save t-mw/77afa699aaec87b3e709218513a7daad to your computer and use it in GitHub Desktop.
#!/bin/bash
# see https://github.com/porglezomp-misc/live-reloading-rs/issues/1
set -e
name="libreloadable"
extension="dylib"
dir="./target/debug"
path="${dir}/${name}.${extension}"
cleanup() {
rm -f "${dir}/${name}_"*;
}
trap cleanup EXIT
timestamp() {
date +"%s";
}
run() {
name2="${name}_$(timestamp)";
for f in "$dir/$name".*; do cp -r "$f" "${f/$name/$name2}"; done
for f in "$dir/deps/$name".*; do cp -r "$f" "${f/$name/$name2}"; done
path2="${dir}/${name2}.${extension}";
deps_path="${dir}/deps/${name2}.${extension}";
install_name_tool -id "$deps_path" "$path2";
install_name_tool -id "$deps_path" "$deps_path";
}
export name
export extension
export dir
export path
export -f timestamp
export -f run
fswatch -o "$path" | xargs -n1 sh -c '$(run);'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment