Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use File::Basename 'basename';
- sub get_cmds_shell_history()
- {
- # Call bash interactive mode and call history bash built-in
- my $get_cmds =
- qq/$ENV{'SHELL'} -i -c "history -r; history"/
- . q/ | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}'/;
- chomp(my @cmds = qx# $get_cmds #);
- my @cmds_separated;
- for (@cmds)
- {
- m/\||\|\||&&/ ?
- push @cmds_separated, # Considers to count
- map { my ($cmd) = split; {$cmd} } # commands between
- split m/\||\|\||&&/, # |, || and &&
- :
- push @cmds_separated, (split / /,$_)[0];
- }
- return @cmds_separated ? @cmds_separated : undef;
- }
- my %cmds_grouped;
- (m|/|) ? $cmds_grouped{ basename($_) }++ : $cmds_grouped{$_}++
- for (get_cmds_shell_history);
- # Popularity sorted decrease order
- # Format output with indented numbers
- printf("% 8d %s\n", $cmds_grouped{$_}, $_)
- for sort { $cmds_grouped{$b} <=> $cmds_grouped{$a} }
- keys %cmds_grouped;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement