line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::VTide::Command::Edit; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2016-02-05 10:11:54 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
962
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
2450
|
use warnings; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
27
|
|
11
|
1
|
|
|
1
|
|
4
|
use version; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
56
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
13
|
1
|
|
|
1
|
|
5
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
14
|
1
|
|
|
1
|
|
339
|
use File::chdir; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
98
|
|
15
|
1
|
|
|
1
|
|
8
|
use Data::Dumper qw/Dumper/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
16
|
1
|
|
|
1
|
|
445
|
use App::VTide::Sessions; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
801
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
extends 'App::VTide::Command::Run'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = version->new('1.0.2'); |
21
|
|
|
|
|
|
|
our $NAME = 'edit'; |
22
|
|
|
|
|
|
|
our $OPTIONS = |
23
|
|
|
|
|
|
|
[ 'add|add-to-session|a', 'recurse|r!', 'test|T!', 'save|s=s', 'verbose|v+', |
24
|
|
|
|
|
|
|
]; |
25
|
|
|
|
|
|
|
our $LOCAL = 1; |
26
|
0
|
|
|
0
|
1
|
|
sub details_sub { return ( $NAME, $OPTIONS, $LOCAL ) } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has sessions => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
lazy => 1, |
31
|
|
|
|
|
|
|
default => sub { |
32
|
|
|
|
|
|
|
App::VTide::Sessions->new(); |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub run { |
37
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my ($name) = $self->env; |
40
|
0
|
|
|
|
|
|
my $cmd = $self->options->files->[0]; |
41
|
0
|
|
|
|
|
|
print "Running $name - $cmd\n"; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ( $self->defaults->{add} ) { |
44
|
0
|
|
|
|
|
|
$self->sessions->add_session( @{ $self->options->files } ); |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $params = $self->params($cmd); |
48
|
0
|
|
|
|
|
|
$params->{edit} = $self->options->files; |
49
|
0
|
|
|
|
|
|
$params->{title} = $cmd; |
50
|
0
|
|
|
|
|
|
$self->base($CWD); |
51
|
0
|
|
|
|
|
|
my @cmd = $self->command( $params, $self->defaults->{recurse} ); |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
0
|
|
|
|
if ( $params->{env} && ref $params->{env} eq 'HASH' ) { |
54
|
0
|
|
|
|
|
|
for my $env ( keys %{ $params->{env} } ) { |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $orig = $ENV{$env}; |
56
|
0
|
|
|
|
|
|
$ENV{$env} = $params->{env}{$env}; |
57
|
0
|
|
|
|
|
|
$ENV{$env} =~ s/[\$]$env/$orig/xms; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$self->load_env( $params->{env} ); |
62
|
0
|
|
|
|
|
|
$self->hooks->run( 'edit_editing', \@cmd ); |
63
|
0
|
|
|
|
|
|
$self->runit(@cmd); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
0
|
|
|
|
$params = $self->params( $ENV{VTIDE_TERM} || '1' ); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
0
|
|
|
|
my $title = $params->{title} || 'bash'; |
68
|
0
|
|
|
|
|
|
my $max = 15; |
69
|
0
|
0
|
|
|
|
|
if ( length $title > $max ) { |
70
|
0
|
|
|
|
|
|
$title = substr $title, ( length $title ) - $max, $max + 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
eval { require Term::Title; } |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
and Term::Title::set_titlebar($title); |
75
|
0
|
|
|
|
|
|
system 'tmux', 'rename-window', $title; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub auto_complete { |
81
|
0
|
|
|
0
|
1
|
|
my ( $self, $auto ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $env = $self->options->files->[-1]; |
84
|
0
|
|
|
|
|
|
my @files = sort keys %{ $self->config->get->{editor}{files} }; |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
eval { |
87
|
0
|
|
|
|
|
|
my $helper = $self->config->get->{editor}{helper_autocomplete}; |
88
|
0
|
0
|
|
|
|
|
if ($helper) { |
89
|
0
|
|
|
|
|
|
my $helper_sub = eval $helper; ## no critic |
90
|
0
|
0
|
|
|
|
|
if ($helper_sub) { |
|
|
0
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
push @files, $helper_sub->( $auto, $self->options->files ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ($@) { |
94
|
0
|
|
|
|
|
|
warn "Errored parsing '$@':\n$helper\n"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
0
|
|
|
|
|
|
warn "Unknown error with helper sub\n"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
1; |
101
|
0
|
0
|
|
|
|
|
} or do { warn $@ }; |
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
print join ' ', |
104
|
0
|
0
|
0
|
|
|
|
grep { $env ne 'vtide' && $env ne 'edit' ? /^$env/xms : 1 } @files; |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
App::VTide::Command::Edit - Run an edit command (like Run but without a terminal spec) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This documentation refers to App::VTide::Command::Edit version 1.0.2 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
vtide edit (glob ...) |
124
|
|
|
|
|
|
|
vtide edit [--help|--man] |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
OPTIONS: |
127
|
|
|
|
|
|
|
-r --recurse Recurse through directories to find files |
128
|
|
|
|
|
|
|
--no-recurese Don't recurse throught directories |
129
|
|
|
|
|
|
|
-s --save[=]name Save edit options |
130
|
|
|
|
|
|
|
-T --test Test the running of the terminal (shows the commands |
131
|
|
|
|
|
|
|
that would be executed) |
132
|
|
|
|
|
|
|
-v --verbose Show more verbose output. |
133
|
|
|
|
|
|
|
--help Show this help |
134
|
|
|
|
|
|
|
--man Show full documentation |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 DESCRIPTION |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
The C<edit> command allows an ad hoc access to starting the editor with lists |
139
|
|
|
|
|
|
|
of files, file groups or globs. The file groups are those defined in the |
140
|
|
|
|
|
|
|
local C<.vtide.yml> config (as defined in L<App::VTide::Configuration/editor>). |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 C<run ()> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Run an editor command with passed in file globs |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 C<auto_complete ()> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Auto completes editor file groups |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 C<details_sub ()> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Returns the commands details. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 HOOKS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 C<edit_editing ($cmd)> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Called just before execution, the command that will be executed is |
161
|
|
|
|
|
|
|
passed and can be modified. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
There are no known bugs in this module. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Patches are welcome. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHOR |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Copyright (c) 2016 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
186
|
|
|
|
|
|
|
All rights reserved. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
189
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
190
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
191
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
192
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |