line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::VTide::Command::Sessions; |
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
|
|
958
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
2366
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
4
|
use version; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
57
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
13
|
1
|
|
|
1
|
|
6
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
14
|
1
|
|
|
1
|
|
344
|
use YAML::Syck qw/ DumpFile LoadFile /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
96
|
|
15
|
1
|
|
|
1
|
|
7
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
16
|
1
|
|
|
1
|
|
26
|
use Data::Dumper qw/Dumper/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1436
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
extends 'App::VTide::Command::Run'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = version->new('0.1.16'); |
21
|
|
|
|
|
|
|
our $NAME = 'sessions'; |
22
|
|
|
|
|
|
|
our $OPTIONS = [ |
23
|
|
|
|
|
|
|
'dest|d=s', 'global|g', 'session|source|s=s', 'verbose|v+', |
24
|
|
|
|
|
|
|
'update|u!', 'test|t!' |
25
|
|
|
|
|
|
|
]; |
26
|
0
|
|
|
0
|
1
|
|
sub details_sub { return ( $NAME, $OPTIONS ) } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has global => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
lazy => 1, |
31
|
|
|
|
|
|
|
default => sub { |
32
|
|
|
|
|
|
|
$_[0]->options->opt->{global} || !$ENV{VTIDE_NAME}; |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub run { |
37
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
0
|
|
|
|
$self->options->opt->{update} //= 1; |
40
|
0
|
|
0
|
|
|
|
$self->options->opt->{session} ||= 'current'; |
41
|
0
|
|
|
|
|
|
my $local = !$self->global; |
42
|
0
|
|
0
|
|
|
|
my $command = 'session_' . ( shift @{ $self->options->files } || 'list' ); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if ( !$self->can($command) ) { |
45
|
0
|
|
|
|
|
|
warn "Unknown command $command!\n"; |
46
|
0
|
|
|
|
|
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
my $base = $local ? $self->config->local_base : $self->config->global_base; |
50
|
0
|
|
|
|
|
|
my $session_file = path( $base, 'sessions.yml' ); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self->$command($session_file); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub session_list { |
58
|
0
|
|
|
0
|
0
|
|
my ( $self, $session_file ) = @_; |
59
|
0
|
|
|
|
|
|
my $name = $self->options->opt->{session}; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if ( !-f $session_file ) { |
62
|
0
|
|
|
|
|
|
warn "No sessions\n"; |
63
|
0
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $session = LoadFile($session_file); |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ( $self->options->opt->{verbose} ) { |
69
|
0
|
|
|
|
|
|
print "Sessions:\n"; |
70
|
0
|
|
|
|
|
|
for my $name ( sort keys %$session ) { |
71
|
0
|
|
|
|
|
|
print " $name\n"; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
print "\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
print "$name:\n"; |
77
|
0
|
0
|
|
|
|
|
if ( $session->{$name} ) { |
78
|
0
|
0
|
|
|
|
|
my $cmd = "vtide session" |
79
|
|
|
|
|
|
|
. ( |
80
|
|
|
|
|
|
|
$name eq 'current' |
81
|
|
|
|
|
|
|
? '' |
82
|
|
|
|
|
|
|
: " --session $name" |
83
|
|
|
|
|
|
|
); |
84
|
0
|
|
|
|
|
|
for my $i ( 0 ... @{ $session->{$name} } - 2 ) { |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $files = $session->{$name}[$i]; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
print " ", ( join " ", @$files ), "\n"; |
88
|
0
|
0
|
|
|
|
|
if ( $i == 0 ) { |
|
|
0
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
print " ('$cmd shift' to run)\n"; |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
elsif ( $i == @{ $session->{$name} } - 2 ) { |
92
|
0
|
|
|
|
|
|
print " ('$cmd pop' to run)\n"; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
0
|
|
|
|
|
|
print " Empty\n"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub session_unshift { |
102
|
0
|
|
|
0
|
0
|
|
my ( $self, $session_file ) = @_; |
103
|
|
|
|
|
|
|
return $self->modify_session( |
104
|
|
|
|
|
|
|
$session_file, |
105
|
|
|
|
|
|
|
sub { |
106
|
0
|
|
|
0
|
|
|
unshift @{ $_[0] }, $self->options->files; |
|
0
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub session_push { |
114
|
0
|
|
|
0
|
0
|
|
my ( $self, $session_file ) = @_; |
115
|
|
|
|
|
|
|
return $self->modify_session( |
116
|
|
|
|
|
|
|
$session_file, |
117
|
|
|
|
|
|
|
sub { |
118
|
0
|
|
|
0
|
|
|
push @{ $_[0] }, $self->options->files; |
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub session_shift { |
126
|
0
|
|
|
0
|
0
|
|
my ( $self, $session_file ) = @_; |
127
|
|
|
|
|
|
|
return $self->modify_session( |
128
|
|
|
|
|
|
|
$session_file, |
129
|
|
|
|
|
|
|
sub { |
130
|
0
|
|
|
0
|
|
|
my ($session) = @_; |
131
|
0
|
|
|
|
|
|
return shift @$session; |
132
|
|
|
|
|
|
|
} |
133
|
0
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub session_pop { |
137
|
0
|
|
|
0
|
0
|
|
my ( $self, $session_file ) = @_; |
138
|
|
|
|
|
|
|
return $self->modify_session( |
139
|
|
|
|
|
|
|
$session_file, |
140
|
|
|
|
|
|
|
sub { |
141
|
0
|
|
|
0
|
|
|
my ($session) = @_; |
142
|
0
|
|
|
|
|
|
return pop @$session; |
143
|
|
|
|
|
|
|
} |
144
|
0
|
|
|
|
|
|
); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub modify_session { |
148
|
0
|
|
|
0
|
0
|
|
my ( $self, $session_file, $modify ) = @_; |
149
|
0
|
|
|
|
|
|
my $name = $self->options->opt->{session}; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
my $session = -f $session_file ? LoadFile($session_file) : {}; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $files = $modify->( $session->{$name} ); |
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
if ( !@{ $session->{$name} } ) { |
|
0
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
delete $session->{$name}; |
157
|
0
|
|
|
|
|
|
warn "Empty session removed!\n"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# TODO work out why update unset with --no-update |
161
|
|
|
|
|
|
|
# write the new session out |
162
|
0
|
0
|
|
|
|
|
if ( $self->options->opt->update ) { |
163
|
0
|
|
|
|
|
|
DumpFile $session_file, $session; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
if ( !$files ) { |
167
|
0
|
|
|
|
|
|
$self->session_list($session_file); |
168
|
0
|
|
|
|
|
|
return; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
my $action = $self->global ? "start" : "edit"; |
172
|
0
|
|
|
|
|
|
system 'vtide', $action, @$files; |
173
|
0
|
|
|
|
|
|
warn join ' ', 'vtide', $action, @$files; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub session_copy { |
177
|
0
|
|
|
0
|
0
|
|
my ( $self, $session_file ) = @_; |
178
|
0
|
|
|
|
|
|
my $name = $self->options->opt->{session}; |
179
|
0
|
|
|
|
|
|
my $dest = $self->options->opt->{dest}; |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
my $session = -f $session_file ? LoadFile($session_file) : {}; |
182
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
if ( !$dest ) { |
184
|
0
|
|
|
|
|
|
warn "No destination name!"; |
185
|
0
|
|
|
|
|
|
return; |
186
|
|
|
|
|
|
|
} |
187
|
0
|
|
|
|
|
|
$session->{$dest} = [ map { [@$_] } @{ $session->{$name} } ]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
DumpFile $session_file, $session; |
190
|
0
|
|
|
|
|
|
$self->session_list($session_file); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub auto_complete { |
194
|
0
|
|
|
0
|
1
|
|
my ( $self, $auto ) = @_; |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
0
|
|
|
|
my $partial = $ARGV[ $auto - 1 ] || ''; |
197
|
0
|
|
|
|
|
|
print join ' ', grep { /^$partial/ } qw/ |
|
0
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
copy |
199
|
|
|
|
|
|
|
list |
200
|
|
|
|
|
|
|
pop |
201
|
|
|
|
|
|
|
push |
202
|
|
|
|
|
|
|
shift |
203
|
|
|
|
|
|
|
unshift |
204
|
|
|
|
|
|
|
/; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
__END__ |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 NAME |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
App::VTide::Command::Sessions - Create/Update/List saved vtide sessions |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 VERSION |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This documentation refers to App::VTide::Command::Sessions version 0.1.16 |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 SYNOPSIS |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
vtide sessions [list] [(-s|--session) name] [-g|--global] [-v|--verbose] |
222
|
|
|
|
|
|
|
vtide sessions unshift [(-s|--session) name] [-g|--global] [--no-update] [-v|--verbose] |
223
|
|
|
|
|
|
|
vtide sessions push [(-s|--session) name] [-g|--global] [--no-update] [-v|--verbose] |
224
|
|
|
|
|
|
|
vtide sessions shift [(-s|--session) name] [-g|--global] [--no-update] [-v|--verbose] |
225
|
|
|
|
|
|
|
vtide sessions pop [(-s|--session) name] [-g|--global] [--no-update] [-v|--verbose] |
226
|
|
|
|
|
|
|
vtide sessions copy (-s|--source) source_session [-d|--destination] destination_session [-g|--global] [-v|--verbose] |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
OPTIONS |
229
|
|
|
|
|
|
|
-g --global Look at the global sessions when in side a vtide managed terminal |
230
|
|
|
|
|
|
|
-s --session[=]name |
231
|
|
|
|
|
|
|
Look at or modify this session (Default current) |
232
|
|
|
|
|
|
|
-s --source[=]name |
233
|
|
|
|
|
|
|
Copy this session |
234
|
|
|
|
|
|
|
-d --dest[=]name |
235
|
|
|
|
|
|
|
Replace/add this session |
236
|
|
|
|
|
|
|
-u --update Update sessions (default) |
237
|
|
|
|
|
|
|
--no-update Don't update sessions |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
-v --verbose Show more detailed output |
240
|
|
|
|
|
|
|
--help Show this help |
241
|
|
|
|
|
|
|
--man Show the full man page |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 DESCRIPTION |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head3 C<run ()> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Run the command |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head2 C<auto_complete ()> |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Auto completes sub-commands that can have help shown |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head2 C<details_sub ()> |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Returns the commands details |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
There are no known bugs in this module. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Patches are welcome. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 AUTHOR |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Copyright (c) 2016 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
282
|
|
|
|
|
|
|
All rights reserved. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
285
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
286
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
287
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
288
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=cut |