2016-06-16 10:26:04 +01:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Exit for non-interactive sessions
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
if [ -z "$PS1" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
|
2016-02-16 20:19:31 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Function to prepend PATH only if it doesn't already exist
|
|
|
|
#--------------------------------------------------------------------------------
|
2016-02-16 19:20:07 +00:00
|
|
|
pathadd() {
|
|
|
|
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
|
|
|
|
PATH="$1${PATH:+":$PATH"}"
|
|
|
|
fi
|
|
|
|
}
|
2016-02-16 20:19:31 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2016-02-16 19:20:07 +00:00
|
|
|
|
2016-02-18 08:03:43 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Decrypt stored keys
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
getkey() {
|
|
|
|
KEYFILE=~/.keys/${1}
|
|
|
|
|
|
|
|
if [ -f ${KEYFILE} ]; then
|
2016-02-18 08:20:25 +00:00
|
|
|
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
|
2016-02-18 08:20:25 +00:00
|
|
|
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
|
|
|
#--------------------------------------------------------------------------------
|
2016-08-30 14:31:47 +01:00
|
|
|
export EDITOR=vim
|
2016-10-05 14:30:59 +01:00
|
|
|
alias vi='vim'
|
2014-11-11 21:13:52 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2014-11-11 21:01:06 +00:00
|
|
|
|
2015-01-14 11:12:25 +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
|
|
|
#--------------------------------------------------------------------------------
|
2016-02-16 19:20:07 +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
|
|
|
|
2016-03-07 22:04:48 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Set some variables
|
|
|
|
#--------------------------------------------------------------------------------
|
2016-03-15 19:51:36 +00:00
|
|
|
if [ -x "$(which brew 2>/dev/null)" ]; then
|
|
|
|
export HOMEBREW_GITHUB_API_TOKEN=$(getkey HOMEBREW_GITHUB_API_TOKEN)
|
|
|
|
fi
|
2016-03-07 22:04:48 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
|
2016-03-01 10:20:34 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2016-01-26 20:12:31 +00:00
|
|
|
# Rebind CTRL-T to search forward in history
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
if [ -n "$PS1" ]; then
|
|
|
|
bind "\C-t":forward-search-history
|
|
|
|
fi
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
|
2016-01-27 15:51:13 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2018-09-02 11:23:53 +01:00
|
|
|
# Add bash completion scripts (deferred until the end and backgrounded)
|
2016-01-27 15:51:13 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2018-09-02 11:23:53 +01:00
|
|
|
function _deferred {
|
|
|
|
if [ -f $(brew --prefix 2>/dev/null)/etc/bash_completion ]; then
|
|
|
|
. $(brew --prefix 2>/dev/null)/etc/bash_completion
|
|
|
|
fi
|
|
|
|
}
|
2016-01-27 15:51:13 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
|
2014-11-11 21:13:52 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# A useful prompt
|
|
|
|
#--------------------------------------------------------------------------------
|
2015-09-14 18:26:36 +01:00
|
|
|
export PS1="[\u@\h \W \[\033[32m\]\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ <\1>/')\[\033[00m\]]\\$ "
|
2014-12-05 18:33:16 +00:00
|
|
|
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
|
|
|
|
#--------------------------------------------------------------------------------
|
2017-05-19 08:28:04 +01:00
|
|
|
# Unlimited history buffer
|
|
|
|
export HISTSIZE=
|
|
|
|
export HISTFILESIZE=
|
2014-11-11 21:01:06 +00:00
|
|
|
|
|
|
|
# Avoid duplicates in the history...
|
2017-05-19 08:28:04 +01:00
|
|
|
export HISTCONTROL=ignoreboth
|
2014-11-11 21:01:06 +00:00
|
|
|
|
2017-09-04 10:41:47 +01:00
|
|
|
# Record the timestamp in the bash history
|
|
|
|
export HISTTIMEFORMAT="%Y-%m-%d %T "
|
|
|
|
|
2014-11-11 21:01:06 +00:00
|
|
|
# Append history entries...
|
|
|
|
shopt -s histappend
|
|
|
|
|
|
|
|
# After each command, save and reload history
|
2016-06-10 18:19:31 +01:00
|
|
|
export PROMPT_COMMAND="history -a; ${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}"
|
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-07-16 16:46:14 +01:00
|
|
|
# Command alias functions
|
2014-11-11 21:13:52 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2016-07-28 16:05:50 +01:00
|
|
|
function datafart() { curl --data-binary @- datafart.com; } && export -f datafart
|
|
|
|
function space() { du -ahx --max-depth=1 | sort -h; } && export -f space
|
2016-07-19 14:16:51 +01:00
|
|
|
if ! alias ll >/dev/null 2>&1; then function ll() { ls -l ${@}; } && export -f ll; fi
|
2016-07-28 16:05:50 +01:00
|
|
|
[[ ! -x $(which psgrep 2>/dev/null) ]] && function psgrep() { ps -ef | grep ${@} | grep -v ${$}; } && export -f psgrep
|
2018-07-15 06:38:56 +01:00
|
|
|
[[ -x $(which glances 2>/dev/null) ]] && function top() { glances; } && export -f top
|
2016-07-28 16:05:50 +01:00
|
|
|
[[ -x $(which gdu 2>/dev/null) ]] && function du() { gdu ${@}; } && export -f du
|
|
|
|
[[ -x $(which gsort 2>/dev/null) ]] && function sort() { gsort ${@}; } && export -f sort
|
2017-04-24 09:07:00 +01:00
|
|
|
[[ -x /bin/ps && -x $(which pstree 2>/dev/null) ]] && function ps() { if [[ ${1} =~ 'f' ]]; then pstree; else /bin/ps ${@}; fi }
|
2017-08-05 16:34:49 +01:00
|
|
|
[[ -x $(which tree 2>/dev/null) ]] && alias tree="tree -AQh --du"
|
2018-07-11 09:25:55 +01:00
|
|
|
export GIT_SSH_COMMAND="$(which ssh) -o RemoteCommand=none"
|
2014-11-11 21:13:52 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2014-11-15 17:05:36 +00:00
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Set up GOPATH for Go development
|
|
|
|
#--------------------------------------------------------------------------------
|
2018-02-14 19:44:39 +00:00
|
|
|
export GOPATH=${HOME}
|
2014-11-15 17:05:36 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2014-11-11 21:01:06 +00:00
|
|
|
|
2015-09-29 19:41:04 +01:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Run an SSH agent, if possible
|
|
|
|
#--------------------------------------------------------------------------------
|
2015-09-29 19:49:49 +01:00
|
|
|
# Check if we already have an agent running and sourced
|
2016-02-17 10:49:03 +00:00
|
|
|
if [ -z "${SSH_AUTH_SOCK}" ]; then
|
2016-02-18 08:34:38 +00:00
|
|
|
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)
|
2016-02-18 08:34:38 +00:00
|
|
|
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
|
2016-02-18 08:34:38 +00:00
|
|
|
ssh-add
|
|
|
|
fi
|
2015-09-29 19:41:04 +01:00
|
|
|
fi
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
|
2016-06-10 18:17:00 +01:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# iTerm2 shell integration
|
|
|
|
#--------------------------------------------------------------------------------
|
2019-01-12 14:31:32 +00:00
|
|
|
[ $(uname -s) = 'Darwin' -a -f ~/.iterm2/shell_integration.bash ] && source ~/.iterm2/shell_integration.bash
|
2016-06-10 18:17:00 +01:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
|
2016-01-26 15:49:00 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Run local .bashrc for any local-only commands
|
|
|
|
#--------------------------------------------------------------------------------
|
2014-11-12 16:58:37 +00:00
|
|
|
[ -f ~/.bashrc_local ] && source ~/.bashrc_local
|
2016-01-26 15:49:00 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2018-09-02 11:23:53 +01:00
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
# Kick off the _deferred() function and background it (speeding up Bash loading)
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
trap '_deferred 2>/dev/null; trap USR1' USR1
|
|
|
|
{ sleep 0.1 ; builtin kill -USR1 $$ ; } & disown
|
|
|
|
#--------------------------------------------------------------------------------
|