| 1 | package App::GitGot::Command::mux; | ||||||||||||||||||||||||||||
| 2 | 16 | our $AUTHORITY = 'cpan:GENEHACK'; | |||||||||||||||||||||||||||
| 3 | 16 | $App::GitGot::Command::mux::VERSION = '1.339'; | |||||||||||||||||||||||||||
| 4 | # ABSTRACT: open a tmux window for a selected project | ||||||||||||||||||||||||||||
| 5 | 16 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use IO::Prompt::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 16 | ▶ | use App::GitGot -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 16 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 16 | extends 'App::GitGot::Command'; | |||||||||||||||||||||||||||
| 13 | 16 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 42 | ▶ | sub command_names { qw/ mux tmux / } | ||||||||||||||||||||||||||
|
Subroutine
command_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub options { | ||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 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 | ▶ | sub _use_io_page { 0 } | ||||||||||||||||||||||||||
|
Subroutine
_use_io_page: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _execute { | ||||||||||||||||||||||||||
|
Subroutine
_execute: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 29 | 0 | my( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | die "-e and -s are mutually exclusive" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->opt->exec and $self->opt->session
MC/DC0%0/2
$self->opt->exec and $self->opt->session
$self->opt->exec
$self->opt->session
Truth table0%0/3
A and B
A= $self->opt->execB= $self->opt->session
| |||||||||||||||||||||||||||||
| 32 | if $self->opt->exec and $self->opt->session; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my @repos = $self->opt->dirty ? $self->_get_dirty_repos() : $self->active_repos(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $target = $self->opt->session ? 'session' : 'window'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( @repos >= 25 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | my $repo_count = scalar @repos; | |||||||||||||||||||||||||||
| 40 | return unless | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | prompt( "\nYou're about to open $repo_count ${target}s - you sure about that? ", { yn => 1, default => 'n' } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | REPO: foreach my $repo ( @repos ) { | |||||||||||||||||||||||||||
| 45 | # is it already opened? | ||||||||||||||||||||||||||||
| 46 | 0 | my %windows = reverse map { /^(\d+):::(\S+)/ } | |||||||||||||||||||||||||||
| 47 | split "\n", `tmux list-$target -F"#I:::#W"`; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if( my $window = $windows{$repo->name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($self->opt->session) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ($self->opt->session) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | push( @args , $self->opt->exec ) if $self->opt->exec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | system @args; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub _get_dirty_repos { | ||||||||||||||||||||||||||
|
Subroutine
_get_dirty_repos: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my @dirty_repos; | |||||||||||||||||||||||||||
| 77 | 0 | foreach my $repo ( @{ $self->full_repo_list } ) { | |||||||||||||||||||||||||||
| 78 | 0 | my $status = $repo->status(); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | unless ( ref( $status )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | die "You need at least Git version 1.7 to use the --dirty flag.\n"; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | push @dirty_repos , $repo | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | if $status->is_dirty; | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | return @dirty_repos; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 16 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | ## FIXME docs | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||