1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#!/usr/bin/perl -d
# This needs to load first on Centos for some reason
use Term::ReadLine;
use FindBin qw( $Bin );
use Cwd;
use lib map { Cwd::realpath("$Bin/../$_") } qw( extlib lib ../lib );
use constant HISTORY_FILE => $ENV{HOME} . '/.mt-phistory';
use vars qw( $mt $HAS_HISTORY );
use MT;
use MT::App::CMS;
BEGIN {
$DB::term || DB::setterm();
$HAS_HISTORY = $DB::term->can('GetHistory');
my @h;
if ($HAS_HISTORY) {
@h = $DB::term->GetHistory;
} else {
print STDERR "== Command history unavailable ==\n\n";
}
# Don't load history if we already have something (probably a db restart)
if ((scalar @h == 0) and $HAS_HISTORY) {
if (open H, '<', HISTORY_FILE()) {
chomp(my @h = <H>);
close H;
my %seen;
$DB::term->SetHistory(grep { /\S/ && !$seen{$_}++ } @h);
}
}
$mt = MT::App::CMS->new() or die MT->errstr;
}
END {
if ($HAS_HISTORY and open(H, '>', HISTORY_FILE())) {
my %seen;
print H join("\n", grep { /\S/ && !$seen{$_}++ } $DB::term->GetHistory);
close H;
}
}
1;
|