summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/history_stats11
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;