Skip to content
Snippets Groups Projects
Commit f5015c4b authored by George Nachman's avatar George Nachman
Browse files

Detect tmux 1.8. Do not attempt to recycle directory since it doesn't know how.

parent a7b946be
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -49,7 +49,8 @@ static NSString *kListWindowsFormat = @"\"#{session_name}\t#{window_id}\t"
 
@implementation iTermInitialDirectory(Tmux)
 
- (NSString *)tmuxNewWindowCommandInSession:(NSString *)session {
- (NSString *)tmuxNewWindowCommandInSession:(NSString *)session
recyclingSupported:(BOOL)recyclingSupported {
NSArray *args = @[ @"new-window", @"-PF '#{window_id}'" ];
if (session) {
Loading
Loading
@@ -59,34 +60,40 @@ static NSString *kListWindowsFormat = @"\"#{session_name}\t#{window_id}\t"
targetSessionArg ];
args = [args arrayByAddingObjectsFromArray:insertionArguments];
}
return [self tmuxCommandByAddingCustomDirectoryWithArgs:args];
return [self tmuxCommandByAddingCustomDirectoryWithArgs:args recyclingSupported:recyclingSupported];
}
 
- (NSString *)tmuxNewWindowCommand {
return [self tmuxNewWindowCommandInSession:nil];
- (NSString *)tmuxNewWindowCommandRecyclingSupported:(BOOL)recyclingSupported {
return [self tmuxNewWindowCommandInSession:nil recyclingSupported:recyclingSupported];
}
 
- (NSString *)tmuxSplitWindowCommand:(int)wp vertically:(BOOL)splitVertically {
- (NSString *)tmuxSplitWindowCommand:(int)wp vertically:(BOOL)splitVertically
recyclingSupported:(BOOL)recyclingSupported {
NSArray *args = @[ @"split-window",
splitVertically ? @"-h": @"-v",
@"-t",
[NSString stringWithFormat:@"%%%d", wp] ];
return [self tmuxCommandByAddingCustomDirectoryWithArgs:args];
return [self tmuxCommandByAddingCustomDirectoryWithArgs:args recyclingSupported:recyclingSupported];
}
 
- (NSString *)tmuxCustomDirectoryParameter {
- (NSString *)tmuxCustomDirectoryParameterRecyclingSupported:(BOOL)recyclingSupported {
switch (self.mode) {
case iTermInitialDirectoryModeHome:
return nil;
case iTermInitialDirectoryModeCustom:
return [self.customDirectory stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
case iTermInitialDirectoryModeRecycle:
return @"#{pane_current_path}";
if (recyclingSupported) {
return @"#{pane_current_path}";
} else {
return nil;
}
}
}
 
- (NSString *)tmuxCommandByAddingCustomDirectoryWithArgs:(NSArray *)args {
NSString *customDirectory = [self tmuxCustomDirectoryParameter];
- (NSString *)tmuxCommandByAddingCustomDirectoryWithArgs:(NSArray *)args
recyclingSupported:(BOOL)recyclingSupported {
NSString *customDirectory = [self tmuxCustomDirectoryParameterRecyclingSupported:recyclingSupported];
if (customDirectory) {
NSString *escapedCustomDirectory= [customDirectory stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
NSString *customDirectoryArgument = [NSString stringWithFormat:@"-c '%@'", escapedCustomDirectory];
Loading
Loading
@@ -713,6 +720,11 @@ static NSString *kListWindowsFormat = @"\"#{session_name}\t#{window_id}\t"
[gateway_ dictionaryForCommand:@"list-windows -F \"#{session_activity}\""
responseTarget:self
responseSelector:@selector(guessVersion21Response:)
responseObject:nil
flags:kTmuxGatewayCommandShouldTolerateErrors],
[gateway_ dictionaryForCommand:@"list-clients -F \"#{client_cwd}\"" // client_cwd was deprecated in 1.9
responseTarget:self
responseSelector:@selector(guessVersion18Response:)
responseObject:nil
flags:kTmuxGatewayCommandShouldTolerateErrors]
];
Loading
Loading
@@ -770,6 +782,24 @@ static NSString *kListWindowsFormat = @"\"#{session_name}\t#{window_id}\t"
}
}
 
- (void)guessVersion18Response:(NSString *)response {
if (response.length == 0) {
[self increaseMinimumServerVersionTo:@"1.9"];
} else {
[self decreaseMaximumServerVersionTo:@"1.8"];
}
}
- (BOOL)recyclingSupported {
NSDecimalNumber *version1_9 = [NSDecimalNumber decimalNumberWithString:@"1.9"];
if (gateway_.minimumServerVersion != nil) {
return ([gateway_.minimumServerVersion compare:version1_9] != NSOrderedAscending);
} else {
// Assume 1.8
return NO;
}
}
// Show an error and terminate the connection because tmux has an unsupported option turned on.
- (void)optionValidationFailedForOption:(NSString *)option
{
Loading
Loading
@@ -860,7 +890,9 @@ static NSString *kListWindowsFormat = @"\"#{session_name}\t#{window_id}\t"
vertically:(BOOL)splitVertically
initialDirectory:(iTermInitialDirectory *)initialDirectory {
// No need for a callback. We should get a layout-changed message and act on it.
[gateway_ sendCommand:[initialDirectory tmuxSplitWindowCommand:wp vertically:splitVertically]
[gateway_ sendCommand:[initialDirectory tmuxSplitWindowCommand:wp
vertically:splitVertically
recyclingSupported:self.recyclingSupported]
responseTarget:nil
responseSelector:nil];
}
Loading
Loading
@@ -874,7 +906,8 @@ static NSString *kListWindowsFormat = @"\"#{session_name}\t#{window_id}\t"
 
- (void)newWindowInSession:(NSString *)targetSession
initialDirectory:(iTermInitialDirectory *)initialDirectory {
[gateway_ sendCommand:[initialDirectory tmuxNewWindowCommandInSession:targetSession]
[gateway_ sendCommand:[initialDirectory tmuxNewWindowCommandInSession:targetSession
recyclingSupported:self.recyclingSupported]
responseTarget:nil
responseSelector:nil];
}
Loading
Loading
@@ -882,7 +915,7 @@ static NSString *kListWindowsFormat = @"\"#{session_name}\t#{window_id}\t"
- (void)newWindowWithAffinity:(NSString *)windowIdString
initialDirectory:(iTermInitialDirectory *)initialDirectory {
_manualOpenRequested = (windowIdString != nil);
[gateway_ sendCommand:[initialDirectory tmuxNewWindowCommand]
[gateway_ sendCommand:[initialDirectory tmuxNewWindowCommandRecyclingSupported:self.recyclingSupported]
responseTarget:self
responseSelector:@selector(newWindowWithAffinityCreated:affinityWindow:)
responseObject:windowIdString
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment