tidy up bashrc

This commit is contained in:
James Dixon 2022-05-22 12:18:02 -04:00
parent 66aaaade52
commit 3f5c2fb237

View File

@ -4,33 +4,15 @@ case $- in
*) return;; *) return;;
esac esac
# start in tmux session if possible ##* environment variables *##
# if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
# exec tmux
# fi
# history # environment variables for commands
HISTSIZE= ;
HISTFILESIZE=
HISTCONTROL="ignoreboth:erasedups"
HISTTIMEFORMAT="%F %T "
# shell options
# if ! shopt -q checkhash 2> /dev/null; then shopt -s checkhash fi
# if ! shopt -q checkwinsize 2> /dev/null; then shopt -s checkwinsize; fi
# if ! shopt -q cmdhist 2> /dev/null; then shopt -s cmdhist; fi
# if ! shopt -q histappend 2> /dev/null; then shopt -s histappend; fi
# if ! shopt -q extglob 2> /dev/null; then shopt -s extglob; fi
# if ! shopt -q globstar 2> /dev/null; then shopt -s globstar; fi
# command variables
export EDITOR="/usr/bin/vim" export EDITOR="/usr/bin/vim"
export VISUAL="/usr/bin/vim" export VISUAL="/usr/bin/vim"
export PAGER="less" export PAGER="less"
export FZF_DEFAULT_OPTS="--bind=ctrl-f:page-down,ctrl-b:page-up" export FZF_DEFAULT_OPTS="--bind=ctrl-f:page-down,ctrl-b:page-up"
# command options # ls options
ls --version &> /dev/null ls --version &> /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
LS_OPTS="--color=auto --group-directories-first -F" LS_OPTS="--color=auto --group-directories-first -F"
@ -39,9 +21,15 @@ else
export CLICOLOR=1 export CLICOLOR=1
fi fi
## aliases ## # bash history options
HISTSIZE= ;
HISTFILESIZE=
HISTCONTROL="ignoreboth:erasedups"
HISTTIMEFORMAT="%F %T "
# core utils ##* aliases *##
# core utils (ls, grep, tree)
alias l="ls ${LS_OPTS}" alias l="ls ${LS_OPTS}"
alias ls="ls ${LS_OPTS}" alias ls="ls ${LS_OPTS}"
alias ll="ls -lsh ${LS_OPTS}" alias ll="ls -lsh ${LS_OPTS}"
@ -59,7 +47,7 @@ alias lsmnt="mount | column -t"
alias pathls='printf "%b\n" "${PATH//:/\\n}"' alias pathls='printf "%b\n" "${PATH//:/\\n}"'
# git - vim - tmux # (git - vim - tmux)
alias g="git" alias g="git"
alias groot="cd $(git rev-parse --show-toplevel 2> /dev/null || echo -n ".")" alias groot="cd $(git rev-parse --show-toplevel 2> /dev/null || echo -n ".")"
@ -72,11 +60,15 @@ alias tmks="tmux kill-session -t" # kill one session
alias tmka="tmux kill-server" # aka killall alias tmka="tmux kill-server" # aka killall
# python # python
# python3 is python unless python is python
if ! command -v python &> /dev/null && command -v python3 &> /dev/null; then
alias python="python3"
alias py="python3" alias py="python3"
alias ipy="ipython3" alias ipy="ipython3"
fi
alias venvac="source venv/bin/activate" alias venvac="source venv/bin/activate"
# gui things # linux gui things
alias xo="xdg-open" alias xo="xdg-open"
alias firefox-temp='firefox --profile $(mktemp -d) &> /dev/null &' alias firefox-temp='firefox --profile $(mktemp -d) &> /dev/null &'
@ -86,7 +78,7 @@ alias mktar="tar -caf"
alias tarls="tar -tvf" alias tarls="tar -tvf"
alias ungzip="gunzip" alias ungzip="gunzip"
## colors ## ##* color variables *##
# color vars using tput or ANSI/VT100 Control sequences # color vars using tput or ANSI/VT100 Control sequences
# check if tput is available # check if tput is available
if [ -x "$(command -v tput)" ]; then if [ -x "$(command -v tput)" ]; then
@ -136,12 +128,10 @@ else # or fallback to ANSI esacpe codes
bold="\[\033[1m\]"; unesc_bold="\033[1m" bold="\[\033[1m\]"; unesc_bold="\033[1m"
fi fi
## functions ## ##* functions *##
# concat common commands # concat common commands
mkcd() { mkdir -p -- "$1" && cd "$1"; } mkcd() { mkdir -p -- "$1" && cd "$1"; }
cdd() { [ -n "$1" ] && for i in $(seq 1 "$1"); do cd ..; done; } cdd() { [ -n "$1" ] && for i in $(seq 1 "$1"); do cd ..; done; }
cdl() { cd "$1" && ls -l; }
cdla() { cd "$1" && ls -la; }
touchx() { touch "$@" && chmod +x "$@"; } touchx() { touch "$@" && chmod +x "$@"; }
# git # git
@ -167,7 +157,6 @@ tm() {
tmux new-session tmux new-session
fi fi
} }
tma() { tma() {
if [ "$#" -gt 0 ]; then if [ "$#" -gt 0 ]; then
tmux attach-session -d -t "$1" tmux attach-session -d -t "$1"
@ -187,11 +176,12 @@ prependpath() {
[[ ":$PATH:" != *":$1:"* ]] && PATH="$1:${PATH}" [[ ":$PATH:" != *":$1:"* ]] && PATH="$1:${PATH}"
} }
# etc functions # misc functions
colordump(){ colordump(){
for i in $(seq 0 255); do printf "$(tput setaf $i)$i "; done for i in $(seq 0 255); do printf "$(tput setaf $i)$i "; done
} }
# "smart" extract function
extract() { extract() {
if [ -z "$1" ]; then if [ -z "$1" ]; then
# display usage if no parameters given # display usage if no parameters given
@ -250,27 +240,21 @@ datauri() {
fi fi
} }
# grep with color into less
grepless(){ grepless(){
grep -ir --color=always "$*" --exclude-dir=".git" --exclude-dir="node_modules" . | less -RX grep -ir --color=always "$*" --exclude-dir=".git" --exclude-dir="node_modules" . | less -RX
} }
# curl shortcuts # curl shortcuts
cheatsh() { cheatsh() {
curl cheat.sh/"$1" curl cheat.sh/"$1"
} }
watip() { watip() {
curl ifconfig.co curl ifconfig.co
# dig +short myip.opendns.com @resolver1.opendns.com # dig +short myip.opendns.com @resolver1.opendns.com
} }
ethgasprice() { ##* prompt stuff *##
avg=$(curl -sSL https://ethgasstation.info/api/ethgasAPI.json? | jq .average)
echo "Average Price in GWEI: $((avg/10))"
}
## prompt stuff ##
# git prompt function # git prompt function
parse_git() { parse_git() {
@ -298,11 +282,9 @@ parse_git() {
PS1="\W \\$ " PS1="\W \\$ "
# PS1="[\u@\h:\W]\\$ " # PS1="[\u@\h:\W]\\$ "
# PS1="\u@\h:\W\\$ " # PS1="\u@\h:\W\\$ "
# *color prompts* # *color prompts*
# PS1="${bold}${blue}\W ${yellow}\\$ ${reset}" # PS1="${bold}${blue}\W ${yellow}\\$ ${reset}"
# PS1="${bold}${purple}\u${yellow}@${cyan}\h${white}:${blue}\W ${yellow}\\$ ${reset}" # PS1="${bold}${purple}\u${yellow}@${cyan}\h${white}:${blue}\W ${yellow}\\$ ${reset}"
# *git color prompts* # *git color prompts*
# PS1="${bold}${blue}\W\$(parse_git)${green} \\$ ${reset}" # PS1="${bold}${blue}\W\$(parse_git)${green} \\$ ${reset}"
# PS1="${bold}${white}\t ${blue}\W\$(parse_git) ${cyan}\\$ ${reset}" # PS1="${bold}${white}\t ${blue}\W\$(parse_git) ${cyan}\\$ ${reset}"
@ -322,9 +304,7 @@ fi
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh; [ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh;
## paths ## ## paths ##
# language version managers #
## language version managers ##
# rbenv (ruby) # rbenv (ruby)
src_rbenv(){ src_rbenv(){
if command -v ruby > /dev/null && command -v gem > /dev/null; then if command -v ruby > /dev/null && command -v gem > /dev/null; then
@ -369,24 +349,30 @@ if command -v cargo > /dev/null; then
appendpath "$HOME/.cargo/bin" appendpath "$HOME/.cargo/bin"
fi fi
## macOS package managers ## ## macOS package managers ##
# homebrew # homebrew
[ -d "/opt/homebrew/bin" ] && appendpath "/opt/homebrew/bin" [ -d "/opt/homebrew/bin" ] && appendpath "/opt/homebrew/bin"
# python3 (macOS) # python3 (macOS)
[ -d "$HOME/Library/Python/3.8/bin" ] && appendpath "$HOME/Library/Python/3.8/bin" [ -d "$HOME/Library/Python/3.8/bin" ] && appendpath "$HOME/Library/Python/3.8/bin"
# local bins # local bins
[ -d "$HOME/.local/bin" ] && appendpath "$HOME/.local/bin" [ -d "$HOME/.local/bin" ] && appendpath "$HOME/.local/bin"
[ -d "$HOME/.local/scripts" ] && appendpath "$HOME/.local/scripts" [ -d "$HOME/.local/scripts" ] && appendpath "$HOME/.local/scripts"
# local rc # local rc
[ -r "$HOME/.config/bashrc" ] && source "$HOME/.config/bashrc" [ -r "$HOME/.config/bashrc" ] && source "$HOME/.config/bashrc"
[ -r "$HOME/.local/bashrc" ] && source "$HOME/.local/bashrc" [ -r "$HOME/.local/bashrc" ] && source "$HOME/.local/bashrc"
# start in tmux session if possible
# if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
# exec tmux
# fi
# shell options
# if ! shopt -q checkhash 2> /dev/null; then shopt -s checkhash fi
# if ! shopt -q checkwinsize 2> /dev/null; then shopt -s checkwinsize; fi
# if ! shopt -q cmdhist 2> /dev/null; then shopt -s cmdhist; fi
# if ! shopt -q histappend 2> /dev/null; then shopt -s histappend; fi
# if ! shopt -q extglob 2> /dev/null; then shopt -s extglob; fi
# if ! shopt -q globstar 2> /dev/null; then shopt -s globstar; fi
# vim:ft=sh # vim:ft=sh