diff options
author | Peter Palfrader <peter@palfrader.org> | 2009-06-27 10:56:07 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2009-06-27 10:56:07 +0000 |
commit | 586ac36478fdd8f0d23c654cd9011318a22a8722 (patch) | |
tree | d1700bb2c9f883082f6796282f01112815ed9420 /Link-Them | |
parent | cab4384bdb27f01a340323312cbcd8129d8d0569 (diff) |
Make relative symlinks
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@399 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'Link-Them')
-rwxr-xr-x | Link-Them | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -1,15 +1,29 @@ -#!/bin/sh +#!/bin/bash set -e cd "`dirname $0`" -DATE="`date +'%Y%m%d'`" -DIR="`pwd`" +date="`date +'%Y%m%d'`" +dir="`pwd`" +if [ "$dir" = "$HOME" ]; then + relpath="" +else + relpath="${dir##$HOME/}/" +fi for file in bash_profile bashrc screenrc vimrc zshrc zshfunc; do + if [ -L "$HOME/.$file" ]; then + if [ "$(readlink "$HOME/.$file")" = "$dir/$file" ]; then # old style symlink, remove + rm -v -f "$HOME/.$file" + fi + fi if ! [ -L "$HOME/.$file" ]; then - [ -e "$HOME/.$file" ] && mv "$HOME/.$file" "$HOME/.$file-$DATE" - ln -s "$DIR/$file" "$HOME/.$file" + if [ -e "$HOME/.$file" ]; then + mv "$HOME/.$file" "$HOME/.$file-$date" + elif [ -L "$HOME/.$file" ]; then # dangling symlink + rm -f "$HOME/.$file" + fi + ln -v -s "$relpath$file" "$HOME/.$file" fi done |