Created
May 16, 2011 20:28
-
-
Save jlogsdon/975295 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/bash | |
# | |
# Links files in this directory to the current users home directory. | |
# | |
# If the link already exists the file will be skipped unless the -f flag is given. | |
real_path () { | |
_=`pwd` | |
[ -d $DIR ] && DIR=$1 | |
[ -f $DIR ] && DIR=`dirname $1` | |
cd $DIR && echo `pwd` && cd $_ | |
} | |
SCRIPT_DIR=$(real_path $0) | |
SCRIPT_PATH=${SCRIPT_DIR}/`basename $0` | |
FORCE=0 | |
PREFIX=$HOME | |
while getopts "fp:" flag; do | |
case "$flag" in | |
f) FORCE=1 ;; | |
p) PREFIX=$OPTARG ;; | |
esac | |
done | |
PREFIX=${PREFIX%/} | |
for FILE_PATH in ${SCRIPT_DIR}/*; do | |
FILE=$(basename $FILE_PATH) | |
HOME_PATH=$PREFIX/.${FILE} | |
if [[ $FILE_PATH = $SCRIPT_PATH ]]; then | |
continue | |
fi | |
if [[ $FILE_PATH = $SCRIPT_PATH || ${FILE:0:1} = '.' ]]; then | |
continue | |
fi | |
if [[ $FORCE -eq 0 && -e $HOME_PATH ]]; then | |
echo Skipping $FILE_PATH | |
continue | |
fi | |
if [[ $FORCE -eq 1 && -e $HOME_PATH ]]; then | |
echo Forcably linking $FILE_PATH to $HOME_PATH | |
rm -f $HOME_PATH | |
else | |
echo Linking $FILE_PATH to $HOME_PATH | |
fi | |
ln -s $FILE_PATH $HOME_PATH | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mrc that's good to know! Fortunately,
for FILE_PATH in ${SCRIPT_DIR}/*
works just as well as @rdpate pointed out.