Skip to content

Instantly share code, notes, and snippets.

@anton-matosov
Forked from dtaskoff/use-local-sh.sh
Created February 18, 2018 06:51
Show Gist options
  • Save anton-matosov/e0bb91f4c85f764f7492fcec53e5a658 to your computer and use it in GitHub Desktop.
Save anton-matosov/e0bb91f4c85f764f7492fcec53e5a658 to your computer and use it in GitHub Desktop.
A script used for modifying the ghc's scripts installed by stack, so that they use a local sh executable
stackargs=$@
shbin="$(which sh)"
if [ -z "$shbin" ] || [[ "$shbin" =~ "not found" ]]; then
echo "Couldn't find sh, exiting."
exit 1
else
echo "Found sh: $shbin"
fi
compilerbin=$(stack path $stackargs | grep compiler-bin | cut -d' ' -f2)
echo "Current project's compiler-bin: $compilerbin"
cd $compilerbin
echo "Modifying the scripts in $compilerbin.."
sedexpr="s@$shbin@$compilerbin/sh@"
for file in $(ls)
do
# Modify every $file that is neither a symlink nor a binary file
if [[ ! -L "$file" ]] && [[ ! "$(file -b --mime $file)" =~ "binary" ]]; then
sed -i bak "$sedexpr" $file
fi
done
echo "Copying $shbin to $compilerbin.."
cp $shbin $compilerbin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment