diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-08-08 21:37:29 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-08-08 22:10:00 -0500 |
commit | 419fdae5066a8a6bcac702805456214ddcb9afa1 (patch) | |
tree | 4863effa8cdbc00a80944984c23b5b9934106fa1 /bin/history_stats | |
parent | 2af64537f31dccb09da93bd648b35a3fa42dbe7d (diff) | |
download | conf-419fdae5066a8a6bcac702805456214ddcb9afa1.tar.gz conf-419fdae5066a8a6bcac702805456214ddcb9afa1.zip |
update this script for expanded zsh history files
Diffstat (limited to 'bin/history_stats')
-rwxr-xr-x | bin/history_stats | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bin/history_stats b/bin/history_stats index ec09a44..d0191ce 100755 --- a/bin/history_stats +++ b/bin/history_stats @@ -5,7 +5,9 @@ use warnings; use Getopt::Long; use Path::Class; -my $fh = dir($ENV{HOME})->file('.bash_history')->openr; +my $history_file = $ENV{SHELL} =~ m{/zsh} ? '.zsh_history' : '.bash_history'; + +my $fh = dir($ENV{HOME})->file($history_file)->openr; my $n = 10; my $subcommand; GetOptions( @@ -18,11 +20,16 @@ my %sudo_cmds; while (<$fh>) { chomp; + + # strip zsh history timestamps + s/^[^;]*;// if /^:/; + for my $cmd (split /;/, $_) { $cmd =~ s/^\s*(.*?)\s*$/$1/; my @words = split /\s+/, $cmd; next unless @words; - shift @words while $words[0] =~ /^[A-Z][A-Z0-9_]*=/; + shift @words while @words && $words[0] =~ /^[A-Z][A-Z0-9_]*=/; + next unless @words; my $sudo; if ($words[0] eq 'sudo') { $sudo = 1; |