Skip to content

Instantly share code, notes, and snippets.

@gotgenes
Created November 1, 2012 13:53
Show Gist options
  • Save gotgenes/3993745 to your computer and use it in GitHub Desktop.
Save gotgenes/3993745 to your computer and use it in GitHub Desktop.
A script to link executables into the local bin directory.
#!/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