dotfiles/.bashrc

126 lines
2.8 KiB
Bash

#
# ~/.bashrc -- global .bashrc, includes ~/.bashrc.local
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Bash settings
set -o noclobber
shopt -s checkwinsize
export HISTCONTROL=ignorespace
export PROMPT_DIRTRIM=3
# Color output and default options
export TERM=xterm-color
export GREP_OPTS='--color=auto'
export LS_OPTS='--color=auto -hFN --group-directories-first'
export LESS="-Ri"
# Colored man pages
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# Set default options
alias ls='ls ${LS_OPTS}'
alias grep='grep ${GREP_OPTS}'
# Common shortcut aliases
alias l='ls -l'
alias la='ls -a'
alias ll='ls -la'
alias sorth='sort -hr'
alias ps-grep='ps -ef | grep'
# Push the queerfeminist agenda
alias woman='man'
alias enby='man'
# X application aliases
alias gvimr='gvim --remote-silent'
alias xclip_='xclip -selection clipboard'
# Open files according to MIME type
xo() {
(nohup mimeopen "$@" 2>/dev/null 1>&2 &)
}
# Wine aliases
alias wine32='env WINEARCH=win32 WINEPREFIX="$HOME/.wine32" wine'
# Stop Ctrl-S from doing terminally things in vim/vimdiff
vim() {
local STTYOPTS="$(stty --save)"
stty stop '' -ixoff
command vim "$@"
stty "$STTYOPTS"
}
vimdiff() {
local STTYOPTS="$(stty --save)"
stty stop '' -ixoff
command vimdiff "$@"
stty "$STTYOPTS"
}
# yay without parameters does "pacman -Syu" but I don't want it to do this
yay() {
[[ $# -gt 0 ]] || { echo "error: no operation specified (use -h for help)"; return 1; }
command yay "$@"
}
# Create and cd to tmp dir
alias cdtmp='cd $(mktemp -d -p ~/tmp/)'
calc() {
echo "$@" | bc
}
# Show content of something, `ls` for dirs (and special files), `cat` for files
lscat() {
[[ $# -eq 0 ]] && ls -la && return
printnewline=""
for f in "$@"; do
[[ $printnewline ]] && echo
printnewline=1
if [[ -f $f ]]; then
[[ $# -gt 1 ]] && echo "-- cat \"$f\""
cat "$f"
else
[[ $# -gt 1 ]] && echo "-- ls \"$f\""
ls -la "$f"
fi
done
}
# Define colors for bash prompt (will also be used in .bashrc.local)
TRED='\[\e[0;31m\]' # Red
TGREEN='\[\e[0;32m\]' # Green
TCYANB='\[\e[1;36m\]' # Cyan bold
TBLUE='\[\e[0;34m\]' # Blue
TWHITEB='\[\e[1;37m\]' # White bold
TRESET='\[\e[0m\]' # Text Reset
# Set default prompt
if [[ ${EUID} == 0 ]] ; then
PS1="${TRED}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
else
PS1="${TGREEN}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
fi
# Include host-specific bashrc
[[ -f ~/.bashrc.local ]] && source ~/.bashrc.local
# Clean up environment variables
unset TRED TGREEN TCYANB TBLUE TWHITEB TRESET