Skip to content

Instantly share code, notes, and snippets.

@jcf
Forked from mislav/log.txt
Last active October 11, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcf/3866489 to your computer and use it in GitHub Desktop.
Save jcf/3866489 to your computer and use it in GitHub Desktop.
Analyze shell history; zsh edition + alias expansion
686 git commit -v
365 git commit -av
169 git checkout -b
160 git push -u
111 nocorrect mkdir -p
102 nocorrect rm -rf
89 nocorrect rm -r
88 git push -f
79 git branch -D
71 git push origin
61 git git l
43 bundle exec cucumber
36 git remote add
31 bundle exec rspec
28 echo "<a class='foo'
27 git status -sb
27 git add -A
21 git rebase -i
19 nocorrect heroku run
19 heroku run console
18 git reset --hard
17 git branch -M
17 gem search -r
16 knife cluster ssh
15 noglob find .
15 nocorrect heroku config:set
15 git push staging
15 cat ~/Downloads/Analytics Evently
14 noglob rake import:delete
14 nocorrect rm -fr
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