Chapter 6. Configure shells

Do these this now because we'll be using shells for the rest and it's annoying to use default configuration shells.

  1. Configure user shell

    Copy from Dropbox (except that we don't get Dropbox until Chapter 7, Obtain the encrypted cloud , so copy from source in the sidebar and maybe go back later to double-check.) cp ~/Dropbox/basic/new_machine/linux/config/.bash_aliases ~/Dropbox/Basic/new_machine/linux/config/.bashrc ~/ Or paste in emacs ~/.bash_aliases ~/.bashrc

    Note

    ~/.bashrc source

    # ~/.bashrc: executed by bash(1) for non-login shells.
    # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
    # for examples
    
    # If not running interactively, don't do anything
    case $- in
        *i*) ;;
          *) return;;
    esac
    
    # 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=1000
    HISTFILESIZE=2000
    
    # 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
    
    export LESSOPEN="| /usr/bin/lesspipe %s";
    export LESSCLOSE="/usr/bin/lesspipe %s %s";
    
    # 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|*-256color) color_prompt=yes;;
    esac
    
    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 [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    fi
    unset color_prompt force_color_prompt
    
    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|rxvt*)
        PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
    *)
        ;;
    esac
    
    # 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'
    fi
    
    if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
    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
    
    # HSTR configuration - add this to ~/.bashrc
    alias hh=hstr                    # hh to be alias for hstr
    export HSTR_CONFIG=hicolor       # get more colors
    shopt -s histappend              # append new history items to .bash_history
    export HISTCONTROL=ignorespace   # leading space hides commands from history
    export HISTFILESIZE=10000        # increase history file size (default is 500)
    export HISTSIZE=${HISTFILESIZE}  # increase history size (default is 500)
    # ensure synchronization between bash memory and history file
    export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
    function hstrnotiocsti {
        { READLINE_LINE="$( { </dev/tty hstr ${READLINE_LINE}; } 2>&1 1>&3 3>&- )"; } 3>&1;
        READLINE_POINT=${#READLINE_LINE}
    }
    # if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
    if [[ $- =~ .*i.* ]]; then bind -x '"\C-r": "hstrnotiocsti"'; fi
    export HSTR_TIOCSTI=n
    

    ~/.bash_aliases source

    # Emacs: -*- mode: bash-ts -*-
    
    # Package Management
    alias asslist='dpkg-query -L'        # list all files in package
    alias assstatus='dpkg -l | grep'     # list local status of all packages matching <string>
    alias ass='apt-cache search'         # Search repositories for <string>
    alias assinfo='apt-get show'         # Show package info for package named <string>
    alias assprovides='dpkg -S'          # Show all packages in repository that contain a filename that contains <string>
    alias assup="apt-get update && apt-get upgrade -y && apt-get autoremove -y && pkcon update"
    
    alias ..='cd ..'
    alias ...='cd ../../'
    alias ....='cd ../../../'
    alias .4='cd ../../../../'
    alias .5='cd ../../../../../'
    
    calc() {
      echo "scale=2; $1" | bc
    }
    
    compose() {
      grep --ignore-case $1 /usr/share/X11/locale/en_US.UTF-8/Compose 
    }
    
    alias cp='cp --interactive' # ask before clobbering
    
    alias df='duf'
    
    alias diff='delta'
    
    alias duh='dust --depth 1'
    alias duhh='dust --depth 2'
    
    alias e='emacs'
    alias elast='emacs $(!!)'
    alias eg='env | grep '
    
    alias gq='geeqie'
    
    alias grep='rg -S'
    alias grep1='rg -S --max-depth=1'
    alias grepnoc='rg ^[^#]' 
    
    alias h=history
    alias hig='history | grep '
    
    alias man='man --pager="less -FX"'
    alias less='less --quit-if-one-screen --no-init'
    alias more='less'
    
    alias exa='exa   --all --binary --changed --group --header --long --time-style=long-iso --tree'
    alias l='exa     --level=1 --sort=changed'
    alias ll='exa    --level=2 --sort=changed'
    alias lll='exa   --level=3 --sort=changed'
    alias llll='exa  --tree --level=4 --sort=changed'
    alias lss='exa   --level=1 --sort=size'
    alias lnn='exa   --level=1 --sort=name'
    
    alias ld="l ~/Downloads/"
    
    # if exa isn't installed:
    #alias l=ls\ -alrt\ --block-size="\'1"
    #alias lss=ls\ -alrS\ --block-size="\'1"
    #alias lnn=ls\ -aln\ --block-size="\'1"
    
    alias m='mpv --fs --osd-level=0'
    alias mkdir='mkdir --parents'
    alias mountt='mount |column -t'
    alias mv='mv --interactive'
    
    
    # quick local network scan
    alias nmap24='sudo nmap -sn -oX nmap_sn.csv 192.168.1.1/24 | awk '\''/Nmap scan report/ {print "\n" $0; next} 1'\'
    
    # full port scan for one address
    # just use nmap <address>
    
    # Maybe these can be done better with procs but not trivially, and these work already
    alias pf='ps auxf' 
    alias pg='ps aux | grep'
    
    # procs isn't backwards-compatible with ps, so don't use it as such.
    alias prf='procs --tree'
    alias prg='procs --tree | rg'
    
    tjoin() {
        tmux a -t ${1}
    RESULT=$?
    if [ $RESULT -ne 0  ]; then
        echo "No existing tmux named ${1}"
        tmux new-session -s ${1}
    fi
    }
    
    alias tx='tar xzvf'   # gzip
    alias tj='tar xjvf'   # bzip2
    alias tJ='tar xJvf'   # xz
    
    woo() {
      whois "$1" | grep Creation
    }
    
    ju() {
      journalctl --user --follow --unit=$1
    }
    
  2. Repeat for root and skel

    sudo cp ~/.bash_aliases ~/.bashrc /root/

    Repeat for skel, which is the template for new users. sudo cp ~/.bash_aliases ~/.bashrc /etc/skel/

  3. Install hstr

    TODO