File: shell

package info (click to toggle)
movabletype-opensource 5.1.4%2Bdfsg-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,996 kB
  • sloc: perl: 197,285; php: 62,405; sh: 166; xml: 117; makefile: 83; sql: 32
file content (50 lines) | stat: -rwxr-xr-x 1,132 bytes parent folder | download
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;