#!/usr/bin/env perl =pod =head1 NAME commandlog-add - log command line history and context to an sqlite db =head1 SYNOPSIS # in zsh function preexec { commandlog add "$@" } =head1 AUTHOR Brennen Bearnes =cut use warnings; use strict; use 5.10.0; use App::CommandLog; use Cwd; use Sys::Hostname; # Bail if logging is paused - can toggle this with commandlog-pause and # commandlog-resume: if (-e "$ENV{HOME}/commandlog-paused") { exit; } my $command = $ARGV[0]; my $expanded_command = $ARGV[2]; # Skip things prefixed with a space: if ($command =~ m/^[ ]+/) { exit; } my $dbh = App::CommandLog::get_dbh(); my $sth = $dbh->prepare(q{ INSERT INTO commands (command, expanded_command, path, hostname, username, shell, terminal, datetime) VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now')) }); $sth->execute($command, $expanded_command, cwd(), hostname(), $ENV{USER}, $ENV{SHELL}, $ENV{TERM});