-
-
Save rdpate/975519 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. | |
# | |
# Existing non-links are always skipped. | |
# BSD's realpath does not have the -f flag | |
real_path () { | |
if [ -f $1 ]; then | |
echo $(real_path $(dirname $1))/$(basename $1) | |
else | |
(cd $1 && pwd) | |
fi | |
} | |
this=$(real_path $0) | |
SCRIPT_DIR=$(real_path $(dirname $0)) | |
PREFIX=$HOME | |
symlink='ln -s' | |
while getopts "vfp:" flag; do | |
case "$flag" in | |
v) symlink=${symlink}v ;; | |
f) symlink=${symlink}f ;; | |
p) PREFIX=${OPTARG%/} ;; | |
esac | |
done | |
errcode=0 | |
for source in $SCRIPT_DIR/*; do | |
[ $(real_path $source) = $this ] && continue | |
target=$PREFIX/.$(basename $source) | |
if [ -e $target -a ! -L $target ]; then | |
errcode=1 | |
echo "skipping non-symlink $target" | |
else | |
$symlink $source $target | |
fi | |
done | |
exit $errcode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment