Created
April 11, 2021 17:29
-
-
Save cdegroot/148733a6d468a0a2c863fb38aedeaaed to your computer and use it in GitHub Desktop.
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/sh | |
linksdir=~/.config/direnv/links | |
cd $linksdir || (echo "No links dir found"; exit 1) | |
for rcfile in * | |
do | |
echo "Installing $rcfile" | |
destdir=$(echo $rcfile | sed 's,_+_,/,g') | |
if [ ! -d $destdir ] | |
then | |
echo " $destdir not available on this machine, skipping" | |
else | |
destfile=$destdir/.envrc | |
echo " to $destfile" | |
if [ -f $destfile -a ! -L $destfile ] | |
then | |
echo " $destfile exists, skipping" | |
else | |
rm -f $destfile # If it's an old link, or something | |
ln -s $linksdir/$rcfile $destfile | |
fi | |
fi | |
done |
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/sh | |
destdir=$(pwd -P) | |
destfile=$destdir/.envrc | |
linksdir=~/.config/direnv/links | |
rcfile=$linksdir/$(echo $destdir | sed 's,/,_+_,g') | |
if [ -f "$rcfile" ] | |
then | |
echo "File exists, maybe you meant direnv-install-links?" | |
exit 1 | |
fi | |
if [ -f "$destfile" ] | |
then | |
cat <<EOF | |
.envrc exists. Execute: | |
mv .envrc $rcfile | |
and then run direnv-install-links. Hit Enter to do that now, Ctrl-C otherwise. | |
EOF | |
read dummy | |
mv .envrc $rcfile | |
direnv-install-links | |
exit 0 | |
fi | |
echo '# -*- mode: sh; -*-' >$rcfile | |
echo '' >>$rcfile | |
echo Installing $rcfile in $destfile | |
ln -s $rcfile $destfile | |
echo "Edit .envrc now" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Direnv is pretty neat and I use it all the time. But in repos that are not exclusively mine, you cannot add .envrc files and I kept losing them.
direnv-new
, above, will create a file under~/.config/direnv
and symlink it, anddirenv-install-links
will install all these links in case you cleaned a repo or something. I combine it with dotfiles in git so I can version control my .envrc files and share them between machines.