| 1 | package App::VTide::Command::Start; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Created on: 2016-01-30 15:06:48 | ||||||||||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::chdir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use YAML::Syck; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use App::VTide::Sessions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | extends 'App::VTide::Command'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | our $VERSION = version->new('1.0.6'); | |||||||||||||||||||||||||||
| 22 | 1 | our $NAME = 'start'; | |||||||||||||||||||||||||||
| 23 | 1 | our $OPTIONS = | |||||||||||||||||||||||||||
| 24 | [ 'windows|w=i', 'add|add-to-session|a', 'test|T!', 'verbose|v+', ]; | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub details_sub { return ( $NAME, $OPTIONS ) } | ||||||||||||||||||||||||||
|
Subroutine
details_sub: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | has sessions => ( | ||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | lazy => 1, | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 31 | App::VTide::Sessions->new( | ||||||||||||||||||||||||||||
| 32 | sessions_file => path $ENV{HOME}, | ||||||||||||||||||||||||||||
| 33 | 0 | '.vtide/sessions.yml' | |||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||
| 36 | 1 | ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my ( $name, $dir ) = $self->session_dir( $self->options->files->[0] ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | local $CWD = $dir; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $self->save_session( $name, $dir ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | $self->hooks->run( 'start_pre', $name, $dir ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | $self->ctags(); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( $self->options->default->{add} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | $self->sessions->add_session($name); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return $self->tmux( $self->vtide->config->data->{title} || $name, $name ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->vtide->config->data->{'title'} || $name
MC/DC0%0/2
$self->vtide->config->data->{'title'} || $name
$self->vtide->config->data->{'title'}
$name
Truth table0%0/3
A || B
A= $self->vtide->config->data->{'title'}B= $name
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub ctags { | ||||||||||||||||||||||||||
|
Subroutine
ctags: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 60 | 0 | my $ctags = path( '/usr', 'bin', 'ctags' ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return if !$self->config->get->{start}{ctags} || !-x $ctags; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->config->get->{"start"}{"ctags"} and -x $ctags
MC/DC0%0/2
$self->config->get->{"start"}{"ctags"} and -x $ctags
$self->config->get->{"start"}{"ctags"}
-x $ctags
Truth table0%0/3
A and B
A= $self->config->get->{"start"}{"ctags"}B= -x $ctags
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my @cmd = ( $ctags, $self->config->get->{start}{ctags} ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | for my $exclude ( @{ $self->config->get->{start}{"ctags-exclude"} } ) { | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $self->config->get->{start}{"ctags-excludes"}{$exclude} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | push @cmd, | ||||||||||||||||||||||||||||
| 69 | 0 | map { "--exclude=$_" } | |||||||||||||||||||||||||||
| 70 | 0 | @{ $self->config->get->{start}{"ctags-excludes"}{$exclude} }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | push @cmd, "--exclude=$exclude"; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | system @cmd; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub tmux { | ||||||||||||||||||||||||||
|
Subroutine
tmux: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, $title, $name ) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | print "\033];$title\007"; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | eval { require Term::Title; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | and Term::Title::set_titlebar($title); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my %session = map { /(^[^:]+)/xms; $1 => 1 } `tmux ls`; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ( $session{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # reconnect | ||||||||||||||||||||||||||||
| 91 | 0 | exec 'tmux', 'attach-session', '-t', $name; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $v = $self->defaults->{verbose} ? '--verbose' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | $v .= " --name $name"; | |||||||||||||||||||||||||||
| 96 | 0 | my $tmux = 'tmux -u2 '; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $count = $self->defaults->{windows} || $self->config->get->{count}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->defaults->{'windows'} || $self->config->get->{'count'}
MC/DC0%0/2
$self->defaults->{'windows'} || $self->config->get->{'count'}
$self->defaults->{'windows'}
$self->config->get->{'count'}
Truth table0%0/3
A || B
A= $self->defaults->{'windows'}B= $self->config->get->{'count'}
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | for my $window ( 1 .. $count ) { | |||||||||||||||||||||||||||
| 100 | 0 | $tmux .= $self->tmux_window( $window, "vtide run $v", $name ); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | $tmux .= "select-window -t 1"; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ( $self->defaults->{test} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | print "$tmux\n"; | |||||||||||||||||||||||||||
| 106 | 0 | return 1; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | mkdir '.vtide' if !-d '.vtide'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | my $fh = path( '.vtide', 'start.log' )->opena; | |||||||||||||||||||||||||||
| 111 | 0 | print {$fh} '[' . localtime . "] START TMUX $tmux\n"; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | system $tmux; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | print {$fh} '[' . localtime . "] END TMUX $tmux\n"; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub tmux_window { | ||||||||||||||||||||||||||
|
Subroutine
tmux_window: not called CC=21 SCAR=61.4
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 0 | my ( $self, $term, $cmd, $name, $split ) = @_; | |||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $conf = !$term ? {} : $self->config->get->{terminals}{$term}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my $out = | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 122 | $split ? '' | ||||||||||||||||||||||||||||
| 123 | : $term == 1 ? "new-session -s $name '$cmd $term' \\; " | ||||||||||||||||||||||||||||
| 124 | : "new-window '$cmd $term' \\; "; | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $letter = !$term ? '' : 'a'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( !$conf || ref $conf ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $conf or ref $conf ne "HASH"
MC/DC0%0/2
not $conf or ref $conf ne "HASH"
not $conf
ref $conf ne "HASH"
Truth table0%0/3
not(A) or B
A= not $confB= ref $conf ne "HASH"
| |||||||||||||||||||||||||||||
| 128 | 0 | $conf = {}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $term ||= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$term ||= ""
MC/DC0%0/1
$term ||= ""
$term
Truth table0%0/2
A
A= $term
| |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $split ||= $conf->{split}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$split ||= $conf->{"split"}
MC/DC0%0/2
$split ||= $conf->{"split"}
$split
$conf->{"split"}
Truth table0%0/3
A ||= B
A= $splitB= $conf->{"split"}
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | for my $split ( split //xms, ( $split || '' ) ) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$split || ''
MC/DC0%0/1
$split || ''
$split
Truth table0%0/2
A
A= $split
| |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | next if !defined $split || $split eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $split or $split eq ""
MC/DC0%0/2
not defined $split or $split eq ""
not defined $split
$split eq ""
Truth table0%0/3
not(A) or B
A= not defined $splitB= $split eq ""
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my $arg = | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 138 | $split eq 'H' ? 'split-window -h' | ||||||||||||||||||||||||||||
| 139 | : $split eq 'h' ? 'split-window -dh' | ||||||||||||||||||||||||||||
| 140 | : $split eq 'V' ? 'split-window -v' | ||||||||||||||||||||||||||||
| 141 | : $split eq 'v' ? 'split-window -dv' | ||||||||||||||||||||||||||||
| 142 | : $split =~ /^\d$/x ? 'select-pane -t ' . $split | ||||||||||||||||||||||||||||
| 143 | : die "Unknown split for terminal $term $split (split = '$split')!\n"; | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | $out .= | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | $split =~ /^\d$/xms ? "$arg \\; " : "$arg '$cmd $term$letter' \\; "; | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $letter++ if $letter; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ( $conf->{tmux} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | $out .= "$conf->{tmux} \\; "; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | return $out; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub auto_complete { | ||||||||||||||||||||||||||
|
Subroutine
auto_complete: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | my $file = $self->history; | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $sessions = eval { LoadFile($file) } || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
LoadFile($file)
}
} || {}
MC/DC0%0/1
eval {
do {
LoadFile($file)
}
} || {}
eval {
do {
LoadFile($file)
}
}
Truth table0%0/2
A
A= eval {
do {
LoadFile($file)
}
}
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | my $env = $self->options->files->[-1]; | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | print join ' ', grep { $env ne 'start' ? /^$env/xms : 1 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | sort keys %{ $sessions->{sessions} }; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | return; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | 1; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | __END__ | ||||||||||||||||||||||||||||