| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::VTide::Command::History; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2016-03-22 15:42:06 |
|
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
|
5
|
|
|
|
|
|
|
# $Id$ |
|
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
|
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1369
|
use Moo; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
10
|
1
|
|
|
1
|
|
2932
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
30
|
|
|
11
|
1
|
|
|
1
|
|
7
|
use version; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
11
|
|
|
12
|
1
|
|
|
1
|
|
77
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
62
|
|
|
13
|
1
|
|
|
1
|
|
9
|
use English qw/ -no_match_vars /; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
10
|
|
|
14
|
1
|
|
|
1
|
|
400
|
use YAML::Syck; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
640
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
extends 'App::VTide::Command::Run'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = version->new('1.0.5'); |
|
19
|
|
|
|
|
|
|
our $NAME = 'history'; |
|
20
|
|
|
|
|
|
|
our $OPTIONS = |
|
21
|
|
|
|
|
|
|
[ 'number|n=i', 'uniq|u', 'search|s=s', 'ignore|i=s', 'verbose|v+', ]; |
|
22
|
0
|
|
|
0
|
1
|
|
sub details_sub { return ( $NAME, $OPTIONS ) } |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub run { |
|
25
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
26
|
0
|
|
|
|
|
|
my @history; |
|
27
|
|
|
|
|
|
|
my %uniq; |
|
28
|
0
|
|
0
|
|
|
|
my $max = $self->defaults->{number} || 10; |
|
29
|
0
|
0
|
0
|
|
|
|
my $run_line = @ARGV && $ARGV[$#ARGV] =~ /^\d+$/ ? pop @ARGV : -1; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $fh = $self->config->history_file->openr; |
|
32
|
0
|
|
|
|
|
|
my $search = $self->defaults->{search}; |
|
33
|
0
|
|
|
|
|
|
my $ignore = $self->defaults->{ignore}; |
|
34
|
0
|
|
|
|
|
|
my $lineno = 0; |
|
35
|
0
|
|
|
|
|
|
while ( my $line = <$fh> ) { |
|
36
|
0
|
|
|
|
|
|
$lineno++; |
|
37
|
0
|
|
|
|
|
|
my ( $date, $command ) = $line =~ /^\[([^\]]+)\]\s+(.*?)\s+$/; |
|
38
|
0
|
0
|
|
|
|
|
next if !$command; |
|
39
|
|
|
|
|
|
|
next |
|
40
|
0
|
0
|
0
|
|
|
|
if $search |
|
41
|
|
|
|
|
|
|
&& $command !~ /$search/; |
|
42
|
|
|
|
|
|
|
next |
|
43
|
0
|
0
|
0
|
|
|
|
if $ignore |
|
44
|
|
|
|
|
|
|
&& $command =~ /$ignore/; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ( $lineno == $run_line ) { |
|
47
|
0
|
|
|
|
|
|
exec "vtide $command"; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
0
|
0
|
|
|
|
|
if ( $self->defaults->{uniq} ) { |
|
50
|
0
|
0
|
|
|
|
|
if ( defined $uniq{$command} ) { |
|
51
|
0
|
|
|
|
|
|
my $size = @history; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
@history = ( |
|
54
|
|
|
|
|
|
|
@history[ 0 .. ( $uniq{$command} - 1 ) ], |
|
55
|
0
|
|
|
|
|
|
@history[ ( $uniq{$command} + 1 ) .. $#history ] |
|
56
|
|
|
|
|
|
|
); |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( @history != $size - 1 ) { |
|
59
|
0
|
|
|
|
|
|
warn 'No change in history'; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
$uniq{$command} = scalar @history; |
|
63
|
0
|
|
|
|
|
|
push @history, [ $date, $lineno, $command ]; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
else { |
|
67
|
0
|
|
|
|
|
|
push @history, [ $date, $lineno, $command ]; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $max_line = length "$history[$#history][1]"; |
|
72
|
0
|
|
|
|
|
|
@history = ( ( reverse @history )[ 0 .. $max - 1 ] ); |
|
73
|
0
|
|
|
|
|
|
for my $item ( reverse @history ) { |
|
74
|
0
|
0
|
0
|
|
|
|
next if !$item || !@$item; |
|
75
|
0
|
|
|
|
|
|
printf "%-25s [%${max_line}d] vtide %s\n", @$item; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub auto_complete { |
|
82
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
App::VTide::Command::History - Tells you about the terminal you are in |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 VERSION |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This documentation refers to App::VTide::Command::History version 1.0.5 |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
vtide history [-f|--force] |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
OPTIONS |
|
102
|
|
|
|
|
|
|
-n (int) The maximum number of history sessions to show (Default 10) |
|
103
|
|
|
|
|
|
|
-i --ignore[=]regex |
|
104
|
|
|
|
|
|
|
Ignore results matching this regex |
|
105
|
|
|
|
|
|
|
-s search[=]regex |
|
106
|
|
|
|
|
|
|
Search for matches this regex |
|
107
|
|
|
|
|
|
|
-u --uniq Show only uniq results |
|
108
|
|
|
|
|
|
|
-v --verbose Show more detailed output |
|
109
|
|
|
|
|
|
|
--help Show this help |
|
110
|
|
|
|
|
|
|
--man Show the full man page |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head3 C<run ()> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Run the command |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 C<auto_complete ()> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Auto completes sub-commands that can have help shown |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 C<details_sub ()> |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns the commands details |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
There are no known bugs in this module. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Patches are welcome. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Copyright (c) 2016 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
|
151
|
|
|
|
|
|
|
All rights reserved. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
|
154
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
|
155
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|
156
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
|
157
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |