root/trunk/tools/shell

Revision 4196, 1.1 kB (checked in by takayama, 3 months ago)

* Set svn keywords

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