ccurtin
9/26/2016 - 12:50 AM

creating shell script and passing flags/arguments.

creating shell script and passing flags/arguments.

touch /bin/new_python_project
chmod +x /bin/new_python_project
    echo '#!/bin/bash
    source /usr/local/bin/virtualenvwrapper.sh

    while getopts ":v:n:" opt; do
      case $opt in
        n)
          PROJECT_NAME=$OPTARG
          mkdir $PWD/$OPTARG
        ;;
        v)
          re='^[a-zA-Z]+$'
          if ! [[ $OPTARG =~ $re ]] ; then
            echo "new project in: $WORKON_HOME"
            echo "-a was triggered, will install python$OPTARG in $PWD/$PROJECT_NAME"
            # echo "sudo apt-get install python$OPTARG"
            echo "mkvirtualenv $WORKON_HOME/$PROJECT_NAME -p /usr/bin/python$OPTARG --always-copy"
            mkvirtualenv $PWD/$PROJECT_NAME -p /usr/bin/python$OPTARG --always-copy
          fi
          ;;
        :)
          echo "Option -$OPTARG requires an argument." >&2
          exit 1
          ;;
      esac
    done
"' >> /bin/new_python_project