182 lines
6.8 KiB
Bash
182 lines
6.8 KiB
Bash
|
#
|
||
|
# this is my ~/.bashrc
|
||
|
# (Note: this _should_ be _somewhat_ OS-agnostic, at least, enough for me)
|
||
|
#
|
||
|
|
||
|
# If not running interactively, don't do anything
|
||
|
[[ $- != *i* ]] && return
|
||
|
|
||
|
# source global bashrc settings (turned off by default, uncomment otherwise)
|
||
|
# [ -f /etc/bashrc ] && source /etc/bashrc
|
||
|
|
||
|
shopt -s checkwinsize # check window size after cmd, update LINES and COLUMNS
|
||
|
shopt -s globstar # pattern '**' matches all files, >= 0 dir/subdirs
|
||
|
|
||
|
HISTCONTROL=ignoredups # ignore duplicate commands or if start with a space
|
||
|
HISTSIZE=48000 # history lines stored in memory (while using bash)
|
||
|
HISTFILESIZE=48000 # history lines stored in .bash_history after session
|
||
|
shopt -s histappend # append to history file instead of overwriting
|
||
|
|
||
|
case "$(uname -s)" in # for OS-specific configuration
|
||
|
Linux) operating_system='linux' ;;
|
||
|
Darwin) operating_system='macOS' ;;
|
||
|
FreeBSD|OpenBSD|NetBSD) operating_system='BSD' ;;
|
||
|
CYGWIN*|MINGW32*|MSYS*|MINGW*) operating_system='windows' ;;
|
||
|
*) operating_system='other' ;;
|
||
|
esac
|
||
|
|
||
|
[ -f /etc/hostname ] && hostname="$(cat /etc/hostname)"
|
||
|
|
||
|
# apply "secret" settings (these are just settings I don't want in git)
|
||
|
[ -f "$HOME"/.bashrc_secrets ] && source "$HOME"/.bashrc_secrets
|
||
|
|
||
|
# set PATH to something tolerable
|
||
|
# NOTE: in Arch, everything's already in /usr/bin, /usr/sbin anyway
|
||
|
PATH="/usr/bin:/usr/local/bin:/bin:/usr/sbin:/usr/local/sbin:/sbin" # base
|
||
|
PATH="$PATH:/var/lib/snapd/snap/bin" # snapd
|
||
|
PATH="$PATH:/usr/local/games:/usr/games" # base
|
||
|
if [ "$hostname" = "foundryside" ]; then
|
||
|
PATH="$PATH:$HOME/bin" # my own secret sauce
|
||
|
PATH="$PATH:$HOME/bin/jdk-11.0.10+9/bin" # JavaTM
|
||
|
PATH="$PATH:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl" # BS
|
||
|
fi
|
||
|
export PATH
|
||
|
|
||
|
# use 'nvim' if it exists on system
|
||
|
[ command -v nvim &> /dev/null ] && export EDITOR="nvim" || export EDITOR="vim"
|
||
|
|
||
|
export BROWSER="firefox"
|
||
|
|
||
|
# make less more friendly for non-text input files, see lesspipe(1)
|
||
|
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||
|
|
||
|
|
||
|
# uncomment for a colored prompt, if the terminal has the capability; turned
|
||
|
# off by default to not distract the user: the focus in a terminal window
|
||
|
# should be on the output of commands, not on the prompt
|
||
|
#force_color_prompt=yes
|
||
|
if [ -n "$force_color_prompt" ]; then
|
||
|
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
|
||
|
# We have color support; assume it's compliant with Ecma-48
|
||
|
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
|
||
|
# a case would tend to support setf rather than setaf.)
|
||
|
color_prompt=yes
|
||
|
else
|
||
|
color_prompt=
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
if [[ "$operating_system" = "macOS" || "$operating_system" = "BSD" ]] ; then
|
||
|
export CLICOLOR=1
|
||
|
fi
|
||
|
|
||
|
# PS1 settings
|
||
|
#Old PS1: PS1="[\u@\h]:\w\$ "
|
||
|
if [[ $(id -u) -eq 0 ]]; then # if current user is root
|
||
|
PS1="\[\033[41m\]\[\033[37m\][\u@\h]\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ "
|
||
|
elif [[ -f ~/.bash_prompt ]]; then # not root, but ~/.bash_prompt exists
|
||
|
unset color_prompt force_color_prompt
|
||
|
source ~/.bash_prompt
|
||
|
else # if not root, and no prompt config
|
||
|
PS1="\[\033[1;37m\][\u@\h]\[\033[00m\]:\[\033[01;32m\]\w\[\033[00m\]$ "
|
||
|
fi
|
||
|
|
||
|
# colored GCC warnings and errors
|
||
|
GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01: quote=01'
|
||
|
export GCC_COLORS
|
||
|
|
||
|
|
||
|
# find-keyword [directory path] [keyword]: find and list files with keyword in
|
||
|
# the filename
|
||
|
find-keyword() {
|
||
|
if [ "$#" -ne 2 ]; then # if not given 2 arguments
|
||
|
echo "Usage: find-keyword [directory path] [keyword]"
|
||
|
else
|
||
|
find $1 -name "*$2*" -ls
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# find-string [string] [directory path]: find and list files containing the
|
||
|
# provided string (and list all occurences/line numbers of the string)
|
||
|
find-string() {
|
||
|
if [ "$#" -ne 2 ]; then # if not given 2 arguments
|
||
|
echo "Usage: find-string [string] [directory path]"
|
||
|
else
|
||
|
grep -nR "$1" "$2"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Note to self: alias substitution is recursive AS LONG AS each expanded alias
|
||
|
# ends in a space character (allowing for multiple aliases to be used on one
|
||
|
# line). This is a POSIX specification. You do not know how long it took me to
|
||
|
# figure this out.
|
||
|
|
||
|
# miscellaneous aliases
|
||
|
alias cl='clear '
|
||
|
alias e='exit '
|
||
|
alias q='exit '
|
||
|
alias DIE='shutdown now '
|
||
|
alias cp='cp -i' # confirm before overwriting a file
|
||
|
alias fucking='sudo '
|
||
|
alias goddammit=' '
|
||
|
alias bottom='top '
|
||
|
alias bc='bc -l ' # makes bc use 'scale=20' by default
|
||
|
alias grep='grep --color '
|
||
|
alias vim="$EDITOR "
|
||
|
alias i3config="$EDITOR ~/.config/i3/config && i3-msg reload && i3-msg restart"
|
||
|
alias bashrc="$EDITOR ~/.bashrc"
|
||
|
alias vimrc="$EDITOR ~/.vimrc"
|
||
|
alias nanorc="nano ~/.config/nano/nanorc" # just for fun!
|
||
|
alias spellcheck='aspell check '
|
||
|
alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m' "
|
||
|
not_in_vim="echo -e \"You're not in vim doofus!\""
|
||
|
alias :wq="$not_in_vim" ; alias :q="$not_in_vim" ; alias :x="$not_in_vim"
|
||
|
alias ZZ="$not_in_vim"
|
||
|
|
||
|
alias rager='ranger '; alias anger='ranger '; alias range='ranger '
|
||
|
alias rangre='ranger '; alias rangr='ranger ' # <<<-^^^-: common ranger typos
|
||
|
|
||
|
alias gdb='gdb -q ' # muzzle gdb
|
||
|
|
||
|
if [[ "$operating_system" = "macOS" ]]; then
|
||
|
alias ls='ls -C '
|
||
|
alias l='ls -C '
|
||
|
alias ll='ls -lh '
|
||
|
alias la='ls -A '
|
||
|
alias lla='ls -lhA '
|
||
|
elif [[ "$operating_system" = "BSD" ]]; then
|
||
|
alias ls='ls --color=auto '
|
||
|
alias l='ls --color=auto '
|
||
|
alias ll='ls -lh --color=auto '
|
||
|
alias la='ls -A --color=auto '
|
||
|
alias lla='ls -lhA --color=auto '
|
||
|
else # assume GNU ls (should work on _most_ Linuxes)
|
||
|
alias ls='ls -C --color=auto '
|
||
|
alias l='ls -C --color=auto '
|
||
|
alias ll='ls -lh --color=auto '
|
||
|
alias la='ls -A --color=auto '
|
||
|
alias lla='ls -lhA --color=auto '
|
||
|
fi
|
||
|
|
||
|
|
||
|
# enable programmable completion features (possibly already enabled by
|
||
|
# /etc/bash.bashrc or /etc/profile).
|
||
|
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
||
|
source /usr/share/bash-completion/bash_completion
|
||
|
elif [ -f /etc/bash_completion ]; then
|
||
|
source /etc/bash_completion
|
||
|
fi
|
||
|
if [ "$operating_system" = "macOS" ]; then
|
||
|
if [ -f /usr/local/etc/bash_completion ]; then # for macOS
|
||
|
source /usr/local/etc/bash_completion
|
||
|
elif [ -d /usr/local/etc/bash_completion.d ]; then # also for macOS
|
||
|
for file in /usr/local/etc/bash_completion.d/* ; do
|
||
|
source "$file"
|
||
|
done
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
complete -cf sudo # so sudo actually has tab autocompletion
|
||
|
bind 'set completion-ignore-case on' # case-insensitive tab autocompletion
|
||
|
|