dotfiles

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

lnkdot (554B) [raw]


      1 #!/bin/sh
      2 # lnkdot -- link a dotfile
      3 set -e
      4 
      5 die() {
      6 	echo "$1" 1>&2
      7 	exit 1
      8 }
      9 
     10 if [ "$#" = "0" ]; then
     11 	die "usage: linkdot DOTFILE [DOTFILE ...]"
     12 fi
     13 
     14 DIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
     15 RELDIR="$(echo $DIR | sed "s#^$HOME/##")"
     16 
     17 lnk() {
     18 	printf "$1 ... "
     19 	if [ -e "$HOME/$1" -a ! -L "$HOME/$1" ]; then
     20 		echo "failed"
     21 	else
     22 		root=$RELDIR
     23 		case $1 in
     24 			*/*) root=$DIR ;;
     25 		esac
     26 		ln -snf $root/$1 $HOME/$1
     27 		echo "linked"
     28 	fi
     29 }
     30 
     31 for f in "$@"; do
     32 	if [ -e "$DIR/$f" ]; then
     33 		lnk "$f"
     34 	else
     35 		die "dotfile doesn't exist: $f"
     36 	fi
     37 done