Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Analyze shell history; zsh edition + alias expansion
480 git commit -v
397 git status -sb
120 git add -p
53 git push
52 git diff
47 noglob bundle exec
45 ls -G
45 git branch -v
45 bundle
39 git push -u
35 git rebase -i
34 bundle exec ruby
33 git pull
32 ruby -v
32 alias -Lr |
30 script/test
29 cd `coral path
29 bundle exec rspec
28 git log -p
25 git show
23 git push origin
21 sh ./apply.sh
21 script/test net_http
21 polyamory
20 vagrant provision
19 mvim
19 git reset --hard
19 git am -3
18 vagrant ssh
18 ruby -e 'p
setopt SH_WORD_SPLIT 2>/dev/null
_aliases="$(alias -Lr 2>/dev/null || alias)"
_history="$(history -10000 2>/dev/null || history)"
alias_for() {
[[ $1 =~ '[[:punct:]]' ]] && return
local found="$( echo "$_aliases" | sed -nE "/^alias ${1}='?(.+)/s//\\1/p" )"
[[ -n $found ]] && echo "${found%\'}"
}
_git_aliases="$(git config --get-regex 'alias\..*')"
git_alias_for() {
[[ $1 =~ '[[:punct:]]' ]] && return
echo "$_git_aliases" | sed -nE "/^alias.${1} ([^!].+)/s//\\1/p"
}
expand_command_line() {
shift
while [[ $1 =~ '=' ]]; do
shift
done
[[ $# -eq 0 ]] && return
local found_alias="$(alias_for $1)"
if [[ -n $found_alias ]]; then
shift
expand_command $found_alias "$@"
else
expand_command "$@"
fi
}
expand_command() {
if [[ ( $1 = git || $1 = hub ) && $# -gt 1 ]]; then
local found_git_alias="$(git_alias_for $2)"
if [[ -n $found_git_alias ]]; then
shift 2
expand_command git $found_alias "$@"
else
echo git $2 $3
fi
else
echo $1 $2 $3
fi
}
{ echo "$_history" | while read cmd; do
expand_command_line $cmd
done
} | sort | uniq -c | sort -k1 -rn | head -30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment