@@ -340,10 +340,13 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m {
340340 for (NSString * key in menuKeys) {
341341 NSMenu * subMenu = [[NSMenu alloc ] init ];
342342 NSMenuItem * menuItem = [[NSMenuItem alloc ] init ];
343- [menuItem setTitle: key];
343+ [self separatorSortRemoval: key];
344+ [menuItem setTitle: menuName];
344345 [menuItem setSubmenu: subMenu];
345346 [m insertItem: menuItem atIndex: pos++];
346-
347+ if (addSeparator) {
348+ [m insertItem: [NSMenuItem separatorItem ] atIndex: pos++];
349+ }
347350 // build submenu
348351 [self buildMenu: menus[key] addToMenu: subMenu];
349352 }
@@ -362,15 +365,53 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m {
362365 // Get the value of setting inTerminal
363366 NSString *termWindow = cfg[@" inTerminal" ];
364367 // Get the menu name will will use this as the title if title is null.
365- NSString *menuName = cfg[@" name" ];
368+ [ self separatorSortRemoval: cfg[@" name" ] ];
366369
367370 // Place the terminal command, theme, and title into an comma delimited string
368371 NSString *menuRepObj = [NSString stringWithFormat: @" %@ ¬_¬%@ ¬_¬%@ ¬_¬%@ ¬_¬%@ " , menuCmd, termTheme, termTitle, termWindow, menuName];
369372
370- [menuItem setTitle: cfg[ @" name " ] ];
373+ [menuItem setTitle: menuName ];
371374 [menuItem setRepresentedObject: menuRepObj];
372375 [menuItem setAction: @selector (openHost: )];
373376 [m insertItem: menuItem atIndex: pos++];
377+ if (addSeparator) {
378+ [m insertItem: [NSMenuItem separatorItem ] atIndex: pos++];
379+ }
380+ }
381+ }
382+
383+ - (void ) separatorSortRemoval : (NSString *)currentName {
384+ NSError *regexError = nil ;
385+ addSeparator = NO ;
386+
387+ NSRegularExpression *regexSort = [NSRegularExpression regularExpressionWithPattern: @" ([\\ [][a-z]{3}[\\ ]])" options: 0 error: ®exError];
388+ NSRegularExpression *regexSeparator = [NSRegularExpression regularExpressionWithPattern: @" ([\\ [][-]{3}[\\ ]])" options: 0 error: ®exError];
389+
390+ NSUInteger sortMatches = [regexSort numberOfMatchesInString: currentName options: 0 range: NSMakeRange (0 ,[currentName length ])];
391+ NSUInteger separatorMatches = [regexSeparator numberOfMatchesInString: currentName options: 0 range: NSMakeRange (0 ,[currentName length ])];
392+ // NSUInteger *totalMatches = sortMatches + separatorMatches;
393+
394+
395+
396+ if ( sortMatches == 1 || separatorMatches == 1 ) {
397+ if (sortMatches == 1 && separatorMatches == 1 ) {
398+ menuName = [regexSort stringByReplacingMatchesInString: currentName options: 0 range: NSMakeRange (0 , [currentName length ]) withTemplate: @" " ];
399+ menuName = [regexSeparator stringByReplacingMatchesInString: menuName options: 0 range: NSMakeRange (0 , [menuName length ]) withTemplate: @" " ];
400+ addSeparator = YES ;
401+ } else {
402+
403+ if ( sortMatches == 1 ) {
404+ menuName = [regexSort stringByReplacingMatchesInString: currentName options: 0 range: NSMakeRange (0 , [currentName length ]) withTemplate: @" " ];
405+ addSeparator = NO ;
406+ }
407+ if ( separatorMatches == 1 ) {
408+ menuName = [regexSeparator stringByReplacingMatchesInString: currentName options: 0 range: NSMakeRange (0 , [currentName length ]) withTemplate: @" " ];
409+ addSeparator = YES ;
410+ }
411+ }
412+ } else {
413+ menuName = currentName;
414+ addSeparator = NO ;
374415 }
375416}
376417
@@ -443,11 +484,6 @@ - (void) openHost:(NSMenuItem *) sender {
443484 }
444485 }
445486
446- // Set Paths to iTerm Legacy AppleScripts
447- NSString *iTermLegacyNewWindow = [[NSBundle mainBundle ] pathForResource: @" iTerm-legacy-new-window" ofType: @" scpt" ];
448- NSString *iTermLegacyCurrentWindow = [[NSBundle mainBundle ] pathForResource: @" iTerm-legacy-current-window" ofType: @" scpt" ];
449- NSString *iTermLegacyNewTabDefault = [[NSBundle mainBundle ] pathForResource: @" iTerm-legacy-new-tab-default" ofType: @" scpt" ];
450-
451487 // Set Paths to iTerm Stable AppleScripts
452488 NSString *iTermStableNewWindow = [[NSBundle mainBundle ] pathForResource: @" iTerm2-stable-new-window" ofType: @" scpt" ];
453489 NSString *iTermStableCurrentWindow = [[NSBundle mainBundle ] pathForResource: @" iTerm2-stable-current-window" ofType: @" scpt" ];
@@ -479,11 +515,11 @@ - (void) openHost:(NSMenuItem *) sender {
479515 else if ( [terminalPref rangeOfString: @" iterm" ].location !=NSNotFound ) {
480516
481517 // If the JSON prefs for iTermVersion are not stable or nightly throw an error
482- if ( ![iTermVersionPref isEqualToString: @" legacy " ] && ![iTermVersionPref isEqualToString: @" stable" ] && ![iTermVersionPref isEqualToString: @" nightly" ] ) {
518+ if ( ![iTermVersionPref isEqualToString: @" stable" ] && ![iTermVersionPref isEqualToString: @" nightly" ] ) {
483519
484520 if ( iTermVersionPref == 0 ) {
485- errorMessage = NSLocalizedString(@" \" iTerm_version\" : \" VALUE\" , is missing.\n\n\" VALUE\" can be:\n\" legacy \" targeting iTerm 2.14 \n\" stable\" targeting new versions.\n\" nightly\" targeting nightly builds.\n\n Please fix your shuttle JSON settings.\n See readme.md on shuttle's github for help." ,nil );
486- errorInfo = NSLocalizedString(@" Press Continue to try iTerm stable applescripts.\n -->(not recommended)<--\n This will fail if you have another version of iTerm installed.\n\n Please fix the JSON settings.\n Press Quit to exit shuttle." ,nil );
521+ errorMessage = NSLocalizedString(@" \" iTerm_version\" : \" VALUE\" , is missing.\n\n\" VALUE\" can be:\n\" stable\" targeting new versions.\n\" nightly\" targeting nightly builds.\n\n Please fix your shuttle JSON settings.\n See readme.md on shuttle's github for help." ,nil );
522+ errorInfo = NSLocalizedString(@" Press Continue to try iTerm stable applescripts.\n -->(not recommended)<--\n This could fail if you have another version of iTerm installed.\n\n Please fix the JSON settings.\n Press Quit to exit shuttle." ,nil );
487523 [self throwError: errorMessage additionalInfo: errorInfo continueOnErrorOption: YES ];
488524 iTermVersionPref = @" stable" ;
489525
@@ -494,23 +530,6 @@ - (void) openHost:(NSMenuItem *) sender {
494530 }
495531 }
496532
497- if ( [iTermVersionPref isEqualToString: @" legacy" ]) {
498-
499- // run the applescript that works with iTerm Legacy
500- // if we are running in a new iTerm "Stable" Window
501- if ( [terminalWindow isEqualToString: @" new" ] ) {
502- [self runScript: iTermLegacyNewWindow handler: handlerName parameters: passParameters];
503- }
504- // if we are running in the current iTerm "Stable" Window
505- if ( [terminalWindow isEqualToString: @" current" ] ) {
506- [self runScript: iTermLegacyCurrentWindow handler: handlerName parameters: passParameters];
507- }
508- // we are using the default action of shuttle... The active window in a new tab
509- if ( [terminalWindow isEqualToString: @" tab" ] ) {
510- [self runScript: iTermLegacyNewTabDefault handler: handlerName parameters: passParameters];
511- }
512- }
513- // iTermVersion is not set to "legacy" using applescripts Configured for Stable
514533 if ( [iTermVersionPref isEqualToString: @" stable" ]) {
515534
516535 // run the applescript that works with iTerm Stable
0 commit comments