zsh snippets

How to fix the iTerm keyboard bindings in OSX (readline configuration)

Tagged zsh, readline, keyboard, shortcuts  Languages bash

The keyboard bindings in iTerm on OSX Snow Leopard are fubar. To fix them either switch to Linux or put this in your zsh configuration:

bindkey "^r" history-incremental-search-backward
bindkey '^E' end-of-line
bindkey '^A' beginning-of-line
bindkey 'ƒ'  forward-word
bindkey '›'  backward-word
bindkey "^F" forward-char
bindkey "^B" backward-char
bindkey "^k" kill-line
bindkey "^u" backward-kill-line

How to get the latest version number from a list of git tags

Tagged bash, git, version, zsh  Languages bash

This will print the latest version number that a git repository has been tagged with:

$ git tag -l 'v*' | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tail -n 1

Note that some versions of the sort command have a —version-sort switch, and some don’t:

sort: unrecognized option `--version-sort'
Try `sort --help' for more information.

Search and replace file contents and file names

Tagged bash, find, replace, search, zsh  Languages bash

Search and replace file contents

# Replace Tree with Trees
# NOTE: If you want to backup the files, change -i '' to -i (without empty string)
grep -rl Tree . |xargs sed -i '' -e 's/Tree/Trees/'

Search and replace of file names

find . -name '*observation*' -exec bash -c 'mv $0 ${0/observation/condition}' {} \;

References https://www.commandlinefu.com/commands/matching/search-replace/c2VhcmNoIHJlcGxhY2U=/sort-by-votes