Skip to content

Instantly share code, notes, and snippets.

@vbmendes
Created June 4, 2011 15:28
Show Gist options
  • Save vbmendes/1007981 to your computer and use it in GitHub Desktop.
Save vbmendes/1007981 to your computer and use it in GitHub Desktop.
Create symbolic links to my folders in site-packages
#!/bin/bash
# ======================================================================
#
# Function: lnsp
# Creates a symbolic link to a folder inside current site-packages. If
# the file already exists, ask for override.
# Works ok with virtualenv.
#
# Parameters:
# $1 - The folder name inside $PWD
# $2 - The destination folder inside site-packages
#
# Examples:
# > # Example 1
# > # Folders with the same name
# > lnsp myfolder
# >
# > # Example 2
# > # Folders with diferent names
# > lnsp myfolder myotherfolder
#
# ======================================================================
# confirm function from
# http://wuhrr.wordpress.com/2010/01/13/adding-confirmation-to-bash/
function confirm()
{
echo -n "$@ "
read -e answer
for response in y Y yes YES Yes Sure sure SURE OK ok Ok
do
if [ "_$answer" == "_$response" ]
then
return 0
fi
done
# Any answer other than the list above is considerred a "no" answer
return 1
}
function lnsp()
{
local SITEPACKAGES=`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"`
local SOURCE=$PWD/$1
local DESTINATION=$SITEPACKAGES/$2
if [ ! $2 ]; then
DESTINATION=$SITEPACKAGES/$1
else
DESTINATION=$SITEPACKAGES/$2
fi
echo "Copying '$SOURCE' to '$DESTINATION'"
if [ -e $DESTINATION ] || [ -h $DESTINATION ]; then
confirm "File already exists. Override it? [y/N]" && rm -rf $DESTINATION || exit 0
fi
ln -s $SOURCE $DESTINATION
echo "$(tput setf 2)[OK!]$(tput sgr0)"
}
lnsp $1 $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment