@@ -22,6 +22,7 @@ tmux session. If the hook gets triggered the views will be updated.
22
22
=cut
23
23
24
24
25
+ use Cwd qw( abs_path) ;
25
26
use File::Basename;
26
27
use Getopt::Long;
27
28
use JSON::PP qw( decode_json) ;
@@ -86,6 +87,9 @@ if (@ARGV == 6) {
86
87
my $width = $config -> {width } || $DEFAULT {TMUX_WIDTH };
87
88
my $height = $config -> {height } || $DEFAULT {TMUX_HEIGHT };
88
89
90
+ # Check hook link before creating tmux session
91
+ ensure_hook_link();
92
+
89
93
# Setup layout
90
94
tmux(' new' , ' -s' , $session , ' -n' , $window , ' -d' , ' -x' , $width , ' -y' , $height , $MINIMAL_BASH );
91
95
tmux(' set' , ' -t' , " $session :$window " , ' status' , " off" );
@@ -100,7 +104,6 @@ if (@ARGV == 6) {
100
104
tmux(' send-keys' , ' -t' , " $session :$window .%$idx " , " clear; $command " , ' Enter' );
101
105
}
102
106
103
- ensure_hook_link();
104
107
tmux(' attach' , ' -t' , $session ) if $config -> {' auto-attach' };
105
108
}
106
109
@@ -183,21 +186,15 @@ sub dashboard_is_running {
183
186
}
184
187
185
188
sub ensure_hook_link {
186
- my $target = resolve_link ($0 );
189
+ my $target = abs_path ($0 );
187
190
my $symlink = task_config(' rc.data.location' ) . ' /hooks/on-exit_dashboard' ;
188
191
if (-e $symlink ) {
189
- die " Hook symlink points to another location!\n " if resolve_link ($symlink ) ne $target ;
192
+ die " Hook symlink points to another location!\n " if abs_path ($symlink ) ne $target ;
190
193
} else {
191
194
symlink $target , $symlink ;
192
195
}
193
196
}
194
197
195
- sub resolve_link {
196
- my $target = shift ;
197
- $target = readlink $target while -l $target ;
198
- return $target ;
199
- }
200
-
201
198
sub task_config {
202
199
chomp (my $output = ` task rc.verbose:nothing rc.hooks:off _get @_ ` );
203
200
$output =~ s / ^~/ $ENV {HOME}/ ; # Tilde expansion
0 commit comments