Private blog of Richard Wöber

A little collection of bash snippets, which I’m tired to search for every time I need them. I will add more on the future.

output/echo and exit in one step (useful for shorthand if):

the key is to have a space-character after/before the {/} and ; after the exit

[[ $1 =~ (foo|bar) ]] || { echo "Usage: $0 <foo|bar>" >&2; exit 1; }

use empty string in case statement:

case "$command" in
  "")        do_empty ;;
  foo)       do_foo ;;
  prefix*)   do_prefix ;;
  *)         do_default ;;

A little collection of seldom but useful snippets for git, often useful for scripting. I will add more on the future.


get current branch name

git rev-parse --abbrev-ref HEAD


get closest annotated tag ~~~ git describe –abbrev=0

get closest _annotated_ tag only when adressed directly

git describe –abbrev=0 –exact-match ~~~

get the lastest tagged commit in all branches:

git describe --tags `git rev-list --tags --max-count=1`

convert lightweight tag to annotated tag (this can be pushed without --force):

git tag -a -f <tagname> <tagname>

push all tags to a remote by default:

$ git config --add remote.origin.push '+refs/tags/*:refs/tags/*'

pull all tags from a remote by default:

git config remote.origin.tagopt --tags

As many others do, I put my basic unixoid dotfiles under Revision control and host them on Github, so they can easily be shared on the different machines I use from day to day.

Here’s a little snippet I use for my shell configuration to adress the settings on different systems. (I use zsh; adaption to other shells should be a no–brainer).

The basic file layout looks like:

… #other dotfiles

In zshenv.Darwin I put the enviroment variables for all of my OS X machines, e.g:

export NODE_PATH=/usr/local/lib/node_modules
export PGDATA=/usr/local/var/postgres
export PGUSER=postgres
export RBENV_ROOT=/usr/local/opt/rbenv

In zshrc.FreeBSD I put the configuration for login on FreeBSD machines:

export LSCOLORS="GxFxCxDxBxEgEdAbAgAcAd"
alias vi=vim

The *.Linux contains, like you already guessed, the Linux settings, the *.FreeBSD the settings for FreeBSD and so on. To get this key for your current machine, type uname -s.
(If you do not know the difference between .zshrc and .zshenv, here’s a short summary).

I also created a .local-version of each, in which I put things that only apply to the current machine (for example, the legacy CVSROOT environment variable on the company laptop).
Be sure to ignore them in git/your VCS!

I included them, by putting the following into the default configuration files:

# at the end of .zshenv
UNAME=$(uname -s)
[[ -f ~/.zsh/zshenv.${UNAME} ]] && source ~/.zsh/zshenv.${UNAME}
[[ -f ~/.zsh/zshenv.local ]] && source ~/.zsh/zshenv.local
# at the end of .zshrc
UNAME=$(uname -s)
[[ -f ~/.zsh/zshrc.${UNAME} ]] && source ~/.zsh/zshrc.${UNAME}
[[ -f ~/.zsh/zshrc.local ]] && source ~/.zsh/zshrc.local

Be sure to place these includes wisely, some other scripts might have special needs about the execution order (e.g. rbenv, which maniplulates the execution path to get things going).

You can, of course, enhance this further by including includes based your machine name (hostname) or any other funny thing (Beware! DCHP can change your hostname if not configured otherwise).
For me, the above is good enough.

After years of various attempts to get my own blog going, I finally took this site online. Hopefully this will encourage me to write some stuff ;-).

This time, I tried Octopress but as soon as I looked into the markup it produced, I wanted some things differently. I found middleman to be far more more my kind of doing things (especially the Wordpress inspired templating with header and footer in separate files and the ATOM Feed. So I worked the last two weekends to adapt and tune things a little to fit my needs; and — here it is.

Layout based, for now, on the the formidable Whitespace theme by Lucas Lew (on his part inspired by Alessandro Melandri).

Prepare for some changes over the next few weeks.