|
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 |
|---|
| 4 | use Term::ReadLine; |
|---|
| 5 | |
|---|
| 6 | use FindBin qw( $Bin ); |
|---|
| 7 | use Cwd; |
|---|
| 8 | use lib map { Cwd::realpath("$Bin/../$_") } qw( extlib lib ../lib ); |
|---|
| 9 | |
|---|
| 10 | use constant HISTORY_FILE => $ENV{HOME} . '/.mt-phistory'; |
|---|
| 11 | |
|---|
| 12 | use vars qw( $mt $HAS_HISTORY ); |
|---|
| 13 | |
|---|
| 14 | use MT; |
|---|
| 15 | use MT::App::CMS; |
|---|
| 16 | |
|---|
| 17 | BEGIN { |
|---|
| 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 | |
|---|
| 41 | END { |
|---|
| 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 | |
|---|
| 49 | 1; |
|---|
| 50 | |
|---|