dotfiles /

Filename Size Date modified Message
docs
etc
requirements
scripts
src
205 B
64 B
842 B
12.0 KB
3.4 KB
206 B
433 B
15.0 KB
28.3 KB
0 B
683 B

dotfiles

Bash scripts, Python scripts, and configuration files for working with projects on *nix platforms in Bash, ZSH, Ruby, and Python.

Objective

  • Minimize error by standardizing common workflows and processes

Configuration files

Included in etc/ are configuration files for:

Bash Configuration

Load Sequence

$ bash
# (~/.bashrc)                    -> ./etc/.bashrc
#    -> (~/.bashrc.venv.sh)     -> ./etc/.bashrc.venv.sh
#        -> (./etc/.bashmarks.sh)
#        -> (./etc/usrlog.sh)
#        -> (~/.projectsrc.sh

etc/.bashrc

Deliberately minimal .bashrc. Should be symlinked to ~/.bashrc.

Sources:

  • etc/.bashrc.venv.sh

etc/.bashrc.venv.sh

Configures ${__WORKSPACE} and ${WORKON_HOME} for virtualenvwrapper and venv.

Sources:

  • etc/.bashmarks.sh
  • etc/usrlog.sh
  • ${__WORKSPACE}/.projectsrc.sh

bashmarks

etc/.bashmarks.sh

A shell script that allows you to save and jump to commonly used directories.

Usage:

# Save bookmark
s bookmarkname

# Goto bookmark
g bookmarkname
g b[TAB]

# Print bookmark
p bookmarkname
p b[TAB]

# Delete bookmark
d bookmarkname
d [TAB]

# List bookmarks
l

Sources:

usrlog.sh

etc/usrlog.sh

Delimited and timestamped terminal history with lightweight 'sessions'

Each invocation of bash or zsh generates a new TERM_ID string which is prepended to the terminal history record.

TERM_ID values are random, but can be set by calling stid

echo $TERM_ID
# 0eZfHHVar76

# Set a new TERM_ID
stid

echo $TERM_ID
BUaOZ2FshNk

# Specify a TERM_ID
stid app_configuration

echo $TERM_ID
app_configuration
# term_id ::: 0eZfHHVar76 [ ./dotfiles/.usrlog ]
$

$VIRTUAL_ENV

When $VIRTUAL_ENV is set in the environment, terminal history is appended to $VIRTUAL_ENV-specific _USRLOG and HISTFILE files.

tail -n 5 ~/.usrlog
tail -n 5 ~/.virtualenvs/dotfiles/.usrlog

~/.projectsrc.sh

${__WORKSPACE}/projectsrc.sh

System-local bash configuration.

virtualenv

Virtual python environment builder

Install:

pip install virtualenv

Sources:

Documentation:

virtualenvwrapper

Enhancements to virtualenv

Install:

# install virtualenvwrapper
pip install virtualenvwrapper

# configure virtualenvwrapper shell variables
grep WORKON_HOME ~/.bashrc.venv.sh
grep VIRTUALENVWRAPPER_SCRIPT ~/.bashrc.venv.sh

Sources:

Documentation:

Venv

./etc/ipython/profile_default/ipython_config.py

Enhancements to virtualenvwrapper for Bash, ZSH, and IPython

Venv is defined in an executable IPython ipython_config.py file:

export
alias

echo $_VENV
cat $_VENV
#> omitted for readability

venv -E --bash
source <(venv -E --bash)

export
alias

Features

  • Configures Python site for a given virtualenv
  • Configures Python sys.path: IPython extension paths
  • Configures IPython command aliases (%alias, or just alias)
  • Generates Bash environments from virtualenv paths
  • Configures Bash variables starting with $_
  • Executes subcommands within generated environments (venv -x bash)

Usage

Create a virtualenv (virtualenvwrapper):

mkvirtualenv dotfiles
workon dotfiles
pip install -e https://bitbucket.org/westurner/dotfiles

Work on a project:

we dotfiles

List current environment settings:

venv -E --bash

Generate environment settings for an environment:

venv dotfiles --bash

Execute a command within an environment:

venv dotfiles -x gnome-terminal

The we command adds a _venv alias to venv -E, so the following commands are equivalent:

venv -E --print
venv dotfiles --print
_venv --print
_venv dotfiles --print
$_VENV -E --print
$_VENV dotfiles --print

List Venv-generated Venv variables, aliases, and commands with:

venv -E --bash

Paths should be contained within ${VIRTUAL_ENV}, which is set by virtualenvwrapper through a call to workon:

echo ${VIRTUAL_ENV}
#
workon dotfiles
echo ${VIRTUAL_ENV}
# ~/.virtualenvs/dotfiles
echo ${_WRD}
#
source <(venv -E --bash)
echo ${_WRD}
# ~/.virtualenvs/dotfiles/src/dotfiles
echo ${_APP}
# dotfiles

Python API

A Venv object builds an Env with ${VIRTUAL_ENV}-relative paths in a common filesystem hierarchy and an ordered dictionary of command aliases, which can be serialized to a bash script (venv --bash) or to JSON (venv --print).

import Venv, json
venv = Venv(from_environ=True)
venv.print()
venv.bash_env()

venv.configure_sys()
venv.configure_ipython()

assert venv.virtualenv  == venv.env['VIRTUAL_ENV']
assert venv.appname     == venv.env['_APP']

print(venv.env['_WRD'])     # working directory
#> ~/.virtualenvs/dotfiles

print(venv.aliases['_edit'])
#> gvim --servername dotfiles --remote-tab

print(venv.env['_EDIT_'])
#> gvim --servername dotfiles --remote-tab

Command Aliases

Note

Many of the aliases generated by Venv are also defined in bashrc.venv.sh.

cd Aliases

cdb:

cd $_BIN
# cdvirtualenv bin

cde:

cd $_ETC
# cdvirtualenv etc

cdpylib:

cd $_PYLIB
# cdsitepackages ..

cdpysite:

cd $_PYSITE
# cdsitepackages

cds:

cd $_SRC
# cdvirtualenv src

cdv:

cd $VIRTUAL_ENV
# cdvirtualenv

cdvar:

cd $_VAR
# cdvirtualenv var

cdve:

cd $WORKON_HOME

cdw:

cd $_WRD
# cdvirtualenv src/${_APP}

cdww:

cd $_WWW
# cdvirtualenv var/www

cdhelp:

set | grep '^cd.*()' | cut -f1 -d' '

gvim

_edit
gvim --servername=${_APP} --remote-tab
_editp::
_edit {README,setup.py,...}

grin

grin --help:

grin --help
grind --help
grin[d] --help

grin[d]v:

grin[d] ${VIRTUAL_ENV}

grin[d]s:

grin[d] ${_SRC}

grin[d]w:

grin[d] ${_WRD}

ipython

ip_session
generate a new ipython notebook sessionkey
ipnb
Start ipython notebook with notebooks from ${_SRC}/notebooks
ipqt
Start IPython Qt console

Scripts

In scripts/

bashmarks_to_nerdtree.sh

Convert bashmarks shortcut variables starting with DIR_ to NERDTreeBookmarks format:

l
./bashmarks_to_nerdtree.sh | tee ~/.NERDTreeBookmarks
gittagstohgtags.sh
Convert git tags to hgtags format
pulse.sh
Setup, configure, start, stop, and restart pulseaudio
setup_mathjax.py
Setup MathJax
setup_pandas_notebook_deb.sh
Setup IPython Notebook, Scipy, Numpy, Pandas with Ubuntu packages and pip
setup_pandas_notebook.sh
Setup Brew, IPython Notebook, scipy, numpy, and pandas on OSX
setup_scipy_deb.py
Install and symlink scipy, numpy, and matplotlib from apt

Python Console Scripts

In src/dotfiles:

deb_deps.py
Work with debian dependencies
deb_search.py
Search for a debian package
build_docs.py
Build sets of sphinx documentation projects
greppaths.py
Grep
lsof.py
lsof subprocess wrapper
mactool.py
MAC address tool
optimizepath.py
Work with PATH as an ordered set
passwordstrength.py
Gauge password strength
pipls.py
Walk and enumerate a pip requirements file
pycut.py
Similar to coreutils' cut: split line-based files into fields
py_index.py
Create a python package index HTML file for a directory of packages. (.egg, .zip, .tar.gz, tgz)
pyline.py
Similar to sed and awk: Execute python expressions over line-based files
pyren.py
Skeleton regex file rename script
repos.py

Wrap version control system commandline interfaces

  • Find vcs repositories
  • Wrap shell commands
  • Yield event tuples from repositories in hg, bzr, git, svn
usrlog.py
Search through .usrlog files

setup.py

Python packaging.

setup.py imports from pavement.py, which requires paver.

Standard setuptools commands are supported:

python setup.py help

pavement.py

pavement.py adds a few useful commands to the standard set of paver commands.

Install

Part One

Install virtualenvwrapper:

pip install virtualenvwrapper
# or: apt-get install virtualenvwrapper

Make a virtualenv for the dotfiles source:

mkvirtualenv dotfiles
workon dotfiles
cdvirtualenv
mkdir -p ${VIRTUAL_ENV}/src
cdvirtualenv src

Part Two

Clone and install the dotfiles repository.

From BitBucket:

repo_url="https://bitbucket.org/westurner/dotfiles"
git clone $repo_url
cd dotfiles
python setup.py develop

# or:
pip install -e hg+$repo_url

From Github:

repo=_url"https://github.com/westurner/dotfiles"
hg clone $repo_url
cd dotfiles
python setup.py develop

# or:
pip install -e git+$repo_url

Part Three

Symlink configuration files from dotfiles/etc:

_etc="~/.dotfiles/etc"
cd ${HOME}
ln -s ${_etc}/.bashrc.venv.sh
ln -s ${_etc}/.bashrc
# or: echo "source ~/.virtualenvs/dotfiles" >> ~/.bashrc

ln -s ${_etc}/.gemrc
ln -s ${_etc}/.htoprc
ln -s ${_etc}/.inputrc
ln -s ${_etc}/.pdbrc
ln -s ${_etc}/.pydistutils.cfg
ln -s ${_etc}/.pythonrc
ln -s ${_etc}/.vimperatorrc
ln -s ${_etc}/hg/.hgrc
ln -s ${_etc}/ipython/ipython_default.py ~/.ipython/profile_default/
ln -s ${_etc}/mimeapps.list ~/.local/share/applications/
ln -s ${_etc}/pip/

source ${HOME}/.bashrc
touch  ${HOME}/.projects.sh
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.