Created
November 1, 2012 13:53
-
-
Save gotgenes/3993745 to your computer and use it in GitHub Desktop.
A script to link executables into the local bin directory.
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 | |
# A simple script to symlink executables to the local bin directory | |
set -e | |
LOCAL_BIN_DIR="$HOME/.local/bin" | |
ln_flags="-sn" | |
while getopts "fd:" OPTION; do | |
case "$OPTION" in | |
f) | |
ln_flags="${ln_flags}f" | |
force=1 | |
;; | |
d) | |
DIR=$OPTARG | |
;; | |
*) | |
exit 1 | |
;; | |
esac | |
done | |
for file in `ls $DIR`; do | |
path="$DIR/$file" | |
if [[ -x $path ]] && [[ -f $path ]]; then | |
echo $path | |
newpath="$LOCAL_BIN_DIR/$file" | |
if [[ -e $newpath ]] && [[ $force != 1 ]]; then | |
echo "Skipping $file because it exists already (maybe try using -f)" | |
else | |
echo "Creating symlink $newpath in $LOCAL_BIN_DIR" | |
ln $ln_flags $path $newpath | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment