Skip to content

Latest commit

 

History

History
294 lines (224 loc) · 7.33 KB

File metadata and controls

294 lines (224 loc) · 7.33 KB

Shell Dot Profile

This generates my .profile that contains environment variables and similar settings applicable to all my shells. Yeah, I’m some-what of a shell-slut, and dabble between Zshell and Fish.

Homebrew

Make sure that Homebrew is both installed and configured correctly.

if which osascript >/dev/null 2>&1
then
  export ON_A_MAC=1
fi

if [ ! -d /usr/local/Cellar -a -n "$ON_A_MAC" ]
then
  echo "ZOMG! No Homebrew installed! Installing now..."
  ruby -e "`curl -fsSL https://raw.github.com/mxcl/homebrew/go/install`"
fi

Path

We want to add these directories, but only if they exist. This makes this more portable between my computers.

OLDPATH=$PATH
PATH=$HOME/bin

for DIR in /usr/local/git/bin /opt/local/bin /opt/local/sbin /usr/local/bin /usr/local/sbin
do
  if [ -d $DIR ]
  then
      PATH=$PATH:$DIR
  fi
done

PATH=$PATH:$OLDPATH

Emacs

Set EDITOR to start up an emacsclient, but do that from the one I built from Homebrew:

export ALTERNATE_EDITOR=/usr/local/bin/emacs
export EDITOR=/usr/local/bin/emacsclient

Global Aliases

I dislike more, especially since less is now really sweet.

alias more=less

System-Specific Variables

Host-specific values, are stored in a separate profile.

if [ -x $HOME/.profile-local ]
then
  . $HOME/.profile-local
fi

Python

Use Homebrew to install the pyenv project:

brew install pyenv

Initialize the project with the following code:

export PYENV_ROOT="${HOME}/.pyenv"

if [ -d "${PYENV_ROOT}" ]; then
    export PATH="${PYENV_ROOT}/bin:${PATH}"
    eval "$(pyenv init -)"
fi

Install a particular version of Python:

pyenv install 2.7.5
pyenv global 2.7.5

Use a particular Python version with:

pyenv virtualenv $NAME    # Creates the virtual env
pyenv activate $NAME      # Choose the virtual env
pyenv deactivate          # Stops using it

While in the root directory of a project, automatically use the appropriate Python version with the local command (do this just once):

pyenv local <virtualenv or version>

When entering this directory, the chosen virtualenv or Python version will be activated automatically. The file that is creatied and specifies the appropriate environment is named .python-version (add this to git).

Enhance pyenv with the pyenv-virtualenv plugin. If installed, this code initializes it:

if which pyenv-virtualenv-init > /dev/null
then
    eval "$(pyenv virtualenv-init -)"
fi

Create a virtual environment with:

pyenv virtualenv 2.7.10 lp-demo

List the created virtual environments:

pyenv virtualenvs

It seems that the local command may make this a moot point, activate a virtual environment manually with:

pyenv activate <name>
pyenv deactivate

In other words, this pyenv project subsumes both autoenv and virtualenvwrapper. See Virtual Environments in the Python Emacs setup for details.

Ruby

Install RVM via:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable

And then just source the following:

source $HOME/.rvm/scripts/rvm

Create new virtual environments with:

rvm install 2.0.0
rvm use ruby-2.0.0-p643
rvm gemset create chef
rvm gemset use chef

And use those environements with:

rvm use ruby-2.0.0-p643@chef

And now gem commands work as expected:

gem install bundler

Prompt

Better approach to displaying the current path, is to only display the first or second directory name … any maybe the name of the Git project. Holy hell, so many exceptions and so few patterns…

function trim_dir {
    V='[[:alnum:]._-]'
    D='[[:alnum:]._/-]'
    sed -E "s|/$D+/($V+)|../\1|; s/ / /g" <<< $1
}

function prompt_dir {
    PWD=$(pwd)

    if [[ $PWD == $HOME ]]
    then
        echo -n '~'
    elif [[ $PWD == $HOME/Work ]]
    then
        echo -n '~/Work'

         # In a Git project?
    elif PRJ=$(git rev-parse --show-toplevel 2>/dev/null)
    then
        name=$(basename $PRJ)
        rest=$(sed "s|$PRJ||" <<< $PWD)
        echo -n "$(sed -e 's/ / /g' <<< [$name])$(trim_dir $rest)"

         # In work-related directory...
    elif [[ $PWD == $HOME/Work/* ]]
    then
        name=$(sed -E "s|$HOME/Work/([[:alnum:]_-]+).*|\1|; s/ / /g" <<< $PWD)
        base=$(basename $PWD)
        intr=$(basename `dirname $PWD`)

        if [[ $name == $base ]]
        then
            echo -n "Ⓦ/$name"
        elif [[ $intr == $name ]]
        then
            echo -n "Ⓦ/$name/$base"
        else
            echo -n "Ⓦ/$name/../$base"
        fi

         # In a home directory
    elif [[ $PWD == $HOME/* ]]
    then
        if [[ $(basename `dirname $PWD`) == $(basename $HOME) ]]
        then
            echo -n "~/$(basename $PWD)"
        else
            echo -n "~/$(trim_dir $PWD)"
        fi
    else
        trim_dir $PWD
    fi
}

I wanna add everything to my command line prompt: the Git repository, the Python virtual environment (in white), the Ruby Virtual Environment (in red) … of course, now I have no room to type commands. ;-)

if [ -d ~/.rvm ]
then
    export PS1='\[\e[1;31m\]$(~/.rvm/bin/rvm-prompt v g)\[\e[1;34m\] $(prompt_dir)$(__git_ps1 " \[\e[1;32m\]:%s")\[\e[0m\] \$ '
else
    export PS1='\[\e[1;34m\]$(prompt_dir)$(__git_ps1 " \[\e[1;32m\]:%s")\[\e[0m\] \$ '
fi

Good thing I seldom use a shell.

My Function Collection

Load up my shared functions. These can be shared with Bash, Fish and Zshell.

if [ -f $HOME/.sh-funcs.sh ]
then
    . $HOME/.sh-funcs.sh
fi

Technical Gunk

Anything else that is interesting, will be set up in more either more shell-specific files, or in Shell Functions file. The following are the tangled settings. Type: C-c C-v t to create the script file.