dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit d170a1e81ff1cfab5b04d9b40f694c4d5c9e8ffa (patch)
parent 81a086e640fd224957b319a88194a53dae46950a
Author: Alex Karle <alex@karle.co>
Date:   Tue,  4 Jun 2019 22:54:49 -0400

[bin] make link.sh more robust (see log)

There were 2 flaws to link.sh:

1. A real bug: not sure how I didn't hit this earlier, but -f returns
   true only if the file is a *real* file. As such, the link.sh script
   was trying to create a bunch of links over links (case 2) without
   removing them. Placing case 2 before case 1 and then turning that -f
   to a -e solves the issue.

2. $HOMEDOTS was hardcoded, which, while true if installed via
   bin/install.sh, is not always the case. This commit attempts to link
   to where it believes the script is located, thus being robust to
   cloning the dotfiles wherever the user may wish

Diffstat:
Mbin/link.sh | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/bin/link.sh b/bin/link.sh @@ -3,22 +3,22 @@ # Handles all (re)linking of dotfiles to their appropriate place # Establish Globals -HOMEDOTS=$HOME/.akarledots +HOMEDOTS="$( cd "$(dirname $(dirname "$0"))" ; pwd -P )" CONFDIR=$HOME/.config # Load messages colors + functions source $HOMEDOTS/bin/messages.sh try_ln() { - # if it doesn't exist, just create it -- works for broken symlinks too! - if [ ! -f $2 ]; then - success_msg "Creating soft symlink from $1 to $2" - ln -s $1 $2 # if its a symlink replace it - elif [ -L $2 ]; then + if [ -L $2 ]; then warn_msg "$2 is a symlink already, replacing it with a symlink to $1" rm $2 ln -s $1 $2 + # if it doesn't exist, just create it -- works for broken symlinks too! + elif [ ! -e $2 ]; then + success_msg "Creating soft symlink from $1 to $2" + ln -s $1 $2 # if it exists but is not a symlink else error_msg "$2 exists as a file that is NOT a symlink. What would you like to do?" @@ -57,8 +57,8 @@ try_ln $HOMEDOTS/perl/perldb $HOME/.perldb try_ln $HOMEDOTS/git/global_gitignore $HOME/.global_gitignore # .config lns -try_ln $HOMEDOTS/alacritty $CONFDIR -try_ln $HOMEDOTS/nvim $CONFDIR +try_ln $HOMEDOTS/alacritty $CONFDIR/alacritty +try_ln $HOMEDOTS/nvim $CONFDIR/nvim # bash lns for file in $HOMEDOTS/bash/*; do