My molb home

Small collection of (maybe) useful tools

All programs are hosted on github!

Unix tips

uniq without loosing line order

awk '!seen[$0]++'
From Jonas Elfström. My old solution was nl -ba | sort -suk2 | sort -n | cut -f2-.

everlasting bash history

Put this in your ~/.bashrc:

# don't put duplicate lines or lines starting with space in the history
HISTCONTROL=ignoreboth

# everlasting history
HISTFILESIZE=
HISTSIZE=

# immediately append to history after every command, so that history
# is sorted chronologically when using multiple sessions
PROMPT_COMMAND="${PROMPT_COMMAND}${PROMPT_COMMAND:+;}history -a"

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

git: Show last three commits at the bottom of the commit message template

  1. Configure global git hooks directory:
    mkdir -p ~/.git/hooks
    git config --global core.hooksPath '~/.git/hooks'
  2. Save the following script as ~/.git/hooks/prepare-commit-msg:
    #!/bin/sh
    if [ -z "$2" ] ; then
        echo "# Recent relevant commits:" >> "$1"
        git diff --cached --name-only -z | xargs -r -0 git log -3 -- | sed -e 's/^/#\t/' -e 's/^#\t$/#/' >> "$1"
    fi