Command-line history logging utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
804 B

  1. #!/usr/bin/env perl
  2. =pod
  3. =head1 NAME
  4. commandlog-add - log command line history and context to an sqlite db
  5. =head1 SYNOPSIS
  6. # in zsh
  7. function preexec {
  8. commandlog add "$@"
  9. }
  10. =head1 AUTHOR
  11. Brennen Bearnes <bbearnes@gmail.com>
  12. =cut
  13. use warnings;
  14. use strict;
  15. use 5.10.0;
  16. use App::CommandLog;
  17. use Cwd;
  18. use Sys::Hostname;
  19. my $command = $ARGV[0];
  20. my $expanded_command = $ARGV[2];
  21. # Skip things prefixed with a space:
  22. if ($command =~ m/^[ ]+/) {
  23. exit;
  24. }
  25. my $dbh = App::CommandLog::get_dbh();
  26. my $sth = $dbh->prepare(q{
  27. INSERT INTO commands (command, expanded_command, path, hostname, username, shell, terminal, datetime)
  28. VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'))
  29. });
  30. $sth->execute($command, $expanded_command, cwd(), hostname(), $ENV{USER}, $ENV{SHELL}, $ENV{TERM});