caio.co/de/bash.d

Initial commit

Id
346c1df04ea820db12148206c00ca054a81298cb
Author
Caio
Commit time
2012-10-10T23:00:30+02:00

Created .gitignore

@@ -1,0 +1,3
+custom/
+*~
+*.pyc

Created bashd.bash

@@ -1,0 +1,60
+# Do absolutely nothing if stdin is not a terminal
+test ! -t 0 && return 0
+
+# Disable ^S/^Q for flow control
+stty -ixon -ixoff
+# Allow binding ^W on inputrc
+stty werase undef
+
+# Resolve bash.d base dir if unset
+if test -z $BASHD_DIR; then
+ export BASHD_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+fi
+
+. ${BASHD_DIR}/core/init.bash
+. ${BASHD_DIR}/core/color.bash
+. ${BASHD_DIR}/core/theme.bash
+
+bashd_source ${BASHD_DIR}/lib/*
+bashd_source ${BASHD_DIR}/custom/*
+
+export EDITOR=vim
+export BROWSER=chromium
+export PYTHONSTARTUP="${HOME}/.pythonrc.py"
+
+pathprepend ~/bin
+pathprepend ~/.bin
+pathprepend ~/.local/bin
+
+shopt -s checkjobs
+shopt -s checkwinsize
+shopt -s extglob
+shopt -s no_empty_cmd_completion
+
+alias mv='mv -i'
+alias cp='cp -i'
+alias rm='rm -I'
+alias j='jobs'
+alias grep='egrep'
+alias ls='ls --color -h --group-directories-first'
+alias l='ls -lh'
+alias la='ls -lhA'
+alias a='ls -d .*'
+alias -- -='cd -'
+alias beep="echo -ne '\a'"
+alias p='ps -eo pid,ruser,cmd| grep -i'
+
+# Save multiline commands as single-line
+shopt -s cmdhist
+# Append to history instead of overwriting
+shopt -s histappend
+
+export HISTSIZE=40000
+export HISTFILESIZE=40000
+export HISTIGNORE="ls:l:clear:d:cd:bg:fg:history"
+export HISTCONTROL="erasedups:ignorespace"
+export HISTTIMEFORMAT='[%Y-%m-%d %H:%M] '
+# }}}
+
+# avoid carrying over test statuses
+true

Created bashrc.example

@@ -1,0 +1,7
+BASHD_THEME=default
+
+. /path/to/bash.d/bashd.bash
+
+make_dir_complete jk ~/src
+make_dir_complete h ~/etc
+make_dir_complete dl /download/errado/

Created core/color.bash

@@ -1,0 +1,37
+FG_BLACK='\[\e[0;30m\]'
+FG_BLUE='\[\e[0;34m\]'
+FG_CYAN='\[\e[0;36m\]'
+FG_GREEN='\[\e[0;32m\]'
+FG_PURPLE='\[\e[0;35m\]'
+FG_RED='\[\e[0;31m\]'
+FG_WHITE='\[\e[0;37m\]'
+FG_YELLOW='\[\e[0;33m\]'
+
+FG_BOLD_BLACK='\[\e[1;30m\]'
+FG_BOLD_BLUE='\[\e[1;34m\]'
+FG_BOLD_CYAN='\[\e[1;36m\]'
+FG_BOLD_GREEN='\[\e[1;32m\]'
+FG_BOLD_PURPLE='\[\e[1;35m\]'
+FG_BOLD_RED='\[\e[1;31m\]'
+FG_BOLD_WHITE='\[\e[1;37m\]'
+FG_BOLD_YELLOW='\[\e[1;33m\]'
+
+FG_UND_BLACK='\[\e[4;30m\]'
+FG_UND_BLUE='\[\e[4;34m\]'
+FG_UND_CYAN='\[\e[4;36m\]'
+FG_UND_GREEN='\[\e[4;32m\]'
+FG_UND_PURPLE='\[\e[4;35m\]'
+FG_UND_RED='\[\e[4;31m\]'
+FG_UND_WHITE='\[\e[4;37m\]'
+FG_UND_YELLOW='\[\e[4;33m\]'
+
+BG_BLACK='\[\e[40m\]'
+BG_BLUE='\[\e[44m\]'
+BG_CYAN='\[\e[46m\]'
+BG_GREEN='\[\e[42m\]'
+BG_PURPLE='\[\e[45m\]'
+BG_RED='\[\e[41m\]'
+BG_WHITE='\[\e[47m\]'
+BG_YELLOW='\[\e[43m\]'
+
+RESET_COLORS='\[\e[0m\]'

Created core/init.bash

@@ -1,0 +1,47
+# Basic functions and settings
+
+_bashd_error() {
+ echo "[ERROR] $*" >&2
+}
+
+pathremove() {
+ local IFS=':'
+ local NEWPATH
+ local DIR
+ local PATHVARIABLE=${2:-PATH}
+ for DIR in ${!PATHVARIABLE} ; do
+ if [ "$DIR" != "$1" ] ; then
+ NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
+ fi
+ done
+ export $PATHVARIABLE="$NEWPATH"
+}
+
+_unckecked_pathappend() {
+ pathremove "$1" "$2"
+ local PATHVARIABLE=${2:-PATH}
+ export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
+}
+
+pathprepend() {
+ test ! -d "${1}" && return 0
+ pathremove "$1" "$2"
+ local PATHVARIABLE=${2:-PATH}
+ export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
+}
+
+pathappend() {
+ test ! -d "${1}" && return 0
+ _unckecked_pathappend "$1" "$2"
+}
+
+pwdappend() {
+ pathappend "$(pwd)"
+}
+
+bashd_source() {
+ for file in ${@}; do
+ test ! -f ${file} -o ! -x ${file} && continue
+ . ${file} || _bashd_error "Unable to load ${file}"
+ done
+}

Created core/theme.bash

@@ -1,0 +1,33
+test -z $BASHD_THEME && BASHD_THEME=default
+BASHD_THEME_DIR=${BASHD_DIR}/theme/${BASHD_THEME}
+
+declare -a BASHD_PROMPT_FUNCTIONS=();
+
+bashd_prompt_register() {
+ BASHD_PROMPT_FUNCTIONS=( "${BASHD_PROMPT_FUNCTIONS[@]}" "$1" )
+}
+
+bashd_prompt_append() {
+ PS1="${PS1}${1}"
+}
+
+bashd_prompt_prepend() {
+ PS1="${1}${PS1}"
+}
+
+bashd_prompt_set_ps1() {
+ PS1=""
+ for prompt_function in "${BASHD_PROMPT_FUNCTIONS[@]}"; do
+ $prompt_function
+ done
+}
+
+bash_prompt_cmd() {
+ LAST_STATUS=$?
+ bashd_prompt_set_ps1
+ export PS1
+}
+export PROMPT_COMMAND=bash_prompt_cmd
+
+bashd_source ${BASHD_THEME_DIR}/prompt.d/*
+test -f ${BASHD_THEME_DIR}/dircolors && eval $(dircolors ${BASHD_THEME_DIR}/dircolors)

Created custom/.gitkeep

Created lib/bashcompletion.sh

@@ -1,0 +1,3
+#!/bin/bash
+
+bashd_source /etc/bash_completion

Created lib/dircolors.sh

@@ -1,0 +1,3
+#!/bin/bash
+
+test -f ~/.dircolors && eval $(dircolors ~/.dircolors) || true

Created lib/haskell.sh

@@ -1,0 +1,8
+__load_cabal() {
+ local cabal_dir="${HOME}/.cabal"
+ test ! -d ${cabal_dir} && return 0
+ pathprepend ${cabal_dir}/bin/
+ export MANPATH=${cabal_dir}/share/man/:$(manpath -g)
+}
+
+__load_cabal

Created lib/make_dir_complete.sh

@@ -1,0 +1,19
+#!/bin/bash
+
+make_dir_complete() {
+ local aliasname=$1
+ local dirname=$(readlink -f $2)
+ local prgname="__s_${aliasname}__"
+ FUNC="function $prgname() {
+ local cur len wrkdir;
+ local IFS=\$'\\n'
+ wrkdir=\"$dirname\"
+ cur=\${COMP_WORDS[COMP_CWORD]};
+ len=\$((\${#wrkdir} + 2));
+ COMPREPLY=( \$(compgen -S/ -d \$wrkdir/\$cur| cut -b \$len-) );
+ }"
+ ALIAS="$aliasname () { cd \"$dirname/\$*\"; }"
+ eval $FUNC
+ eval $ALIAS
+ complete -o nospace -F $prgname $aliasname
+}

Created lib/onepiece.sh

@@ -1,0 +1,47
+#!/bin/bash
+
+__wm_check() {
+ if [ ! -d WATCHED ]; then
+ echo "You must create a ./WATCHED dir to use this command" >&2
+ return 2
+ fi
+ return 0
+}
+
+wm() {
+ video="${@}"
+ mplayer "${video}"
+ result=$?
+ if test $result -eq 0; then
+ mv "${video}" WATCHED/
+ subfile="${video%.*}.srt"
+ test -f "${subfile}" && mv "${subfile}" WATCHED
+ return 0;
+ fi
+}
+
+wnext() {
+ __wm_check || return $?
+ local target=""
+ while read LINE; do
+ test -d "${LINE}" && continue
+ test ! -f "${LINE}" && continue
+ target=${LINE}
+ break
+ done < <(/bin/ls -1 !(*.srt|WATCHED))
+ test -z "${target}" && return 1
+ wm "${target}"
+}
+
+wprev() {
+ __wm_check || return $?
+ local target=""
+ while read LINE; do
+ test -d "${LINE}" && continue
+ test ! -f "${LINE}" && continue
+ target=${LINE}
+ break
+ done < <(ls -1 WATCHED| egrep -v '.+\.srt'| tac| sed 's/^/WATCHED\//g')
+ test -z "${target}" && return 1
+ mplayer "${target}"
+}

Created lib/perlbrew.sh

@@ -1,0 +1,11
+#!/bin/bash
+
+__load_perlbrew() {
+ local perlbrew_root="${HOME}/.perl5/perlbrew"
+ test ! -d ${perlbrew_root} && return 0
+ export PERLBREW_ROOT=${perlbrew_root}
+ . ${PERLBREW_ROOT}/etc/bashrc
+ . ${PERLBREW_ROOT}/etc/perlbrew-completion.bash
+}
+
+__load_perlbrew

Created lib/power.sh

@@ -1,0 +1,30
+#!/bin/bash
+
+_dbus_send() {
+ local cmd=${1}
+ local tmp=${1%.*}
+ local dest=${tmp/.Manager/}
+ local mgr="/${tmp//.//}"
+ dbus-send --system --print-reply --dest=${dest} ${mgr} ${cmd}
+}
+
+power() {
+ case "$1" in
+ shutdown)
+ _dbus_send org.freedesktop.ConsoleKit.Manager.Stop
+ ;;
+ restart)
+ _dbus_send org.freedesktop.ConsoleKit.Manager.Restart
+ ;;
+ sleep)
+ _dbus_send org.freedesktop.UPower.Suspend
+ ;;
+ hibernate)
+ _dbus_send org.freedesktop.UPower.Hibernate
+ ;;
+ *)
+ return 1
+ esac
+}
+
+complete -W "shutdown${IFS}restart${IFS}sleep${IFS}hibernate" power

Created lib/pythonbrew.sh

@@ -1,0 +1,9
+#!/bin/bash
+
+__load_pybrew() {
+ local pybrewinit="${HOME}/.pythonbrew/etc/bashrc"
+ test ! -r ${pybrewinit} && return 0
+ . ${pybrewinit}
+}
+
+__load_pybrew

Created lib/rvm.sh

@@ -1,0 +1,10
+#!/bin/bash
+
+__load_rvm() {
+ local rvm_load_path="${HOME}/.rvm"
+ test ! -d ${rvm_load_path} && return 0
+ . ${rvm_load_path}/scripts/rvm
+ . ${rvm_load_path}/scripts/completion
+}
+
+__load_rvm

Created lib/telnets.sh

@@ -1,0 +1,5
+telnets() {
+ local host=$1
+ local port=${2-443}
+ openssl s_client -quiet -connect $host:$port
+}

Created lib/tmux.sh

@@ -1,0 +1,4
+#!/bin/bash
+
+# Force tmux to use 256 colors
+test -n "$TMUX" && export TERM=screen-256color || true

Created lib/unpack.sh

@@ -1,0 +1,70
+#!/bin/bash
+
+unpack() {
+ # Usage: unpack [-r] <package> [extra_options]
+ # extra_options are filetype/extration-command -dependant
+ local remove_archive=0
+
+ if [ "$1" = "-r" ]; then
+ remove_archive=1
+ shift
+ fi
+
+ filename="$1"
+ shift
+
+ if [ ! -f "$filename" ]; then
+ echo "File not found: $filename" 1>&2
+ return 1
+ fi
+
+ options=${@}
+
+ case "$filename" in
+ *.tar.bz2)
+ tar xvjf "$filename" $options;;
+ *.tar.gz)
+ tar xvzf "$filename" $options;;
+ *.tar.xz)
+ tar xvJf "$filename" $options;;
+ *.tar.lzma)
+ tar --lzma -xvf "$filename" $options;;
+ *.bz2)
+ bunzip $options "$filename";;
+ *.rar)
+ unrar x $options "$filename";;
+ *.gz)
+ gunzip $options "$filename";;
+ *.tar)
+ tar xvf "$filename" $options;;
+ *.tbz2)
+ tar xvjf "$filename" $options;;
+ *.tgz)
+ tar xvzf "$filename" $options;;
+ *.zip)
+ unzip "$filename" $options;;
+ *.Z)
+ uncompress $options "$filename";;
+ *.7z)
+ 7z x $options "$filename";;
+ *.rpm)
+ rpm2cpio "$filename" | cpio -ivd $options;;
+ *.deb)
+ ar vx "$filename";;
+ *)
+ echo "Unknown filetype: $filename" 1>&2
+ return 1;;
+ esac
+
+ local retcode=$?
+
+ if [ $retcode -ne 0 ]; then
+ echo "Error extracting: $filename" 1>&2
+ return $retcode
+ fi
+
+ if [ $remove_archive -eq 1 ]; then
+ echo "Removing: $filename"
+ rm "$filename"
+ fi
+}

Created lib/uumount.sh

@@ -1,0 +1,23
+#!/bin/bash
+
+__umountables() {
+ local cur
+ local IFS=$'\n'
+ wrkdir='/media/'
+ cur=${COMP_WORDS[COMP_CWORD]};
+ len=$((${#wrkdir} + 1));
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $(compgen -d /media/${cur}| cut -b $len-) )
+ else
+ COMPREPLY=()
+ fi
+}
+
+uumount() {
+ [ ${#} -ne 1 ] && return 1;
+ udiskie-umount /media/${1}
+}
+
+complete -F __umountables uumount
+

Created lib/vcsinfo.sh

@@ -1,0 +1,83
+#!/bin/bash
+
+__vcs_dir() {
+ local vcs base_dir sub_dir ref RED YELLOW GREEN BLUE
+ local LIGHT_RED LIGHT_GREEN WHITE LIGHT_GRAY COLOR_NONE
+
+ RED="\[\033[0;31m\]"
+ YELLOW="\[\033[0;35m\]"
+ GREEN='\[\e[0;36m\]'
+ BLUE="\[\033[0;34m\]"
+ LIGHT_RED="\[\033[1;31m\]"
+ LIGHT_GREEN="\[\033[1;32m\]"
+ WHITE="\[\033[1;37m\]"
+ LIGHT_GRAY="\[\033[0;37m\]"
+ COLOR_NONE="\[\e[0m\]"
+
+ sub_dir() {
+ local sub_dir
+ sub_dir=$(readlink -f "${PWD}")
+ sub_dir=${sub_dir#$1}
+ echo ${sub_dir#/}
+ }
+
+ git_dir() {
+
+ parse_git_branch() {
+ # Capture the output of the "git status" command.
+ git_status="$(git status --ignore-submodules 2> /dev/null)"
+
+ # Set color based on clean/staged/dirty.
+ if [[ ${git_status} =~ "working directory clean" ]]; then
+ state="${GREEN}"
+ elif [[ ${git_status} =~ "Changes to be committed" ]]; then
+ state="${YELLOW}"
+ else
+ state="${RED}"
+ fi
+
+ # Set arrow icon based on status against remote.
+ remote_pattern="# Your branch is (ahead of|behind)"
+ if [[ ${git_status} =~ ${remote_pattern} ]]; then
+ if [[ ${BASH_REMATCH[1]} == "ahead of" ]]; then
+ remote="↑"
+ else
+ remote="↓"
+ fi
+ fi
+ diverge_pattern="# Your branch and (.*) have diverged"
+ if [[ ${git_status} =~ ${diverge_pattern} ]]; then
+ remote="↕"
+ fi
+
+ # Get the name of the branch.
+ branch_pattern="^# On branch ([^${IFS}]*)"
+ if [[ ${git_status} =~ ${branch_pattern} ]]; then
+ branch=${BASH_REMATCH[1]}
+ fi
+
+ # Display the prompt.
+ echo "${state}${branch}${remote}${COLOR_NONE}"
+ }
+ base_dir=$(git rev-parse --git-dir 2>/dev/null) || return 1
+ base_dir=$(readlink -f "$base_dir/..")
+ sub_dir=$(git rev-parse --show-prefix)
+ sub_dir=${sub_dir%/}
+ ref=$(parse_git_branch)
+ vcs="Β±"
+ }
+
+ git_dir ||
+ base_dir="$PWD"
+
+ __vcs_base_dir="${base_dir/$HOME/~}"
+ if [ -n "$vcs" ]; then
+ __vcs_prefix="$vcs"
+ __vcs_ref="$ref"
+ __vcs_sub_dir="${sub_dir}"
+ else
+ __vcs_prefix=""
+ __vcs_ref=""
+ __vcs_sub_dir=""
+ fi
+}

Created lib/virtualenvwrapper.sh

@@ -1,0 +1,13
+#!/bin/bash
+
+__load_venvwrapper() {
+ local venvbase="${BASHD_DIR}/lib/virtualenvwrapper"
+ test ! -d ${venvbase} && return 0
+ export WORKON_HOME=${HOME}/.virtualenvs
+ export PIP_VIRTUALENV_BASE=$WORKON_HOME
+ mkdir -p $WORKON_HOME
+ pathappend ${venvbase} PYTHONPATH
+ . ${venvbase}/virtualenvwrapper.sh
+}
+
+__load_venvwrapper

Created lib/virtualenvwrapper/virtualenvwrapper.sh

@@ -1,0 +1,956
+# -*- mode: shell-script -*-
+#
+# Shell functions to act as wrapper for Ian Bicking's virtualenv
+# (http://pypi.python.org/pypi/virtualenv)
+#
+#
+# Copyright Doug Hellmann, All Rights Reserved
+#
+# Permission to use, copy, modify, and distribute this software and its
+# documentation for any purpose and without fee is hereby granted,
+# provided that the above copyright notice appear in all copies and that
+# both that copyright notice and this permission notice appear in
+# supporting documentation, and that the name of Doug Hellmann not be used
+# in advertising or publicity pertaining to distribution of the software
+# without specific, written prior permission.
+#
+# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+#
+#
+# Project home page: http://www.doughellmann.com/projects/virtualenvwrapper/
+#
+#
+# Setup:
+#
+# 1. Create a directory to hold the virtual environments.
+# (mkdir $HOME/.virtualenvs).
+# 2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs"
+# to your .bashrc.
+# 3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh"
+# to your .bashrc.
+# 4. Run: source ~/.bashrc
+# 5. Run: workon
+# 6. A list of environments, empty, is printed.
+# 7. Run: mkvirtualenv temp
+# 8. Run: workon
+# 9. This time, the "temp" environment is included.
+# 10. Run: workon temp
+# 11. The virtual environment is activated.
+#
+
+# Locate the global Python where virtualenvwrapper is installed.
+if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ]
+then
+ VIRTUALENVWRAPPER_PYTHON="$(\which python2)"
+fi
+
+# Set the name of the virtualenv app to use.
+if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ]
+then
+ VIRTUALENVWRAPPER_VIRTUALENV="virtualenv2"
+fi
+
+# Define script folder depending on the platorm (Win32/Unix)
+VIRTUALENVWRAPPER_ENV_BIN_DIR="bin"
+if [ "$OS" = "Windows_NT" ] && [ "$MSYSTEM" = "MINGW32" ]
+then
+ # Only assign this for msys, cygwin use standard Unix paths
+ # and its own python installation
+ VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts"
+fi
+
+function virtualenvwrapper_derive_workon_home {
+ typeset workon_home_dir="$WORKON_HOME"
+
+ # Make sure there is a default value for WORKON_HOME.
+ # You can override this setting in your .bashrc.
+ if [ "$workon_home_dir" = "" ]
+ then
+ workon_home_dir="$HOME/.virtualenvs"
+ fi
+
+ # If the path is relative, prefix it with $HOME
+ # (note: for compatibility)
+ if echo "$workon_home_dir" | (unset GREP_OPTIONS; \grep '^[^/~]' > /dev/null)
+ then
+ workon_home_dir="$HOME/$WORKON_HOME"
+ fi
+
+ # Only call on Python to fix the path if it looks like the
+ # path might contain stuff to expand.
+ # (it might be possible to do this in shell, but I don't know a
+ # cross-shell-safe way of doing it -wolever)
+ if echo "$workon_home_dir" | (unset GREP_OPTIONS; \egrep '([\$~]|//)' >/dev/null)
+ then
+ # This will normalize the path by:
+ # - Removing extra slashes (e.g., when TMPDIR ends in a slash)
+ # - Expanding variables (e.g., $foo)
+ # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur)
+ workon_home_dir=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.expandvars(os.path.expanduser(\"$workon_home_dir\"))")
+ fi
+
+ echo "$workon_home_dir"
+ return 0
+}
+
+# Check if the WORKON_HOME directory exists,
+# create it if it does not
+# seperate from creating the files in it because this used to just error
+# and maybe other things rely on the dir existing before that happens.
+function virtualenvwrapper_verify_workon_home {
+ RC=0
+ if [ ! -d "$WORKON_HOME/" ]
+ then
+ if [ "$1" != "-q" ]
+ then
+ echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2
+ fi
+ mkdir -p $WORKON_HOME
+ RC=$?
+ fi
+ return $RC
+}
+
+#HOOK_VERBOSE_OPTION="-q"
+
+# Expects 1 argument, the suffix for the new file.
+function virtualenvwrapper_tempfile {
+ # Note: the 'X's must come last
+ typeset suffix=${1:-hook}
+ typeset file="`\mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX`"
+ if [ $? -ne 0 ]
+ then
+ echo "ERROR: virtualenvwrapper could not create a temporary file name." 1>&2
+ return 1
+ fi
+ trap "\rm -f '$file' >/dev/null 2>&1" EXIT
+ echo $file
+ return 0
+}
+
+# Run the hooks
+function virtualenvwrapper_run_hook {
+ typeset hook_script="$(virtualenvwrapper_tempfile ${1}-hook)"
+ if [ -z "$hook_script" ]
+ then
+ echo "ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2
+ return 1
+ fi
+ if [ -z "$VIRTUALENVWRAPPER_LOG_DIR" ]
+ then
+ echo "ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
+ return 1
+ fi
+ "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
+ result=$?
+
+ if [ $result -eq 0 ]
+ then
+ if [ ! -f "$hook_script" ]
+ then
+ echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2
+ return 2
+ fi
+ # cat "$hook_script"
+ source "$hook_script"
+ fi
+ \rm -f "$hook_script" >/dev/null 2>&1
+ return $result
+}
+
+# Set up tab completion. (Adapted from Arthur Koziel's version at
+# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
+function virtualenvwrapper_setup_tab_completion {
+ if [ -n "$BASH" ] ; then
+ _virtualenvs () {
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
+ }
+ _cdvirtualenv_complete () {
+ local cur="$2"
+ COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
+ }
+ _cdsitepackages_complete () {
+ local cur="$2"
+ COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
+ }
+ complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
+ complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages
+ complete -o default -o nospace -F _virtualenvs workon
+ complete -o default -o nospace -F _virtualenvs rmvirtualenv
+ complete -o default -o nospace -F _virtualenvs cpvirtualenv
+ complete -o default -o nospace -F _virtualenvs showvirtualenv
+ elif [ -n "$ZSH_VERSION" ] ; then
+ _virtualenvs () {
+ reply=( $(virtualenvwrapper_show_workon_options) )
+ }
+ _cdvirtualenv_complete () {
+ reply=( $(cdvirtualenv && ls -d ${1}*) )
+ }
+ _cdsitepackages_complete () {
+ reply=( $(cdsitepackages && ls -d ${1}*) )
+ }
+ compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv
+ compctl -K _cdvirtualenv_complete cdvirtualenv
+ compctl -K _cdsitepackages_complete cdsitepackages
+ fi
+}
+
+# Set up virtualenvwrapper properly
+function virtualenvwrapper_initialize {
+ export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)"
+
+ virtualenvwrapper_verify_workon_home -q || return 1
+
+ # Set the location of the hook scripts
+ if [ "$VIRTUALENVWRAPPER_HOOK_DIR" = "" ]
+ then
+ export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME"
+ fi
+
+ # Set the location of the hook script logs
+ if [ "$VIRTUALENVWRAPPER_LOG_DIR" = "" ]
+ then
+ export VIRTUALENVWRAPPER_LOG_DIR="$WORKON_HOME"
+ fi
+
+ virtualenvwrapper_run_hook "initialize"
+ if [ $? -ne 0 ]
+ then
+ echo "virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
+ return 1
+ fi
+
+ virtualenvwrapper_setup_tab_completion
+
+}
+
+
+# Verify that virtualenv is installed and visible
+function virtualenvwrapper_verify_virtualenv {
+ typeset venv=$(\which "$VIRTUALENVWRAPPER_VIRTUALENV" | (unset GREP_OPTIONS; \grep -v "not found"))
+ if [ "$venv" = "" ]
+ then
+ echo "ERROR: virtualenvwrapper could not find $VIRTUALENVWRAPPER_VIRTUALENV in your path" >&2
+ return 1
+ fi
+ if [ ! -e "$venv" ]
+ then
+ echo "ERROR: Found $VIRTUALENVWRAPPER_VIRTUALENV in path as \"$venv\" but that does not exist" >&2
+ return 1
+ fi
+ return 0
+}
+
+# Verify that the requested environment exists
+function virtualenvwrapper_verify_workon_environment {
+ typeset env_name="$1"
+ if [ ! -d "$WORKON_HOME/$env_name" ]
+ then
+ echo "ERROR: Environment '$env_name' does not exist. Create it with 'mkvirtualenv $env_name'." >&2
+ return 1
+ fi
+ return 0
+}
+
+# Verify that the active environment exists
+function virtualenvwrapper_verify_active_environment {
+ if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]
+ then
+ echo "ERROR: no virtualenv active, or active virtualenv is missing" >&2
+ return 1
+ fi
+ return 0
+}
+
+# Help text for mkvirtualenv
+function mkvirtualenv_help {
+ echo "Usage: mkvirtualenv [-i package] [-r requirements_file] [virtualenv options] env_name"
+ echo
+ echo " -i package"
+ echo
+ echo " Install a package after the environment is created."
+ echo " This option may be repeated."
+ echo
+ echo " -r requirements_file"
+ echo
+ echo " Provide a pip requirements file to install a base set of packages"
+ echo " into the new environment."
+ echo;
+ echo 'virtualenv help:';
+ echo;
+ virtualenv -h;
+}
+
+# Create a new environment, in the WORKON_HOME.
+#
+# Usage: mkvirtualenv [options] ENVNAME
+# (where the options are passed directly to virtualenv)
+#
+function mkvirtualenv {
+ typeset -a in_args
+ typeset -a out_args
+ typeset -i i
+ typeset tst
+ typeset a
+ typeset envname
+ typeset requirements
+ typeset packages
+
+ in_args=( "$@" )
+
+ if [ -n "$ZSH_VERSION" ]
+ then
+ i=1
+ tst="-le"
+ else
+ i=0
+ tst="-lt"
+ fi
+ while [ $i $tst $# ]
+ do
+ a="${in_args[$i]}"
+ # echo "arg $i : $a"
+ case "$a" in
+ -h)
+ mkvirtualenv_help;
+ return;;
+ -i)
+ i=$(( $i + 1 ));
+ packages="$packages ${in_args[$i]}";;
+ -r)
+ i=$(( $i + 1 ));
+ requirements="${in_args[$i]}";;
+ *)
+ if [ ${#out_args} -gt 0 ]
+ then
+ out_args=( "${out_args[@]-}" "$a" )
+ else
+ out_args=( "$a" )
+ fi;;
+ esac
+ i=$(( $i + 1 ))
+ done
+
+ set -- "${out_args[@]}"
+
+ eval "envname=\$$#"
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_virtualenv || return 1
+ (
+ [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT
+ \cd "$WORKON_HOME" &&
+ "$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" &&
+ [ -d "$WORKON_HOME/$envname" ] && \
+ virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname"
+ )
+ typeset RC=$?
+ [ $RC -ne 0 ] && return $RC
+
+ # If they passed a help option or got an error from virtualenv,
+ # the environment won't exist. Use that to tell whether
+ # we should switch to the environment and run the hook.
+ [ ! -d "$WORKON_HOME/$envname" ] && return 0
+ # Now activate the new environment
+ workon "$envname"
+
+ if [ ! -z "$requirements" ]
+ then
+ pip install -r "$requirements"
+ fi
+
+ for a in $packages
+ do
+ pip install $a
+ done
+
+ virtualenvwrapper_run_hook "post_mkvirtualenv"
+}
+
+# Remove an environment, in the WORKON_HOME.
+function rmvirtualenv {
+ typeset env_name="$1"
+ virtualenvwrapper_verify_workon_home || return 1
+ if [ "$env_name" = "" ]
+ then
+ echo "Please specify an enviroment." >&2
+ return 1
+ fi
+ env_dir="$WORKON_HOME/$env_name"
+ if [ "$VIRTUAL_ENV" = "$env_dir" ]
+ then
+ echo "ERROR: You cannot remove the active environment ('$env_name')." >&2
+ echo "Either switch to another environment, or run 'deactivate'." >&2
+ return 1
+ fi
+
+ # Move out of the current directory to one known to be
+ # safe, in case we are inside the environment somewhere.
+ typeset prior_dir="$(pwd)"
+ \cd "$WORKON_HOME"
+
+ virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name"
+ \rm -rf "$env_dir"
+ virtualenvwrapper_run_hook "post_rmvirtualenv" "$env_name"
+
+ # If the directory we used to be in still exists, move back to it.
+ if [ -d "$prior_dir" ]
+ then
+ \cd "$prior_dir"
+ fi
+}
+
+# List the available environments.
+function virtualenvwrapper_show_workon_options {
+ virtualenvwrapper_verify_workon_home || return 1
+ # NOTE: DO NOT use ls here because colorized versions spew control characters
+ # into the output list.
+ # echo seems a little faster than find, even with -depth 3.
+ (\cd "$WORKON_HOME"; for f in */$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate; do echo $f; done) 2>/dev/null | \sed 's|^\./||' | \sed "s|/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate||" | \sort | (unset GREP_OPTIONS; \egrep -v '^\*$')
+
+# (\cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
+}
+
+function _lsvirtualenv_usage {
+ echo "lsvirtualenv [-blh]"
+ echo " -b -- brief mode"
+ echo " -l -- long mode"
+ echo " -h -- this help message"
+}
+
+# List virtual environments
+#
+# Usage: lsvirtualenv [-l]
+function lsvirtualenv {
+
+ typeset long_mode=true
+ if command -v "getopts" &> /dev/null
+ then
+ # Use getopts when possible
+ OPTIND=1
+ while getopts ":blh" opt "$@"
+ do
+ case "$opt" in
+ l) long_mode=true;;
+ b) long_mode=false;;
+ h) _lsvirtualenv_usage;
+ return 1;;
+ ?) echo "Invalid option: -$OPTARG" >&2;
+ _lsvirtualenv_usage;
+ return 1;;
+ esac
+ done
+ else
+ # fallback on getopt for other shell
+ typeset -a args
+ args=($(getopt blh "$@"))
+ if [ $? != 0 ]
+ then
+ _lsvirtualenv_usage
+ return 1
+ fi
+ for opt in $args
+ do
+ case "$opt" in
+ -l) long_mode=true;;
+ -b) long_mode=false;;
+ -h) _lsvirtualenv_usage;
+ return 1;;
+ esac
+ done
+ fi
+
+ if $long_mode
+ then
+ for env_name in $(virtualenvwrapper_show_workon_options)
+ do
+ showvirtualenv "$env_name"
+ done
+ else
+ virtualenvwrapper_show_workon_options
+ fi
+}
+
+# Show details of a virtualenv
+#
+# Usage: showvirtualenv [env]
+function showvirtualenv {
+ typeset env_name="$1"
+ if [ -z "$env_name" ]
+ then
+ if [ -z "$VIRTUAL_ENV" ]
+ then
+ echo "showvirtualenv [env]"
+ return 1
+ fi
+ env_name=$(basename $VIRTUAL_ENV)
+ fi
+
+ echo -n "$env_name"
+ virtualenvwrapper_run_hook "get_env_details" "$env_name"
+ echo
+}
+
+# List or change working virtual environments
+#
+# Usage: workon [environment_name]
+#
+function workon {
+ typeset env_name="$1"
+ if [ "$env_name" = "" ]
+ then
+ lsvirtualenv -b
+ return 1
+ fi
+
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_workon_environment $env_name || return 1
+
+ activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"
+ if [ ! -f "$activate" ]
+ then
+ echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." >&2
+ return 1
+ fi
+
+ # Deactivate any current environment "destructively"
+ # before switching so we use our override function,
+ # if it exists.
+ type deactivate >/dev/null 2>&1
+ if [ $? -eq 0 ]
+ then
+ deactivate
+ unset -f deactivate >/dev/null 2>&1
+ fi
+
+ virtualenvwrapper_run_hook "pre_activate" "$env_name"
+
+ source "$activate"
+
+ # Save the deactivate function from virtualenv under a different name
+ virtualenvwrapper_original_deactivate=`typeset -f deactivate | sed 's/deactivate/virtualenv_deactivate/g'`
+ eval "$virtualenvwrapper_original_deactivate"
+ unset -f deactivate >/dev/null 2>&1
+
+ # Replace the deactivate() function with a wrapper.
+ eval 'deactivate () {
+
+ # Call the local hook before the global so we can undo
+ # any settings made by the local postactivate first.
+ virtualenvwrapper_run_hook "pre_deactivate"
+
+ env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate"
+ old_env=$(basename "$VIRTUAL_ENV")
+
+ # Call the original function.
+ virtualenv_deactivate $1
+
+ virtualenvwrapper_run_hook "post_deactivate" "$old_env"
+
+ if [ ! "$1" = "nondestructive" ]
+ then
+ # Remove this function
+ unset -f virtualenv_deactivate >/dev/null 2>&1
+ unset -f deactivate >/dev/null 2>&1
+ fi
+
+ }'
+
+ virtualenvwrapper_run_hook "post_activate"
+
+ return 0
+}
+
+
+# Prints the Python version string for the current interpreter.
+function virtualenvwrapper_get_python_version {
+ # Uses the Python from the virtualenv because we're trying to
+ # determine the version installed there so we can build
+ # up the path to the site-packages directory.
+ python -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.
+}
+
+# Prints the path to the site-packages directory for the current environment.
+function virtualenvwrapper_get_site_packages_dir {
+ echo "$VIRTUAL_ENV/lib/python`virtualenvwrapper_get_python_version`/site-packages"
+}
+
+# Path management for packages outside of the virtual env.
+# Based on a contribution from James Bennett and Jannis Leidel.
+#
+# add2virtualenv directory1 directory2 ...
+#
+# Adds the specified directories to the Python path for the
+# currently-active virtualenv. This will be done by placing the
+# directory names in a path file named
+# "virtualenv_path_extensions.pth" inside the virtualenv's
+# site-packages directory; if this file does not exist, it will be
+# created first.
+function add2virtualenv {
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_active_environment || return 1
+
+ site_packages="`virtualenvwrapper_get_site_packages_dir`"
+
+ if [ ! -d "${site_packages}" ]
+ then
+ echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" >&2
+ return 1
+ fi
+
+ # Prefix with _ to ensure we are loaded as early as possible,
+ # and at least before easy_install.pth.
+ path_file="$site_packages/_virtualenv_path_extensions.pth"
+
+ if [ "$*" = "" ]
+ then
+ echo "Usage: add2virtualenv dir [dir ...]"
+ if [ -f "$path_file" ]
+ then
+ echo
+ echo "Existing paths:"
+ cat "$path_file" | grep -v "^import"
+ fi
+ return 1
+ fi
+
+ remove=0
+ if [ "$1" = "-d" ]
+ then
+ remove=1
+ shift
+ fi
+
+ if [ ! -f "$path_file" ]
+ then
+ echo "import sys; sys.__plen = len(sys.path)" >> "$path_file"
+ echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file"
+ fi
+
+ for pydir in "$@"
+ do
+ absolute_path=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.abspath(\"$pydir\")")
+ if [ "$absolute_path" != "$pydir" ]
+ then
+ echo "Warning: Converting \"$pydir\" to \"$absolute_path\"" 1>&2
+ fi
+
+ if [ $remove -eq 1 ]
+ then
+ sed -i.tmp "\:^$absolute_path$: d" "$path_file"
+ else
+ sed -i.tmp '1 a\
+'$absolute_path'
+' "$path_file"
+ fi
+ rm -f "${path_file}.tmp"
+ done
+ return 0
+}
+
+# Does a ``cd`` to the site-packages directory of the currently-active
+# virtualenv.
+function cdsitepackages {
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_active_environment || return 1
+ typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
+ \cd "$site_packages"/$1
+}
+
+# Does a ``cd`` to the root of the currently-active virtualenv.
+function cdvirtualenv {
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_active_environment || return 1
+ \cd $VIRTUAL_ENV/$1
+}
+
+# Shows the content of the site-packages directory of the currently-active
+# virtualenv
+function lssitepackages {
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_active_environment || return 1
+ typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
+ ls $@ $site_packages
+
+ path_file="$site_packages/_virtualenv_path_extensions.pth"
+ if [ -f "$path_file" ]
+ then
+ echo
+ echo "_virtualenv_path_extensions.pth:"
+ cat "$path_file"
+ fi
+}
+
+# Toggles the currently-active virtualenv between having and not having
+# access to the global site-packages.
+function toggleglobalsitepackages {
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_active_environment || return 1
+ typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
+ if [ -f $no_global_site_packages_file ]; then
+ rm $no_global_site_packages_file
+ [ "$1" = "-q" ] || echo "Enabled global site-packages"
+ else
+ touch $no_global_site_packages_file
+ [ "$1" = "-q" ] || echo "Disabled global site-packages"
+ fi
+}
+
+# Duplicate the named virtualenv to make a new one.
+function cpvirtualenv {
+ typeset env_name="$1"
+ if [ "$env_name" = "" ]
+ then
+ virtualenvwrapper_show_workon_options
+ return 1
+ fi
+ typeset new_env="$2"
+ if [ "$new_env" = "" ]
+ then
+ echo "Please specify target virtualenv"
+ return 1
+ fi
+ if echo "$WORKON_HOME" | (unset GREP_OPTIONS; \grep "/$" > /dev/null)
+ then
+ typeset env_home="$WORKON_HOME"
+ else
+ typeset env_home="$WORKON_HOME/"
+ fi
+ typeset source_env="$env_home$env_name"
+ typeset target_env="$env_home$new_env"
+
+ if [ ! -e "$source_env" ]
+ then
+ echo "$env_name virtualenv doesn't exist"
+ return 1
+ fi
+
+ \cp -r "$source_env" "$target_env"
+ for script in $( \ls $target_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/* )
+ do
+ newscript="$script-new"
+ \sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
+ \mv "$newscript" "$script"
+ \chmod a+x "$script"
+ done
+
+ "$VIRTUALENVWRAPPER_VIRTUALENV" "$target_env" --relocatable
+ \sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate" > "$target_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"
+
+ (\cd "$WORKON_HOME" && (
+ virtualenvwrapper_run_hook "pre_cpvirtualenv" "$env_name" "$new_env";
+ virtualenvwrapper_run_hook "pre_mkvirtualenv" "$new_env"
+ ))
+ workon "$new_env"
+ virtualenvwrapper_run_hook "post_mkvirtualenv"
+ virtualenvwrapper_run_hook "post_cpvirtualenv"
+}
+
+#
+# virtualenvwrapper project functions
+#
+
+# Verify that the PROJECT_HOME directory exists
+function virtualenvwrapper_verify_project_home {
+ if [ -z "$PROJECT_HOME" ]
+ then
+ echo "ERROR: Set the PROJECT_HOME shell variable to the name of the directory where projects should be created." >&2
+ return 1
+ fi
+ if [ ! -d "$PROJECT_HOME" ]
+ then
+ [ "$1" != "-q" ] && echo "ERROR: Project directory '$PROJECT_HOME' does not exist. Create it or set PROJECT_HOME to an existing directory." >&2
+ return 1
+ fi
+ return 0
+}
+
+# Given a virtualenv directory and a project directory,
+# set the virtualenv up to be associated with the
+# project
+function setvirtualenvproject {
+ typeset venv="$1"
+ typeset prj="$2"
+ if [ -z "$venv" ]
+ then
+ venv="$VIRTUAL_ENV"
+ fi
+ if [ -z "$prj" ]
+ then
+ prj="$(pwd)"
+ fi
+ echo "Setting project for $(basename $venv) to $prj"
+ echo "$prj" > "$venv/.project"
+}
+
+# Show help for mkproject
+function mkproject_help {
+ echo "Usage: mkproject [-t template] [virtualenv options] project_name"
+ echo ""
+ echo "Multiple templates may be selected. They are applied in the order"
+ echo "specified on the command line."
+ echo;
+ echo "mkvirtualenv help:"
+ echo
+ mkvirtualenv -h;
+ echo
+ echo "Available project templates:"
+ echo
+ "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' -l project.template
+}
+
+# Create a new project directory and its associated virtualenv.
+function mkproject {
+ typeset -a in_args
+ typeset -a out_args
+ typeset -i i
+ typeset tst
+ typeset a
+ typeset t
+ typeset templates
+
+ in_args=( "$@" )
+
+ if [ -n "$ZSH_VERSION" ]
+ then
+ i=1
+ tst="-le"
+ else
+ i=0
+ tst="-lt"
+ fi
+ while [ $i $tst $# ]
+ do
+ a="${in_args[$i]}"
+ # echo "arg $i : $a"
+ case "$a" in
+ -h)
+ mkproject_help;
+ return;;
+ -t)
+ i=$(( $i + 1 ));
+ templates="$templates ${in_args[$i]}";;
+ *)
+ if [ ${#out_args} -gt 0 ]
+ then
+ out_args=( "${out_args[@]-}" "$a" )
+ else
+ out_args=( "$a" )
+ fi;;
+ esac
+ i=$(( $i + 1 ))
+ done
+
+ set -- "${out_args[@]}"
+
+ # echo "templates $templates"
+ # echo "remainder $@"
+ # return 0
+
+ eval "typeset envname=\$$#"
+ virtualenvwrapper_verify_project_home || return 1
+
+ if [ -d "$PROJECT_HOME/$envname" ]
+ then
+ echo "Project $envname already exists." >&2
+ return 1
+ fi
+
+ mkvirtualenv "$@" || return 1
+
+ cd "$PROJECT_HOME"
+
+ virtualenvwrapper_run_hook project.pre_mkproject $envname
+
+ echo "Creating $PROJECT_HOME/$envname"
+ mkdir -p "$PROJECT_HOME/$envname"
+ setvirtualenvproject "$VIRTUAL_ENV" "$PROJECT_HOME/$envname"
+
+ cd "$PROJECT_HOME/$envname"
+
+ for t in $templates
+ do
+ echo
+ echo "Applying template $t"
+ # For some reason zsh insists on prefixing the template
+ # names with a space, so strip them out before passing
+ # the value to the hook loader.
+ virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') project.template $envname
+ done
+
+ virtualenvwrapper_run_hook project.post_mkproject
+}
+
+# Change directory to the active project
+function cdproject {
+ virtualenvwrapper_verify_workon_home || return 1
+ virtualenvwrapper_verify_active_environment || return 1
+ if [ -f "$VIRTUAL_ENV/.project" ]
+ then
+ project_dir=$(cat "$VIRTUAL_ENV/.project")
+ if [ ! -z "$project_dir" ]
+ then
+ cd "$project_dir"
+ else
+ echo "Project directory $project_dir does not exist" 1>&2
+ return 1
+ fi
+ else
+ echo "No project set in $VIRTUAL_ENV/.project" 1>&2
+ return 1
+ fi
+ return 0
+}
+
+#
+# Temporary virtualenv
+#
+# Originally part of virtualenvwrapper.tmpenv plugin
+#
+mktmpenv() {
+ typeset tmpenvname
+ typeset RC
+
+ # Generate a unique temporary name
+ tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import uuid; print uuid.uuid4()' 2>/dev/null)
+ if [ -z "$tmpenvname" ]
+ then
+ # This python does not support uuid
+ tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import random; print hex(random.getrandbits(64))[2:-1]' 2>/dev/null)
+ fi
+
+ # Create the environment
+ mkvirtualenv "$@" "$tmpenvname"
+ RC=$?
+ if [ $RC -ne 0 ]
+ then
+ return $RC
+ fi
+
+ # Change working directory
+ cdvirtualenv
+
+ # Create the tmpenv marker file
+ echo "This is a temporary environment. It will be deleted when you run 'deactivate'." | tee "$VIRTUAL_ENV/README.tmpenv"
+
+ # Update the postdeactivate script
+ cat - >> "$VIRTUAL_ENV/bin/postdeactivate" <<EOF
+if [ -f "$VIRTUAL_ENV/README.tmpenv" ]
+then
+ echo "Removing temporary environment:" $(basename "$VIRTUAL_ENV")
+ rmvirtualenv $(basename "$VIRTUAL_ENV")
+fi
+EOF
+}
+
+
+#
+# Invoke the initialization hooks
+#
+virtualenvwrapper_initialize

Created lib/virtualenvwrapper/virtualenvwrapper/__init__.py

@@ -1,0 +1,4
+"""virtualenvwrapper module
+"""
+
+__import__('pkg_resources').declare_namespace(__name__)

Created lib/virtualenvwrapper/virtualenvwrapper/hook_loader.py

@@ -1,0 +1,143
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# Copyright (c) 2010 Doug Hellmann. All rights reserved.
+#
+"""Load hooks for virtualenvwrapper.
+"""
+
+import inspect
+import logging
+import logging.handlers
+import optparse
+import os
+import sys
+
+import pkg_resources
+
+def main():
+ parser = optparse.OptionParser(
+ usage='usage: %prog [options] <hook> [<arguments>]',
+ prog='virtualenvwrapper.hook_loader',
+ description='Manage hooks for virtualenvwrapper',
+ )
+
+ parser.add_option('-S', '--script',
+ help='Runs "hook" then "<hook>_source", writing the ' +
+ 'result to <file>',
+ dest='script_filename',
+ default=None,
+ )
+ parser.add_option('-s', '--source',
+ help='Print the shell commands to be run in the current shell',
+ action='store_true',
+ dest='sourcing',
+ default=False,
+ )
+ parser.add_option('-l', '--list',
+ help='Print a list of the plugins available for the given hook',
+ action='store_true',
+ default=False,
+ dest='listing',
+ )
+ parser.add_option('-v', '--verbose',
+ help='Show more information on the console',
+ action='store_const',
+ const=2,
+ default=1,
+ dest='verbose_level',
+ )
+ parser.add_option('-q', '--quiet',
+ help='Show less information on the console',
+ action='store_const',
+ const=0,
+ dest='verbose_level',
+ )
+ parser.add_option('-n', '--name',
+ help='Only run the hook from the named plugin',
+ action='append',
+ dest='names',
+ default=[],
+ )
+ parser.disable_interspersed_args() # stop when we hit an option without an '-'
+ options, args = parser.parse_args()
+
+ root_logger = logging.getLogger('')
+
+ # Set up logging to a file
+ root_logger.setLevel(logging.DEBUG)
+ file_handler = logging.handlers.RotatingFileHandler(
+ os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_LOG_DIR', 'hook.log')),
+ maxBytes=10240,
+ backupCount=1,
+ )
+ formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
+ file_handler.setFormatter(formatter)
+ root_logger.addHandler(file_handler)
+
+ # Send higher-level messages to the console, too
+ console = logging.StreamHandler()
+ console_level = [ logging.WARNING,
+ logging.INFO,
+ logging.DEBUG,
+ ][options.verbose_level]
+ console.setLevel(console_level)
+ formatter = logging.Formatter('%(name)s %(message)s')
+ console.setFormatter(formatter)
+ root_logger.addHandler(console)
+
+ #logging.getLogger(__name__).debug('cli args %s', args)
+
+ # Determine which hook we're running
+ if not args:
+ parser.error('Please specify the hook to run')
+ hook = args[0]
+
+ if options.sourcing and options.script_filename:
+ parser.error('--source and --script are mutually exclusive.')
+
+ if options.sourcing:
+ hook += '_source'
+
+ log = logging.getLogger(__name__)
+
+ log.debug('Running %s hooks', hook)
+ run_hooks(hook, options, args)
+
+ if options.script_filename:
+ log.debug('Saving sourcable %s hooks to %s', hook, options.script_filename)
+ options.sourcing = True
+ output = open(options.script_filename, "w")
+ try:
+ output.write('# %s\n' % hook)
+ run_hooks(hook + '_source', options, args, output)
+ finally:
+ output.close()
+
+ return 0
+
+def run_hooks(hook, options, args, output=None):
+ if output is None:
+ output = sys.stdout
+
+ for ep in pkg_resources.iter_entry_points('virtualenvwrapper.%s' % hook):
+ if options.names and ep.name not in options.names:
+ continue
+ plugin = ep.load()
+ if options.listing:
+ print ' %-10s -- %s' % (ep.name, inspect.getdoc(plugin) or '')
+ continue
+ if options.sourcing:
+ # Show the shell commands so they can
+ # be run in the calling shell.
+ contents = (plugin(args[1:]) or '').strip()
+ if contents:
+ output.write('# %s\n' % ep.name)
+ output.write(contents)
+ output.write("\n")
+ else:
+ # Just run the plugin ourselves
+ plugin(args[1:])
+
+if __name__ == '__main__':
+ main()

Created lib/virtualenvwrapper/virtualenvwrapper/project.py

@@ -1,0 +1,60
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# Copyright (c) 2010 Doug Hellmann. All rights reserved.
+#
+"""virtualenvwrapper.project
+"""
+
+import logging
+import os
+
+import pkg_resources
+
+from virtualenvwrapper.user_scripts import make_hook, run_global
+
+log = logging.getLogger(__name__)
+
+GLOBAL_HOOKS = [
+ # mkproject
+ ("premkproject",
+ "This hook is run after a new project is created and before it is activated."),
+ ("postmkproject",
+ "This hook is run after a new project is activated."),
+
+ # rmproject
+ ("prermproject",
+ "This hook is run before a project is deleted."),
+ ("postrmproject",
+ "This hook is run after a project is deleted."),
+ ]
+
+def initialize(args):
+ """Set up user hooks
+ """
+ for filename, comment in GLOBAL_HOOKS:
+ make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
+ return
+
+
+def pre_mkproject(args):
+ log.debug('pre_mkproject %s', str(args))
+ envname=args[0]
+ run_global('premkproject', *args)
+ return
+
+def post_mkproject_source(args):
+ return """
+#
+# Run user-provided scripts
+#
+[ -f "$WORKON_HOME/postmkproject" ] && source "$WORKON_HOME/postmkproject"
+"""
+
+def post_activate_source(args):
+ return """
+#
+# Change to the project directory
+#
+[ -f "$VIRTUAL_ENV/.project" ] && cd "$(cat \"$VIRTUAL_ENV/.project\")"
+"""

Created lib/virtualenvwrapper/virtualenvwrapper/user_scripts.py

@@ -1,0 +1,261
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# Copyright (c) 2010 Doug Hellmann. All rights reserved.
+#
+"""Plugin to handle hooks in user-defined scripts.
+"""
+
+import logging
+import os
+import re
+import stat
+import subprocess
+import sys
+
+import pkg_resources
+
+log = logging.getLogger(__name__)
+
+
+# Are we running under msys
+if sys.platform == 'win32' and os.environ.get('OS') == 'Windows_NT' and os.environ.get('MSYSTEM') == 'MINGW32':
+ is_msys = True
+ script_folder = 'Scripts'
+else:
+ is_msys = False
+ script_folder = 'bin'
+
+
+def run_script(script_path, *args):
+ """Execute a script in a subshell.
+ """
+ if os.path.exists(script_path):
+ cmd = [script_path] + list(args)
+ if is_msys:
+ cmd = [get_path(os.environ['MSYS_HOME'],'bin','sh.exe')] + cmd
+ log.debug('running %s', str(cmd))
+ try:
+ return_code = subprocess.call(cmd)
+ except OSError, msg:
+ log.error('could not run "%s": %s', script_path, str(msg))
+ #log.debug('Returned %s', return_code)
+ return
+
+
+def run_global(script_name, *args):
+ """Run a script from $VIRTUALENVWRAPPER_HOOK_DIR.
+ """
+ script_path = get_path('$VIRTUALENVWRAPPER_HOOK_DIR', script_name)
+ run_script(script_path, *args)
+ return
+
+
+PERMISSIONS = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH
+
+
+GLOBAL_HOOKS = [
+ # initialize
+ ("initialize",
+ "This hook is run during the startup phase when loading virtualenvwrapper.sh."),
+
+ # mkvirtualenv
+ ("premkvirtualenv",
+ "This hook is run after a new virtualenv is created and before it is activated."),
+ ("postmkvirtualenv",
+ "This hook is run after a new virtualenv is activated."),
+
+ # rmvirtualenv
+ ("prermvirtualenv",
+ "This hook is run before a virtualenv is deleted."),
+ ("postrmvirtualenv",
+ "This hook is run after a virtualenv is deleted."),
+
+ # deactivate
+ ("predeactivate",
+ "This hook is run before every virtualenv is deactivated."),
+ ("postdeactivate",
+ "This hook is run after every virtualenv is deactivated."),
+
+ # activate
+ ("preactivate",
+ "This hook is run before every virtualenv is activated."),
+ ("postactivate",
+ "This hook is run after every virtualenv is activated."),
+
+ # get_env_details
+ ("get_env_details",
+ "This hook is run when the list of virtualenvs is printed so each name can include details."),
+ ]
+
+
+LOCAL_HOOKS = [
+ # deactivate
+ ("predeactivate",
+ "This hook is run before this virtualenv is deactivated."),
+ ("postdeactivate",
+ "This hook is run after this virtualenv is deactivated."),
+
+ # activate
+ ("preactivate",
+ "This hook is run before this virtualenv is activated."),
+ ("postactivate",
+ "This hook is run after this virtualenv is activated."),
+
+ # get_env_details
+ ("get_env_details",
+ "This hook is run when the list of virtualenvs is printed in 'long' mode so each name can include details."),
+ ]
+
+
+def make_hook(filename, comment):
+ """Create a hook script.
+
+ :param filename: The name of the file to write.
+ :param comment: The comment to insert into the file.
+ """
+ filename = get_path(filename)
+ if not os.path.exists(filename):
+ log.info('creating %s', filename)
+ f = open(filename, 'w')
+ try:
+ f.write("""#!%(shell)s
+# %(comment)s
+
+""" % {'comment':comment, 'shell':os.environ.get('SHELL', '/bin/sh')})
+ finally:
+ f.close()
+ os.chmod(filename, PERMISSIONS)
+ return
+
+
+
+# HOOKS
+
+
+def initialize(args):
+ for filename, comment in GLOBAL_HOOKS:
+ make_hook(get_path('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
+ return
+
+
+def initialize_source(args):
+ return """
+#
+# Run user-provided scripts
+#
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
+"""
+
+def pre_mkvirtualenv(args):
+ log.debug('pre_mkvirtualenv %s', str(args))
+ envname=args[0]
+ for filename, comment in LOCAL_HOOKS:
+ make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
+ run_global('premkvirtualenv', *args)
+ return
+
+
+def post_mkvirtualenv_source(args):
+ return """
+#
+# Run user-provided scripts
+#
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
+"""
+
+def pre_cpvirtualenv(args):
+ log.debug('pre_cpvirtualenv %s', str(args))
+ envname=args[0]
+ for filename, comment in LOCAL_HOOKS:
+ make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
+ run_global('precpvirtualenv', *args)
+ return
+
+
+def post_cpvirtualenv_source(args):
+ return """
+#
+# Run user-provided scripts
+#
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
+"""
+
+
+def pre_rmvirtualenv(args):
+ log.debug('pre_rmvirtualenv')
+ run_global('prermvirtualenv', *args)
+ return
+
+
+def post_rmvirtualenv(args):
+ log.debug('post_rmvirtualenv')
+ run_global('postrmvirtualenv', *args)
+ return
+
+
+def pre_activate(args):
+ log.debug('pre_activate')
+ run_global('preactivate', *args)
+ script_path = get_path('$WORKON_HOME', args[0], script_folder, 'preactivate')
+ run_script(script_path, *args)
+ return
+
+
+def post_activate_source(args):
+ log.debug('post_activate')
+ return """
+#
+# Run user-provided scripts
+#
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
+[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
+"""
+
+
+def pre_deactivate_source(args):
+ log.debug('pre_deactivate')
+ return """
+#
+# Run user-provided scripts
+#
+[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
+"""
+
+
+def post_deactivate_source(args):
+ log.debug('post_deactivate')
+ return """
+#
+# Run user-provided scripts
+#
+VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV="$WORKON_HOME/%(env_name)s"
+[ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
+unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
+""" % { 'env_name':args[0] }
+
+
+def get_env_details(args):
+ log.debug('get_env_details')
+ run_global('get_env_details', *args)
+ script_path = get_path('$WORKON_HOME', args[0], script_folder, 'get_env_details')
+ run_script(script_path, *args)
+ return
+
+def get_path(*args):
+ '''
+ Get a full path from args.
+ Path separator is determined according to the os and the shell and allow to use is_msys.
+ Variables and user are expanded during the process.
+ '''
+ path = os.path.expanduser(os.path.expandvars(os.path.join(*args)))
+ if is_msys:
+ # MSYS accept unix or Win32 and sometimes it drives to mixed style paths
+ if re.match(r'^/[a-zA-Z](/|^)', path):
+ # msys path could starts with '/c/'-form drive letter
+ path = ''.join((path[1],':',path[2:]))
+ path = path.replace('/', os.sep)
+
+ return os.path.abspath(path)

Created theme/default/dircolors

@@ -1,0 +1,258
+
+# Dark 256 color solarized theme for the color GNU ls utility.
+# Used and tested with dircolors (GNU coreutils) 8.5
+#
+# @author {@link http://sebastian.tramp.name Sebastian Tramp}
+# @license http://sam.zoy.org/wtfpl/ Do What The Fuck You Want To Public License (WTFPL)
+#
+# More Information at
+# https://github.com/seebi/dircolors-solarized
+
+# Term Section
+TERM Eterm
+TERM ansi
+TERM color-xterm
+TERM con132x25
+TERM con132x30
+TERM con132x43
+TERM con132x60
+TERM con80x25
+TERM con80x28
+TERM con80x30
+TERM con80x43
+TERM con80x50
+TERM con80x60
+TERM cons25
+TERM console
+TERM cygwin
+TERM dtterm
+TERM eterm-color
+TERM gnome
+TERM gnome-256color
+TERM jfbterm
+TERM konsole
+TERM kterm
+TERM linux
+TERM linux-c
+TERM mach-color
+TERM mlterm
+TERM putty
+TERM rxvt
+TERM rxvt-256color
+TERM rxvt-cygwin
+TERM rxvt-cygwin-native
+TERM rxvt-unicode
+TERM rxvt-unicode256
+TERM rxvt-unicode-256color
+TERM screen
+TERM screen-256color
+TERM screen-256color-bce
+TERM screen-bce
+TERM screen-w
+TERM screen.linux
+TERM vt100
+TERM xterm
+TERM xterm-16color
+TERM xterm-256color
+TERM xterm-88color
+TERM xterm-color
+TERM xterm-debian
+
+## Documentation
+#
+# standard colors
+#
+# Below are the color init strings for the basic file types. A color init
+# string consists of one or more of the following numeric codes:
+# Attribute codes:
+# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
+# Text color codes:
+# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
+# Background color codes:
+# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
+#
+#
+# 256 color support
+# see here: http://www.mail-archive.com/bug-coreutils@gnu.org/msg11030.html)
+#
+# Text 256 color coding:
+# 38;5;COLOR_NUMBER
+# Background 256 color coding:
+# 48;5;COLOR_NUMBER
+
+## Special files
+
+NORMAL 00;38;5;244 # no color code at all
+#FILE 00 # regular file: use no color at all
+RESET 0 # reset to "normal" color
+DIR 00;38;5;33 # directory 01;34
+LINK 01;38;5;37 # symbolic link. (If you set this to 'target' instead of a
+ # numerical value, the color is as for the file pointed to.)
+MULTIHARDLINK 00 # regular file with more than one link
+FIFO 48;5;230;38;5;136;01 # pipe
+SOCK 48;5;230;38;5;136;01 # socket
+DOOR 48;5;230;38;5;136;01 # door
+BLK 48;5;230;38;5;244;01 # block device driver
+CHR 48;5;230;38;5;244;01 # character device driver
+ORPHAN 48;5;235;38;5;160 # symlink to nonexistent file, or non-stat'able file
+SETUID 48;5;160;38;5;230 # file that is setuid (u+s)
+SETGID 48;5;136;38;5;230 # file that is setgid (g+s)
+CAPABILITY 30;41 # file with capability
+STICKY_OTHER_WRITABLE 48;5;64;38;5;230 # dir that is sticky and other-writable (+t,o+w)
+OTHER_WRITABLE 48;5;235;38;5;33 # dir that is other-writable (o+w) and not sticky
+STICKY 48;5;33;38;5;230 # dir with the sticky bit set (+t) and not other-writable
+# This is for files with execute permission:
+EXEC 01;38;5;64
+
+## Archives or compressed (violet + bold for compression)
+.tar 00;38;5;61
+.tgz 01;38;5;61
+.arj 01;38;5;61
+.taz 01;38;5;61
+.lzh 01;38;5;61
+.lzma 01;38;5;61
+.tlz 01;38;5;61
+.txz 01;38;5;61
+.zip 01;38;5;61
+.z 01;38;5;61
+.Z 01;38;5;61
+.dz 01;38;5;61
+.gz 01;38;5;61
+.lz 01;38;5;61
+.xz 01;38;5;61
+.bz2 01;38;5;61
+.bz 01;38;5;61
+.tbz 01;38;5;61
+.tbz2 01;38;5;61
+.tz 01;38;5;61
+.deb 01;38;5;61
+.rpm 01;38;5;61
+.jar 01;38;5;61
+.rar 01;38;5;61
+.ace 01;38;5;61
+.zoo 01;38;5;61
+.cpio 01;38;5;61
+.7z 01;38;5;61
+.rz 01;38;5;61
+.apk 01;38;5;61
+
+# Image formats (yellow)
+.jpg 00;38;5;136
+.JPG 00;38;5;136 #stupid but needed
+.jpeg 00;38;5;136
+.gif 00;38;5;136
+.bmp 00;38;5;136
+.pbm 00;38;5;136
+.pgm 00;38;5;136
+.ppm 00;38;5;136
+.tga 00;38;5;136
+.xbm 00;38;5;136
+.xpm 00;38;5;136
+.tif 00;38;5;136
+.tiff 00;38;5;136
+.png 00;38;5;136
+.svg 00;38;5;136
+.svgz 00;38;5;136
+.mng 00;38;5;136
+.pcx 00;38;5;136
+.dl 00;38;5;136
+.xcf 00;38;5;136
+.xwd 00;38;5;136
+.yuv 00;38;5;136
+.cgm 00;38;5;136
+.emf 00;38;5;136
+.eps 00;38;5;136
+.CR2 00;38;5;136
+.ico 00;38;5;136
+
+# Files of special interest (base1 + bold)
+.tex 01;38;5;245
+.rdf 01;38;5;245
+.owl 01;38;5;245
+.n3 01;38;5;245
+.ttl 01;38;5;245
+.nt 01;38;5;245
+.torrent 01;38;5;245
+*Makefile 01;38;5;245
+*Rakefile 01;38;5;245
+*build.xml 01;38;5;245
+*rc 01;38;5;245
+*1 01;38;5;245
+.nfo 01;38;5;245
+*README 01;38;5;245
+*README.txt 01;38;5;245
+*readme.txt 01;38;5;245
+*README.md 01;38;5;245
+*README.markdown 01;38;5;245
+*ini 01;38;5;245
+*yml 01;38;5;245
+*cfg 01;38;5;245
+*conf 01;38;5;245
+
+# "unimportant" files as logs and backups (base01)
+.log 00;38;5;240
+.bak 00;38;5;240
+.aux 00;38;5;240
+.bbl 00;38;5;240
+.blg 00;38;5;240
+*~ 00;38;5;240
+*# 00;38;5;240
+.part 00;38;5;240
+.incomplete 00;38;5;240
+.swp 00;38;5;240
+.tmp 00;38;5;240
+.temp 00;38;5;240
+.o 00;38;5;240
+.pyc 00;38;5;240
+.class 00;38;5;240
+.cache 00;38;5;240
+
+# Audio formats (orange)
+.aac 00;38;5;166
+.au 00;38;5;166
+.flac 00;38;5;166
+.mid 00;38;5;166
+.midi 00;38;5;166
+.mka 00;38;5;166
+.mp3 00;38;5;166
+.mpc 00;38;5;166
+.ogg 00;38;5;166
+.ra 00;38;5;166
+.wav 00;38;5;166
+.m4a 00;38;5;166
+# http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions
+.axa 00;38;5;166
+.oga 00;38;5;166
+.spx 00;38;5;166
+.xspf 00;38;5;166
+
+# Video formats (as audio + bold)
+.mov 01;38;5;166
+.mpg 01;38;5;166
+.mpeg 01;38;5;166
+.m2v 01;38;5;166
+.mkv 01;38;5;166
+.ogm 01;38;5;166
+.mp4 01;38;5;166
+.m4v 01;38;5;166
+.mp4v 01;38;5;166
+.vob 01;38;5;166
+.qt 01;38;5;166
+.nuv 01;38;5;166
+.wmv 01;38;5;166
+.asf 01;38;5;166
+.rm 01;38;5;166
+.rmvb 01;38;5;166
+.flc 01;38;5;166
+.avi 01;38;5;166
+.fli 01;38;5;166
+.flv 01;38;5;166
+.gl 01;38;5;166
+.m2ts 01;38;5;166
+# http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions
+.axv 01;38;5;166
+.anx 01;38;5;166
+.ogv 01;38;5;166
+.ogx 01;38;5;166
+
+

Created theme/default/prompt.d/00-ssh_hostname.bash

@@ -1,0 +1,7
+__prompt_ssh_hostname() {
+ if [ -n "$SSH_CLIENT" ]; then
+ bashd_prompt_append "${FG_BOLD_GREEN}$(hostname -s) "
+ fi
+}
+
+bashd_prompt_register __prompt_ssh_hostname

Created theme/default/prompt.d/01-current_directory.bash

@@ -1,0 +1,16
+__prompt_current_directory() {
+ transform_pwd() {
+ curdir="$@"
+ curdir=${curdir/#~\/src\//:}
+ curdir=${curdir/#:personal\//${col_txtcyn}➀${col_txtblu}}
+ curdir=${curdir/#:work\//${col_txtred}βš’${col_txtblu}}
+
+ curdir=${curdir/#~\/etc\//${col_txtpur}ΠΆ${col_txtblu}}
+ echo $curdir
+ }
+
+ local CUR_DIR=${PWD/$HOME/\~}
+ bashd_prompt_append "${FG_BLUE}$(transform_pwd ${CUR_DIR})"
+}
+
+bashd_prompt_register __prompt_current_directory

Created theme/default/prompt.d/02-return_code.bash

@@ -1,0 +1,7
+__prompt_return_code() {
+ if [ $LAST_STATUS -gt 0 ]; then
+ bashd_prompt_append " ${FG_BOLD_RED}${LAST_STATUS}!"
+ fi
+}
+
+bashd_prompt_register __prompt_return_code

Created theme/default/prompt.d/20-virtualenv.bash

@@ -1,0 +1,8
+__prompt_virtualenv() {
+ local envname=$(basename $VIRTUAL_ENV 2>/dev/null)
+ if [ -n "$envname" ]; then
+ bashd_prompt_append " ${FG_YELLOW}Β·${envname}Β·"
+ fi
+}
+
+bashd_prompt_register __prompt_virtualenv

Created theme/default/prompt.d/30-pythonbrew.bash

@@ -1,0 +1,8
+__prompt_pythonbrew() {
+ local PYBREW="$(which python 2>/dev/null|sed -n 's/.*Python-\([0-9].[0-9]\).*/\1/p')"
+ if [ ! -z "$PYBREW" ]; then
+ bashd_prompt_append " ${FG_PURPLE}∝${PYBREW}"
+ fi
+}
+
+bashd_prompt_register __prompt_pythonbrew

Created theme/default/prompt.d/40-rvm.bash

@@ -1,0 +1,7
+__prompt_rvm() {
+ if [ ! -z $RUBY_VERSION ]; then
+ bashd_prompt_append " ${FG_GREEN}∼$(echo $RUBY_VERSION |sed 's/.*-\(.\+\)-.*/\1/g')"
+ fi
+}
+
+bashd_prompt_register __prompt_rvm

Created theme/default/prompt.d/50-vscinfo.bash

@@ -1,0 +1,8
+__prompt_vcsinfo() {
+ __vcs_dir
+ if [ ! -z "$__vcs_prefix" ]; then
+ bashd_prompt_append " ${FG_BOLD_WHITE}${__vcs_prefix}${__vcs_ref}"
+ fi
+}
+
+bashd_prompt_register __prompt_vcsinfo

Created theme/default/prompt.d/98-usertag.bash

@@ -1,0 +1,9
+__prompt_usertag() {
+ if [ "$UID" -eq "0" ]; then
+ bashd_prompt_append " ${FG_RED}#"
+ else
+ bashd_prompt_append " ${FG_WHITE}$"
+ fi
+}
+
+bashd_prompt_register __prompt_usertag

Created theme/default/prompt.d/99-reset_color.bash

@@ -1,0 +1,5
+__prompt_reset_color() {
+ bashd_prompt_append "${RESET_COLORS} "
+}
+
+bashd_prompt_register __prompt_reset_color