line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::GitGot::Command::mux; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENEHACK'; |
3
|
|
|
|
|
|
|
$App::GitGot::Command::mux::VERSION = '1.337'; |
4
|
|
|
|
|
|
|
# ABSTRACT: open a tmux window for a selected project |
5
|
15
|
|
|
15
|
|
9246
|
use 5.014; |
|
15
|
|
|
|
|
58
|
|
6
|
|
|
|
|
|
|
|
7
|
15
|
|
|
15
|
|
102
|
use IO::Prompt::Simple; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
1123
|
|
8
|
|
|
|
|
|
|
|
9
|
15
|
|
|
15
|
|
108
|
use App::GitGot -command; |
|
15
|
|
|
|
|
48
|
|
|
15
|
|
|
|
|
116
|
|
10
|
|
|
|
|
|
|
|
11
|
15
|
|
|
15
|
|
5268
|
use Moo; |
|
15
|
|
|
|
|
35
|
|
|
15
|
|
|
|
|
94
|
|
12
|
|
|
|
|
|
|
extends 'App::GitGot::Command'; |
13
|
15
|
|
|
15
|
|
4974
|
use namespace::autoclean; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
107
|
|
14
|
|
|
|
|
|
|
|
15
|
42
|
|
|
42
|
1
|
3570
|
sub command_names { qw/ mux tmux / } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub options { |
18
|
0
|
|
|
0
|
0
|
|
my( $class , $app ) = @_; |
19
|
|
|
|
|
|
|
return ( |
20
|
0
|
|
|
|
|
|
[ 'dirty|D' => 'open session or window for all dirty repos' ] , |
21
|
|
|
|
|
|
|
[ 'exec|e=s' => 'pass a command to the `tmux new-window` command (not valid in combination with -s option)'] , |
22
|
|
|
|
|
|
|
[ 'session|s' => 'use tmux-sessions (default: tmux windows)' ] , |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
|
|
sub _use_io_page { 0 } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _execute { |
29
|
0
|
|
|
0
|
|
|
my( $self, $opt, $args ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
0
|
|
|
|
die "-e and -s are mutually exclusive" |
32
|
|
|
|
|
|
|
if $self->opt->exec and $self->opt->session; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
my @repos = $self->opt->dirty ? $self->_get_dirty_repos() : $self->active_repos(); |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
my $target = $self->opt->session ? 'session' : 'window'; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if ( @repos >= 25 ) { |
39
|
0
|
|
|
|
|
|
my $repo_count = scalar @repos; |
40
|
|
|
|
|
|
|
return unless |
41
|
0
|
0
|
|
|
|
|
prompt( "\nYou're about to open $repo_count ${target}s - you sure about that? ", { yn => 1, default => 'n' } ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
REPO: foreach my $repo ( @repos ) { |
45
|
|
|
|
|
|
|
# is it already opened? |
46
|
0
|
|
|
|
|
|
my %windows = reverse map { /^(\d+):::(\S+)/ } |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
split "\n", `tmux list-$target -F"#I:::#W"`; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if( my $window = $windows{$repo->name} ) { |
50
|
0
|
0
|
|
|
|
|
if ($self->opt->session) { |
51
|
0
|
|
|
|
|
|
system 'tmux', 'switch-client', '-t' => $window; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
|
system 'tmux', 'select-window', '-t' => $window; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
next REPO; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
chdir $repo->path; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if ($self->opt->session) { |
62
|
0
|
|
|
|
|
|
delete local $ENV{TMUX}; |
63
|
0
|
|
|
|
|
|
system 'tmux', 'new-session', '-d', '-s', $repo->name; |
64
|
0
|
|
|
|
|
|
system 'tmux', 'switch-client', '-t' => $repo->name;} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
|
my @args = (qw/ tmux new-window -n / , $repo->name ); |
67
|
0
|
0
|
|
|
|
|
push( @args , $self->opt->exec ) if $self->opt->exec; |
68
|
0
|
|
|
|
|
|
system @args; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _get_dirty_repos { |
74
|
0
|
|
|
0
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my @dirty_repos; |
77
|
0
|
|
|
|
|
|
foreach my $repo ( @{ $self->full_repo_list } ) { |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $status = $repo->status(); |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
unless ( ref( $status )) { |
81
|
0
|
|
|
|
|
|
die "You need at least Git version 1.7 to use the --dirty flag.\n"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
push @dirty_repos , $repo |
85
|
|
|
|
|
|
|
if $status->is_dirty; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return @dirty_repos; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
## FIXME docs |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |