UP  |  HOME

Bash shell

Table of Contents

Configs

Listing 1: ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# Vi-like keybindings
set -o vi

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# set PATH so it includes user's private bin if it exists
if [ -d ~/.local/bin ] ; then
    PATH="${PATH}":~/.local/bin
fi

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=2000
HISTFILESIZE=10000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lessfile ] && eval "$(SHELL=/bin/sh lessfile)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# 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
export PROMPT_DIRTRIM=3
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[38;5;10m\]\u\[$(tput sgr0)\]\[\033[38;5;12m\]@\[$(tput sgr0)\]\[\033[38;5;13m\]\h\[$(tput sgr0)\]:\[$(tput sgr0)\]\[\033[38;5;12m\]\w\\$\[$(tput sgr0)\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ '
fi
unset color_prompt force_color_prompt

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    (test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)") || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    alias dir='dir --color=auto'
    alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# Source local aliases
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

# Source private stuff
if [ -f ~/.bashrc_private ]; then
. ~/.bashrc_private
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

if [ "$TERM" == "xterm" ]; then
        export TERM=xterm-256color
fi

# some procmail stuff based on tutorial for setting up mutt and gmail
MAIL="/var/spool/mail/$USER" && export MAIL

eval "$(keychain --quiet --noask --eval )"

# GPG is dumb and won't prompt properly by default
GPG_TTY=$(tty)
export GPG_TTY
# hostnames list for command completion
HOSTFILE="$HOME/.hosts"

# Check for configuration file changes and bother me so I commit them
yadm_diff=$(yadm --no-pager diff --name-only --exit-code)
if [ $? -ne 0 ]; then
        echo -e "\e[1m\e[91m[yadm] \e[0m\e[92mThese config files have been modified:\e[39m"
    echo "$yadm_diff"
fi

# jump to switch ($2) in manpage ($1)
function mans() { man $1 | less -p "^ +$2"; }

#automatic logbook
# based on https://routley.io/tech/2017/11/23/logbook.html
# and http://edunham.net/2015/01/29/vim_open_file_with_cursor_at_the_end.html
# Disable 2021-12-10 (did not use, would switch to org markup if I did)
# function lb() {
#    vim "+normal Go" +startinsert ~"/logbook/$(date '+%Y-%m-%d').md"
#}

# autojump (learns common paths, use "j abbr" to jump to path)

if [[ -f /usr/share/autojump/autojump.bash ]]; then
    . /usr/share/autojump/autojump.bash
elif [[ -f /usr/local/share/autojump/autojump.bash ]]; then
    . /usr/local/share/autojump/autojump.bash
fi
Listing 2: ~/.bash_profile
# ~/.bash_profile: executed by bash(1) for login shells.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/login.defs
#umask 022

# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
fi


if [ -f "$HOME/.cargo/env" ]; then
    . "$HOME/.cargo/env"
fi

Aliases

Listing 3: ~/.bash_aliases
# no scientific notation, use radians
alias wcalc='wcalc -EE -r'

alias lmake='latexmk -interaction=nonstopmode -pdf -pvc -xelatex'

alias make='make -j `nproc`'

# fix import because gimp always confuses on the offset
alias import='import +repage'

# set for my canoscan 670u
alias scanimage-color='scanimage -y 279.4 -x 215.9 --batch --format=tiff --mode Color --resolution 300'
alias scanimage-gray='scanimage -y 279.4 -x 215.9 --batch --format=tiff --mode Gray --resolution 300'
alias scanimage-lineart='scanimage -y 279.4 -x 215.9 --batch --format=tiff --mode Lineart --resolution 300'
alias tiffcp-out='tiffcp -lzw out*.tif output.tif'

# give scheme readline support
alias scheme='rlwrap -f "$HOME"/.scheme_completion scheme'

# command to strip color codes from shell output
alias stripcolors='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"'

# always run vim as a server for remote management
alias vim='vim --servername "VIM"'

# print org agenda for the next 10 days
alias agenda="emacs --batch -l ~/.config/emacs/init.el -eval '(org-batch-agenda \"a\" org-agenda-span 10)' 2>/dev/null"

Hosts list

Used for completion of hostnames. 0.0.0.0 addresses are just placeholders. As far as I know nothing actually tries to resolve names to addresses based on this file.

Listing 4: ~/.hosts
# Set with  HOSTFILE  option  in  ~/.bashrc
0.0.0.0 hostname     hostname.domain
0.0.0.0 hostname2    hostname2.domain
0.0.0.0 public_host.com