Advertisement
Guest User

Popular history

a guest
Jul 7th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.79 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. use File::Basename 'basename';
  6.  
  7. sub get_cmds_shell_history()
  8. {
  9.         # Call bash interactive mode and call history built-in
  10.         my $get_cmds =
  11.                 qq/$ENV{'SHELL'} -i -c "history -r; history"/
  12.                 .  q/ | awk '{ print $2 }'/
  13.                 .  q/ | awk -F\| '{ print $1 }'/; # Choice first pipe command
  14.  
  15.         chomp(my @cmds = qx# $get_cmds #);
  16.  
  17.         return @cmds ? @cmds : undef;
  18. }
  19.  
  20. my %cmds_grouped = ();
  21.  
  22. (m|/|) ? $cmds_grouped{ basename($_) }++ : $cmds_grouped{$_}++
  23.         for (get_cmds_shell_history);
  24.  
  25. # Popularity sorted decrease order
  26. printf("% 8d %s\n", $cmds_grouped{$_}, $_)
  27.          for sort { $cmds_grouped{$b} <=> $cmds_grouped{$a} }
  28.                  keys %cmds_grouped;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement