Command history meme

This is an old meme, but I never got around to do it. However, I didn’t want to do it with partial history.

So, I came up with this little piece of code that stores each and every command, and also the location where it was executed.

zshaddhistory() {
	print -r -- "${1%%$'\n'} ### ${PWD}" >> ~/.histstat || true

I have been running this for four months.

cat ~/.histstat | awk '{a[$1]++} END{for(i in a){printf "%5d\t%s\n",a[i],i}}' | sort -rn | head
40432	git
13266	ls
11356	gvim
 8615	cd
 7425	make
 5952	gitk
 3271	scp
 1639	ssh
 1593	rm
 1568	sudo

But my end goal is to analyse the actual commands I usually type.

1188	git clean -fxd
1228	mbsync -a && nmm-poll
1345	ssh d
1776	cd ..
2787	make
2882	git show
3437	gitk
3823	git br
4226	git diff
11250	ls

Clearly I need to make some aliases, starting with g=git.

Update: Based on the analysis I decided to make these changes:

Ignore these commands:

HISTIGNORE="ls:[bf]g:exit:reset:clear:cd *"

Since I run ‘git branch’ so much, I decided to put the current branch in my prompt:

PS1='%m:%~$(__git_ps1 "[%%F{5}%s%%f]")%# '
setopt prompt_subst

Plus zsh has a nice option to automatically cd to a directory, if what you type is a directory, like ‘/tmp’ instead of ‘cd /tmp’:

setopt auto_cd

Plus obvious git stuff:

alias g=git

function gk()
	gitk $* &

And corresponding git aliases:

	s = show
	c = commit
	r = reset
	d = describe --tags
        b = branch

And add some directory shortcuts:

hash -d milaatu=/private/dev/maemo/milaatu
hash -d linux-n900=/data/dev/omap/linux-n900
hash -d mma-video-test=/private/dev/maemo/mma-video-test
hash -d gst-dsp=/private/dev/maemo/gst-dsp

One thought on “Command history meme

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s