$ curl -L https://gist.githubusercontent.com/mamemomonga/6a1e7a871869ed73ca845c789dced6f5/raw/cd19e1b5555480a29ce73bdd679a11b5eca2f2f4/tmux-open-pwd > tmux-open-pwd
$ chmod 755 tmux-open-pwd
1つ開く
$ ./tmux-open-pwd
3つ開く
$ ./tmux-open-pwd 3
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use feature 'say'; | |
| use Cwd qw(getcwd); | |
| use Data::Dumper; | |
| my $popup_delay=2; # ポップアップの表示時間 | |
| my @windows=(); | |
| my $current_window; | |
| my $cwd=getcwd(); | |
| my $count=1; | |
| if($#ARGV!=-1) { | |
| $count=$1 if($ARGV[0]=~/^(\d+)$/); | |
| } | |
| sub get_windows { | |
| @windows=(); | |
| foreach(split("\n",`tmux list-windows`)) { | |
| $current_window=[$1,$2] if(m!^(\d+): (.+?)\*!); | |
| push @windows,[$1,$2] if(m!^(\d+): (.+?)\W!); | |
| } | |
| } | |
| sub get_next_window_name { | |
| my $base=$current_window->[1]; | |
| my $start=0; | |
| $start=$1 if($base=~s/(\d+)$//); | |
| my $newname=$base; | |
| foreach my $ct($start..99) { | |
| $newname=$base.$ct; | |
| my $exists=0; | |
| foreach(@windows) { | |
| $exists=1 if($_->[1] eq $newname); | |
| } | |
| last unless($exists); | |
| } | |
| return $newname; | |
| } | |
| foreach(1..$count) { | |
| get_windows(); | |
| my $newname=get_next_window_name(); | |
| system('tmux','new-window','-c',$cwd,'-n',$newname); | |
| system('tmux','select-window','-t',$newname); | |
| system('tmux','display-popup','-E','-h','4',qq{echo "$cwd" && sleep $popup_delay}); | |
| } |