@@ -222,13 +222,15 @@ static void cleanup_function(void* parameters) {
222222 }
223223 currentSession->activePager = FALSE ;
224224 }
225- if ((!joinMainThread) && p->isPipeOut ) {
225+ // If the command was started as a pipe, we wait for the first command to finish sending data
226+ // There is an exception for ssh, which can be started by scp or sftp. They will wait for it.
227+ if ((!joinMainThread) && p->isPipeOut && (strcmp (commandName, " ssh" ) != 0 )) {
226228 if (currentSession->current_command_root_thread != 0 ) {
227229 if (currentSession->current_command_root_thread != pthread_self ()) {
228- // NSLog(@"Thread %x is waiting for root_thread of currentSession: %x \n", pthread_self(), currentSession->current_command_root_thread);
230+ NSLog (@" Thread %x is waiting for root_thread of currentSession: %x \n " , pthread_self (), currentSession->current_command_root_thread );
229231 while (currentSession->current_command_root_thread != 0 ) { }
230232 } else {
231- // NSLog(@"Terminating root_thread of currentSession %x \n", pthread_self());
233+ NSLog (@" Terminating root_thread of currentSession %x \n " , pthread_self ());
232234 currentSession->current_command_root_thread = 0 ;
233235 }
234236 }
@@ -272,7 +274,7 @@ static void cleanup_function(void* parameters) {
272274 }
273275 }
274276 if (mustCloseStderr) {
275- // NSLog(@"Closing stderr (mustCloseStderr): %d \n", fileno(p->stderr));
277+ NSLog (@" Closing stderr (mustCloseStderr): %d \n " , fileno (p->stderr ));
276278 fclose (p->stderr );
277279 }
278280 bool mustCloseStdout = fileno (p->stdout ) != fileno (stdout);
@@ -283,18 +285,18 @@ static void cleanup_function(void* parameters) {
283285 }
284286 }
285287 if (mustCloseStdout) {
286- // NSLog(@"Closing stdout (mustCloseStdout): %d \n", fileno(p->stdout));
288+ NSLog (@" Closing stdout (mustCloseStdout): %d \n " , fileno (p->stdout ));
287289 fclose (p->stdout );
288290 }
289291 if ((p->dlHandle != RTLD_SELF) && (p->dlHandle != RTLD_MAIN_ONLY)
290292 && (p->dlHandle != RTLD_DEFAULT) && (p->dlHandle != RTLD_NEXT))
291293 dlclose (p->dlHandle );
292294 free (parameters); // This was malloc'ed in ios_system
293295 if (isLastThread) {
294- // NSLog(@"Terminating lastthread of currentSession %x lastThreadId %x\n", pthread_self(), currentSession->lastThreadId);
296+ NSLog (@" Terminating lastthread of currentSession %x lastThreadId %x \n " , pthread_self (), currentSession->lastThreadId );
295297 currentSession->lastThreadId = 0 ;
296298 } else {
297- // NSLog(@"Current thread %x lastthread %x \n", pthread_self(), currentSession->lastThreadId);
299+ NSLog (@" Current thread %x lastthread %x \n " , pthread_self (), currentSession->lastThreadId );
298300 }
299301 ios_releaseThread (pthread_self ());
300302 if (currentSession->current_command_root_thread == pthread_self ()) {
@@ -1583,9 +1585,35 @@ void ios_stopInteractive() {
15831585 function = dlsym (RTLD_MAIN_ONLY, " stopInteractive" );
15841586 if (function != NULL ) {
15851587 function ();
1588+ } else {
1589+ NSLog (@" Could not find function stopInteractive" );
15861590 }
15871591}
15881592
1593+ void ios_startInteractive () {
1594+ // With aliasing, we can have commands that are interactive and not detected by the command-line interpreter.
1595+ void (*function)() = NULL ;
1596+ function = dlsym (RTLD_MAIN_ONLY, " startInteractive" );
1597+ if (function != NULL ) {
1598+ function ();
1599+ } else {
1600+ NSLog (@" Could not find function startInteractive" );
1601+ }
1602+ }
1603+
1604+ static int isInteractive (const char * command) {
1605+ // let interactiveRegexp = /^vim|^ipython|^less|^more|^ssh|^scp|^sftp|^jump|\|&? *less|\|&? *more|^man/;
1606+ if (strncmp (command, " vim" , 3 ) == 0 ) return true ;
1607+ if (strncmp (command, " ipython" , 7 ) == 0 ) return true ;
1608+ if (strncmp (command, " less" , 4 ) == 0 ) return true ;
1609+ if (strncmp (command, " more" , 4 ) == 0 ) return true ;
1610+ if (strncmp (command, " scp" , 3 ) == 0 ) return true ;
1611+ if (strncmp (command, " man" , 3 ) == 0 ) return true ;
1612+ if (strncmp (command, " sftp" , 4 ) == 0 ) return true ;
1613+ if (strncmp (command, " jump" , 4 ) == 0 ) return true ;
1614+ return false ;
1615+ }
1616+
15891617void ios_setContext (const void *context) {
15901618 if (currentSession == NULL ) return ;
15911619 currentSession->context = context;
@@ -1899,6 +1927,11 @@ int ios_system(const char* inputCmd) {
18991927 originalCommand = newCommand;
19001928 cmd = newCommand;
19011929 command = newCommand;
1930+ // Maybe we aliased to an interactive command (vim, ssh, less, more, man, scp, sftp)
1931+ // We need to tell the command line editor:
1932+ if (isInteractive (newCommand)) {
1933+ ios_startInteractive ();
1934+ }
19021935 }
19031936 }
19041937 free (commandForParsing);
0 commit comments