.Dotfiles

Paul Esch-Laurent

there's no place like $HOME

WHAT?

[...] user's home directory to store per-user configuration [...]

e.g. .bashrc, .vimrc, .gitconfig

Not for forking.

How to manage?

Feat. my dotfiles:

  • Bash
  • Vim
  • Tmux
  • Git
  • Ack
  • .inputrc (readline)

Bash: aliases

Replacement of a word by another string.

Examples:

# Always use color output for `ls`
alias ls="ls --color" # --color for GNU, -G for Mac OS

# Better default output from `dirs`
alias dirs='dirs -v'

# Copy `pwd` with no '\n' to the clipboard
alias cpwd="pwd | tr -d '\n' | pbcopy"

Bash: functionS

As expected: arguments, multiple statements, return values.

Examples:

# Make a directory and `cd` into it
mkd() {
	mkdir -p "$@" && cd "$_"
}

# Get the weather
weather() {
	# If no $1, use the zip code from our IP
	# If no $2, use "q0n" as URL params
	curl -s -H "Accept-Language: ${LANG%_*}" http://wttr.in/${1:-$(curl -s http://ipinfo.io/postal)}?${2:-q0n}
}

# Kill all processes on a specified port
# Source: https://stackoverflow.com/a/5043907
killport() {
	if [ -z "${1}" ]; then
		echo "Usage: \`killport <port>\`"
		return 1
	fi

	lsof -i tcp:${1} | awk 'NR!=1 {print $2}' | xargs kill
}

Bash: prompt

Export $PS1: hostname, username, Git repo, etc.

screenshot:

vim: config

But how do I exit?!

examples:

" Save file with root permissions
cmap w!! w !sudo tee % > /dev/null

" Toggle :paste mode with F2
set pastetoggle=<F2>

" 'jk' goes into normal mode from insert mode
inoremap jk <Esc>

vim: plugins

But there's so many options?

tl;dr:

  • Pathogen for managing your plugins
  • vim-sensible is a un-opinionated starting point
  • Tim Pope (github.com/tpope) has lots of plugins
    • ... and is author of the above two

tmux: config

Recommendation: re-map the <prefix> keybinding.

Example:

# Rebind prefix to C-a
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Start window index at 1 (match keyboard order)
set -g base-index 1
setw -g pane-base-index 1

# Re-number windows sequentially after closing them
set -g renumber-windows on

# Use | and - to split panes
unbind '"'
unbind %
bind | split-window -h
bind - split-window -v

tmux: plugins

Once again, there's so many options?

tl;dr:

  • tpm for managing your plugins
  • tmux-sensible is a un-opinionated starting point
  • tmux-resurrect for keeping sessions after reboot

git: config

Aliases (again?!) and settings. Globally and repo-specific.

Example:

[alias]    
    # Git `status` with shorthand output
    st  = status -bs
    sti = status -bs --ignored

    # List contributors with number of commits
    who = shortlog -sn

    # Show verbose output about tags, branches or remotes
    tags = tag -l
    branches = branch -a
    remotes = remote -v

[push]
    default = simple
    followTags = true

git: commit templates

Keeps commits more consistent (can pair with a Vim config).

Example:

[commit]
	template = ~/.gitmessage
# If applied, this commit will...

# Explain why this change is being made

# Provide links to any relevant tickets, articles or other resources
" Force the cursor onto a new line after 80 characters
set textwidth=80

" However, in Git commit messages, let’s make it 72 characters
autocmd FileType gitcommit set textwidth=72

" Color the column just after our line limit so that we don’t type over it
set colorcolumn=+1

" In Git commit messages, also color the 51st column (for titles)
autocmd FileType gitcommit set colorcolumn+=51

git: commit templates (cont.)

Using the previous settings.

Example:

git: bash completion

Handle tab-completion for branch names et al.

Example:

# Source Git Bash completion
source ~/.bash/git-completion.bash

readline: .inputrc

Configures the Readline lib (used in REPLs like Python).

Example:

# Case insensitive <Tab>-completion
set completion-ignore-case on

# Use up/down for history searching
"\e[A": history-search-backward
"\e[B": history-search-forward

# Cycle through completions
"\t": menu-complete

ProTip: z

Track commonly-used dirs based on "frecency". rupa/z

Example:

# Source z (https://github.com/rupa/z)
source ~/.bash/z/z.sh

ProTip: Separate out files

Separate based on aliases, functions, exports, etc.

Example:

# Load the shell dotfiles
for file in ~/.{exports,aliases,functions,bash_prompt,bash.local}; do
	[ -r "$file" ] && source "$file"
done
unset file

ProTip: Local config overrides

Untracked files to override configs based on local changes.

Example:

" Local config
if filereadable($HOME . "/.vimrc.local")
	source ~/.vimrc.local
endif

# Local config
if-shell "[ -f ~/.tmux.conf.local ]" 'source ~/.tmux.conf.local'

questions?

Dotfiles

By Paul Esch-Laurent

Dotfiles

A general overview of dotfiles.

  • 155