dotfiles/.bashrc

149 lines
6.5 KiB
Bash
Raw Normal View History

2016-02-16 20:19:31 +00:00
#--------------------------------------------------------------------------------
# Function to prepend PATH only if it doesn't already exist
#--------------------------------------------------------------------------------
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1${PATH:+":$PATH"}"
fi
}
2016-02-16 20:19:31 +00:00
#--------------------------------------------------------------------------------
2016-02-18 08:03:43 +00:00
#--------------------------------------------------------------------------------
# Decrypt stored keys
#--------------------------------------------------------------------------------
getkey() {
KEYFILE=~/.keys/${1}
if [ -f ${KEYFILE} ]; then
if [ -x /usr/bin/security ]; then
PASS=$(/usr/bin/security find-internet-password -l ssh:scott@wallace.sh -gw)
else
read -sp "Password: " PASS
2016-02-18 08:43:13 +00:00
echo
fi
2016-02-18 08:03:43 +00:00
openssl rsautl -decrypt -inkey ~/.ssh/scott@wallace.sh -passin "pass:${PASS}" -in ${KEYFILE} 2>/dev/null
else
echo "No such key" >&2
fi
}
#--------------------------------------------------------------------------------
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2014-11-11 21:01:06 +00:00
# The best editor
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2015-03-06 17:40:44 +00:00
alias vi=vim
2014-11-15 17:05:36 +00:00
export EDITOR=vim
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2014-11-11 21:01:06 +00:00
#--------------------------------------------------------------------------------
# Make less use visual bell
#--------------------------------------------------------------------------------
export LESS="-qr"
#--------------------------------------------------------------------------------
2016-01-26 15:38:37 +00:00
#--------------------------------------------------------------------------------
# Default directories
#--------------------------------------------------------------------------------
mkdir -p ~/src ~/tmp ~/var/log
#--------------------------------------------------------------------------------
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2014-11-11 21:01:06 +00:00
# Update the path with local overrides
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
pathadd /usr/local/sbin
pathadd /usr/local/bin
pathadd ~/bin
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2014-11-11 21:01:06 +00:00
#--------------------------------------------------------------------------------
# Set some variables
#--------------------------------------------------------------------------------
if [ -x "$(which brew 2>/dev/null)" ]; then
export HOMEBREW_GITHUB_API_TOKEN=$(getkey HOMEBREW_GITHUB_API_TOKEN)
fi
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
2016-03-01 10:20:34 +00:00
# Display pretty summary thing at the beginning of a session
#--------------------------------------------------------------------------------
archey -o 2>/dev/null
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Rebind CTRL-T to search forward in history
#--------------------------------------------------------------------------------
if [ -n "$PS1" ]; then
bind "\C-t":forward-search-history
fi
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Add bash completion scripts
#--------------------------------------------------------------------------------
2016-02-29 18:24:19 +00:00
if [ -f $(brew --prefix 2>/dev/null)/etc/bash_completion ]; then
. $(brew --prefix 2>/dev/null)/etc/bash_completion
2016-02-29 11:52:27 +00:00
fi
#--------------------------------------------------------------------------------
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
# A useful prompt
#--------------------------------------------------------------------------------
export PS1="[\u@\h \W \[\033[32m\]\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ <\1>/')\[\033[00m\]]\\$ "
export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Record history for longer and more dynamically
#--------------------------------------------------------------------------------
2014-11-11 21:01:06 +00:00
# Large history buffer
export HISTSIZE=9999
export HISTFILESIZE=9999
# Avoid duplicates in the history...
export HISTCONTROL=ignoredups:erasedups
# Append history entries...
shopt -s histappend
# After each command, save and reload history
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a"
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2014-11-11 21:01:06 +00:00
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2016-01-27 15:49:34 +00:00
# Command aliases
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2016-01-27 15:49:34 +00:00
alias ll='ls -l'
[[ -x $(which htop 2>/dev/null) ]] && alias top='sudo htop'
2016-04-04 09:17:58 +01:00
alias psgrep='ps -ef | grep'
2014-11-11 21:13:52 +00:00
#--------------------------------------------------------------------------------
2014-11-15 17:05:36 +00:00
#--------------------------------------------------------------------------------
# Set up GOPATH for Go development
#--------------------------------------------------------------------------------
export GOPATH=${HOME}/src/go
#--------------------------------------------------------------------------------
2014-11-11 21:01:06 +00:00
#--------------------------------------------------------------------------------
# Run an SSH agent, if possible
#--------------------------------------------------------------------------------
# Check if we already have an agent running and sourced
2016-02-17 10:49:03 +00:00
if [ -z "${SSH_AUTH_SOCK}" ]; then
SSH_AUTH_SOCK_FILE=~/.ssh/auth_sock
if [ -S ${SSH_AUTH_SOCK_FILE} ]; then
2016-02-18 08:40:56 +00:00
export SSH_AUTH_SOCK=${SSH_AUTH_SOCK_FILE}
export SSH_AGENT_PID=$(cat ~/.ssh/agent.pid)
else
eval `ssh-agent -a ${SSH_AUTH_SOCK_FILE} -s`
2016-02-18 08:40:56 +00:00
echo ${SSH_AGENT_PID} > ~/.ssh/agent.pid
ssh-add
fi
fi
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# Run local .bashrc for any local-only commands
#--------------------------------------------------------------------------------
[ -f ~/.bashrc_local ] && source ~/.bashrc_local
#--------------------------------------------------------------------------------