From ed8a957f569188401dee78f1fadb5c390ff425e3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 20 Dec 2015 23:39:37 -0500 Subject: [PATCH] Rewrite bash dotfiles --- bash/aliases | 67 +--------------------------------------------------- bash/config | 38 +++++++++++++++++++++++++---- bash/path | 35 --------------------------- bash_profile | 31 +++++++++++++++++------- 4 files changed, 56 insertions(+), 115 deletions(-) delete mode 100644 bash/path diff --git a/bash/aliases b/bash/aliases index c452069e..ab39093a 100755 --- a/bash/aliases +++ b/bash/aliases @@ -1,66 +1 @@ -#!/bin/bash - -alias q='exit' -alias clr='clear' -alias catn='cat -n' # cat + line numbers -# Allow sudo with aliases -alias sudo='sudo ' -alias ls='ls -G' -alias l='ls -o' -alias la='ls -AGFoh' - -# Command fixes -alias ln="${aliases[ln]:-ln} -v" # verbose ln -alias wget='wget -c' # Resume download if possible -alias rsyncd='rsync -va --delete' # Hard sync two directories - -# Shortcut for git -is-callable hub && alias git='hub' -g() { [ $# -eq 0 ] && git status --short || git $* } - -alias gi='git init' -alias ga='git add' -alias gap='git add --patch' -alias gc='git commit --verbose' -alias gcm='git commit --verbose -m' -alias gco='git checkout' -alias gcl='git clone' -alias gp='git push' -alias gpl='git pull' -alias gb='git branch' -alias gt='git tag' -alias gs='git status --short' -alias gS='git status' -alias gr='git reset "HEAD^"' -alias gd='git diff' - -if is-callable 'tmux'; then - alias t='tmux' - - # Start new session or create a grouped session so I'm not simply watching - # the same session in both windows. - alias ta='tmux new -s $(hostname) || tmux new -t $(hostname) -s $(hostname)-2 || tmux attach -t "io-2"' - - function ts { - tmux send-keys "$*" - } - - alias tls='tmux ls' - # New instance attached to old session - alias tn='tmux new-session -t "x"' -fi - -alias va='vagrant' -alias rk='rake' -alias rkg='rake -g' - -# Interpreters -alias rb='ruby' -alias rbe='rbenv' -alias b='bundle' -alias be='bundle exec' -alias bi='bundle install --path vendor' - -alias py='python' -alias pye='pyenv' -alias pyi='ipython' +load aliases diff --git a/bash/config b/bash/config index 3c6a6bac..e5e67229 100644 --- a/bash/config +++ b/bash/config @@ -15,14 +15,42 @@ shopt -s autocd 2>/dev/null shopt -s globstar 2>/dev/null +#### Exports ################################################ + +# Make vim the default editor. +export EDITOR='vim'; + +# Enable persistent REPL history for `node`. +export NODE_REPL_HISTORY=~/.node_history; +# Allow 32³ entries; the default is 1000. +export NODE_REPL_HISTORY_SIZE='32768'; +# Use sloppy mode by default, matching web browsers. +export NODE_REPL_MODE='sloppy'; + +# Make Python use UTF-8 encoding for output to stdin, stdout, and stderr. +export PYTHONIOENCODING='UTF-8'; + +# Increase Bash history size. Allow 32³ entries; the default is 500. +export HISTSIZE='32768'; +export HISTFILESIZE="${HISTSIZE}"; +# Omit duplicates and commands that begin with a space from history. +export HISTCONTROL='ignoreboth'; + +# Prefer US English and use UTF-8. +export LANG='en_US.UTF-8'; +export LC_ALL='en_US.UTF-8'; + +# Highlight section titles in manual pages. +export LESS_TERMCAP_md="${yellow}"; + +# Don’t clear the screen after quitting a manual page. +export MANPAGER='less -X'; + + #### Completion ############################################# # Add tab completion for many Bash commands -if is-callable "brew" && [ -f "$(brew --prefix)/etc/bash_completion" ]; then - source "$(brew --prefix)/etc/bash_completion"; -elif [ -f /etc/bash_completion ]; then - source /etc/bash_completion; -fi +[ -f /etc/bash_completion ] && source /etc/bash_completion # Enable tab completion for `g` by marking it as an alias for `git` if type _git &> /dev/null && [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then diff --git a/bash/path b/bash/path deleted file mode 100644 index 3f3e4ae4..00000000 --- a/bash/path +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -declare -a paths_prepend=( - "/usr/local/bin" - "/usr/local/sbin" - "$HOME/.dotfiles/bin" - "$HOME/.rbenv/shims" - "$HOME/.pyenv/shims" - "$HOME/.rbenv/bin" - "$HOME/.pyenv/bin" - "$(brew --prefix coreutils)/libexec/gnubin" -) - -declare -a paths_append=( - # ... -) - -# Prepend directories to PATH -for index in ${!dirs_to_prepend[*]}; do - if [ -d ${dirs_to_prepend[$index]} ]; then - # If these directories exist, then prepend them to existing PATH - PATH="${dirs_to_prepend[$index]}:$PATH" - fi -done - -# Append directories to PATH -for index in ${!dirs_to_append[*]}; do - if [ -d ${dirs_to_append[$index]} ]; then - # If these bins exist, then append them to existing PATH - PATH="$PATH:${dirs_to_append[$index]}" - fi -done - -unset paths_prepend paths_append -export PATH diff --git a/bash_profile b/bash_profile index 89c2a3ad..5c5c32f3 100644 --- a/bash_profile +++ b/bash_profile @@ -1,7 +1,3 @@ -function is-callable { - which "$1" > /dev/null -} - # set 256 color profile where possible if [[ $COLORTERM == gnome-* && $TERM == xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color @@ -10,9 +6,26 @@ elif infocmp xterm-256color >/dev/null 2>&1; then fi -#### Other Settings ######################################### +## Bash rcfiles ########################### -source ~/.bash/path -source ~/.bash/aliases -source ~/.bash/config -source ~/.bash/prompt +source $HOME/.dotfiles/.common.sh + +declare -a paths=( + "$DOTFILES/{bin,scripts}" + "$HOME/.{rb,py}env/{shims,bin}" + "/usr/local/{bin,sbin}" +) +[[ "$OSTYPE" == "darwin"* ]] && paths+="$(brew --prefix coreutils)/libexec/gnubin" + +for index in ${!paths[*]}; do + [ -d ${paths[$index]} ] && PATH="${paths[$index]}:$PATH" +done +unset paths +export PATH + + +## Bash rcfiles ########################### + +load bash/aliases # ~/.bash/aliases +load bash/config # ~/.bash/config +iload bash/prompt # ~/.bash/prompt