2023-01-06 23:22:05 +00:00
|
|
|
### Andrew's .bashrc
|
2019-05-02 01:21:48 +00:00
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
# _ _
|
|
|
|
# ___ _ ____ _(_)_ __ ___ _ __ _ __ ___ ___ _ __ | |_
|
|
|
|
# / _ \ '_ \ \ / / | '__/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __|
|
|
|
|
# | __/ | | \ V /| | | | (_) | | | | | | | | | __/ | | | |_
|
|
|
|
# \___|_| |_|\_/ |_|_| \___/|_| |_|_| |_| |_|\___|_| |_|\__|
|
|
|
|
|
|
|
|
|
|
|
|
# Set some defaults.
|
|
|
|
export EDITOR="nvim"
|
2023-01-07 05:13:34 +00:00
|
|
|
export PATH=".:~/bin:~/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
|
2023-01-06 23:20:53 +00:00
|
|
|
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"
|
|
|
|
|
|
|
|
|
2023-01-07 05:13:34 +00:00
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
# checks (stolen from zshuery)
|
|
|
|
if [[ $(uname) = 'Linux' ]]; then
|
|
|
|
IS_LINUX=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $(uname) = 'Darwin' ]]; then
|
|
|
|
IS_MAC=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -x `which brew >/dev/null 2>&1` ]]; then
|
|
|
|
HAS_BREW=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -x `which apt-get >/dev/null 2>&1` ]]; then
|
|
|
|
HAS_APT=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -x `which yum >/dev/null 2>&1` ]]; then
|
|
|
|
HAS_YUM=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# _
|
|
|
|
# _ __ _ __ ___ _ __ ___ _ __ | |_
|
|
|
|
# | '_ \| '__/ _ \| '_ ` _ \| '_ \| __|
|
|
|
|
# | |_) | | | (_) | | | | | | |_) | |_
|
|
|
|
# | .__/|_| \___/|_| |_| |_| .__/ \__|
|
|
|
|
# |_| |_|
|
|
|
|
|
|
|
|
|
2019-05-02 01:21:48 +00:00
|
|
|
# define useful aliases for color codes
|
|
|
|
sh_norm="\[\033[0m\]"
|
|
|
|
sh_black="\[\033[0;30m\]"
|
|
|
|
sh_dark_gray="\[\033[1;30m\]"
|
|
|
|
sh_blue="\[\033[0;34m\]"
|
|
|
|
sh_light_blue="\[\033[1;34m\]"
|
|
|
|
sh_green="\[\033[0;32m\]"
|
|
|
|
sh_light_green="\[\033[1;32m\]"
|
|
|
|
sh_cyan="\[\033[0;36m\]"
|
|
|
|
sh_light_cyan="\[\033[1;36m\]"
|
|
|
|
sh_red="\[\033[0;31m\]"
|
|
|
|
sh_light_red="\[\033[1;31m\]"
|
|
|
|
sh_purple="\[\033[0;35m\]"
|
|
|
|
sh_light_purple="\[\033[1;35m\]"
|
|
|
|
sh_brown="\[\033[0;33m\]"
|
|
|
|
sh_yellow="\[\033[1;33m\]"
|
|
|
|
sh_light_gray="\[\033[0;37m\]"
|
|
|
|
sh_white="\[\033[1;37m\]"
|
|
|
|
|
|
|
|
# Make a pretty prompt.
|
2023-01-02 00:52:58 +00:00
|
|
|
export PROMPT_COMMAND='history -a; if [ $? -ne 0 ];then ERROR_FLAG=1;else ERROR_FLAG=;fi;'
|
2019-05-02 01:21:48 +00:00
|
|
|
export PS1=${HOSTCOLOUR}${sh_light_gray}'\t | \h'${sh_green}':\w'${sh_light_gray}' '${sh_light_gray}'${ERROR_FLAG:+'${sh_light_red}'}\$ '${sh_norm}
|
|
|
|
|
|
|
|
# New files and folders should not be world readable
|
|
|
|
umask 0027
|
|
|
|
|
|
|
|
# Borrow features from sensible.bash
|
|
|
|
|
|
|
|
# Trim long paths in prompt
|
|
|
|
PROMPT_DIRTRIM=2
|
|
|
|
|
|
|
|
# Update window size after every command
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# _ _ _
|
|
|
|
# | |__ (_)___| |_ ___ _ __ _ _
|
|
|
|
# | '_ \| / __| __/ _ \| '__| | | |
|
|
|
|
# | | | | \__ \ || (_) | | | |_| |
|
|
|
|
# |_| |_|_|___/\__\___/|_| \__, |
|
|
|
|
# |___/
|
|
|
|
|
2019-05-02 01:21:48 +00:00
|
|
|
# Append history don't overwrite
|
|
|
|
shopt -s histappend
|
|
|
|
|
|
|
|
# Save multi-line commands as one line
|
|
|
|
shopt -s cmdhist
|
|
|
|
|
|
|
|
# Avoid duplicate entries
|
|
|
|
export HISTCONTROL="erasedups:ignoreboth"
|
|
|
|
|
|
|
|
# Use ISO8601 time format for history file.
|
|
|
|
export HISTTIMEFORMAT='%F %T '
|
|
|
|
|
|
|
|
# Big history file
|
|
|
|
HISTSIZE=500000
|
|
|
|
HISTFILESIZE=100000
|
|
|
|
|
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
# _ _
|
|
|
|
# __ _| (_) __ _ ___ ___ ___
|
|
|
|
# / _` | | |/ _` / __|/ _ \/ __|
|
|
|
|
# | (_| | | | (_| \__ \ __/\__ \
|
|
|
|
# \__,_|_|_|\__,_|___/\___||___/
|
2019-05-02 01:21:48 +00:00
|
|
|
|
|
|
|
# jump down the tree.
|
|
|
|
alias ..="cd .."
|
|
|
|
|
|
|
|
# empty the screen (or use C-l)
|
|
|
|
alias c="clear"
|
|
|
|
|
|
|
|
# why wouldn't you want human readable sizes?
|
|
|
|
alias df="df -h"
|
|
|
|
|
|
|
|
# get outta here!
|
|
|
|
alias e="exit"
|
|
|
|
|
|
|
|
# grep shortie
|
|
|
|
alias g="grep --color=auto -i "
|
|
|
|
|
|
|
|
# shorter ls
|
|
|
|
alias l="ls -G"
|
|
|
|
|
|
|
|
# list files with details
|
|
|
|
alias ll="ls -lh"
|
|
|
|
|
|
|
|
# list all files.
|
|
|
|
alias la="ls -alh"
|
|
|
|
|
|
|
|
# List directories.
|
|
|
|
alias ld="ls -Gd */"
|
|
|
|
|
|
|
|
# add some color to grep.
|
|
|
|
alias grep="grep --color=auto"
|
|
|
|
|
|
|
|
# make the whole directory tree if required and let us know about it.
|
|
|
|
alias mkdir="mkdir -p -v "
|
|
|
|
|
|
|
|
# don't ping forever.
|
|
|
|
#alias ping="ping -c5"
|
|
|
|
|
|
|
|
# refresh the shell customizations without opening a new one.
|
2023-01-02 00:52:58 +00:00
|
|
|
alias refresh="source ~/.bashrc && hash -r"
|
2019-05-02 01:21:48 +00:00
|
|
|
|
|
|
|
# A python calculator
|
|
|
|
alias pc='python -ic "from __future__ import division; from math import *"'
|
|
|
|
|
|
|
|
# Start nano with line numbering no wrapping and autoindenting
|
|
|
|
alias nano='nano -ciw '
|
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
# shortcut for tmux command
|
|
|
|
alias tm="tmux new-session -A -s main"
|
|
|
|
|
|
|
|
# always use nvim
|
|
|
|
alias vim='nvim'
|
|
|
|
alias vi='nvim'
|
|
|
|
alias nv='nvim'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# __ _ _
|
|
|
|
# / _|_ _ _ __ ___| |_(_) ___ _ __ ___
|
|
|
|
# | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
|
|
|
|
# | _| |_| | | | | (__| |_| | (_) | | | \__ \
|
|
|
|
# |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
|
|
|
|
|
2019-05-02 01:21:48 +00:00
|
|
|
# General purpose extract command.
|
|
|
|
extract () {
|
|
|
|
if [ -f $1 ] ; then
|
|
|
|
case $1 in
|
|
|
|
*.tar.bz2) tar xjf $1 ;;
|
|
|
|
*.tar.gz) tar xzf $1 ;;
|
|
|
|
*.tar.xz) tar xJf $1 ;;
|
|
|
|
*.bz2) bunzip2 $1 ;;
|
|
|
|
*.rar) rar x $1 ;;
|
|
|
|
*.gz) gunzip $1 ;;
|
|
|
|
*.tar) tar xf $1 ;;
|
|
|
|
*.tbz2) tar xjf $1 ;;
|
|
|
|
*.tgz) tar xzf $1 ;;
|
|
|
|
*.zip) unzip $1 ;;
|
|
|
|
*.Z) uncompress $1 ;;
|
|
|
|
*.7z) 7za e $1 ;;
|
|
|
|
*.xz) xz -dv $1 ;;
|
|
|
|
*) echo "'$1' cannot be extracted via extract()" ;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
echo "'$1' is not a valid file"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# General purpose backup command.
|
|
|
|
bu () { tar czf ~/.backup/`basename $1`-`date +%Y%m%d%H%M`.tgz $1; }
|
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
# create an archive of a list of files, compress the archive, and encrypt the compressed archive
|
|
|
|
function archive-and-encrypt {
|
|
|
|
echo -n "Enter desired output filename: "
|
|
|
|
read filename
|
|
|
|
tar cJ $1 | \
|
|
|
|
gpg -q -r andrew@amdavidson.com -s -e -o "$filename.tar.xz.gpg"
|
|
|
|
}
|
|
|
|
|
2019-05-02 01:21:48 +00:00
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
# run mosh and tmux to a specific host
|
|
|
|
function mt {
|
|
|
|
mosh $1 -- tmux new-session -A -s main
|
2019-05-02 01:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-06 23:20:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
# _ _
|
|
|
|
# (_)_ __ ___ _ __ ___ _ __| |_ ___
|
|
|
|
# | | '_ ` _ \| '_ \ / _ \| '__| __/ __|
|
|
|
|
# | | | | | | | |_) | (_) | | | |_\__ \
|
|
|
|
# |_|_| |_| |_| .__/ \___/|_| \__|___/
|
|
|
|
# |_|
|
|
|
|
|
2023-01-07 01:58:30 +00:00
|
|
|
# import fzf if possible
|
|
|
|
|
|
|
|
# Debian
|
|
|
|
if [ -d /usr/share/doc/fzf/examples ]; then
|
|
|
|
source /usr/share/doc/fzf/examples/key-bindings.bash
|
|
|
|
source /usr/share/doc/fzf/examples/completion.bash
|
|
|
|
fi
|
|
|
|
|
|
|
|
# MacOS
|
|
|
|
if [ -d /opt/homebrew/opt/fzf/shell ]; then
|
|
|
|
source /opt/homebrew/opt/fzf/shell/key-bindings.bash
|
|
|
|
source /opt/homebrew/opt/fzf/shell/completion.bash
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-02 01:21:48 +00:00
|
|
|
# Import local extensions if needed.
|
|
|
|
if [ -f $HOME/.bashrc_local ]; then
|
|
|
|
source $HOME/.bashrc_local
|
|
|
|
fi
|
|
|
|
|