Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iterm2 issue : create new tab with same path of previous current tab BUT 2 tabs are clones and not indepedent

I have switched from default terminal on MacOS Mojave to iterm2. I have an issue about the opening of a new tab from the current tab.

Indeed, I would like to be in the same path than the previous current tab.

For this, I did the classical procedure, i.e to go to iterm2 preferences and Profile and choose Reuse previous session's directory for new tab :

enter image description here

Then, the issue is that once tab opened, all the other tabs are affected and change from their old path to the path of the new tab: I don't understand what happens and which option to use to prevent this behavior.

  1. Every tab is the same than the others: if I do a cd ~/foo/, then the other tabs will go into foodirectory.

  2. Result worse: if I edit with vim a file in one tab, if I do a cd ~/foo/ in another tab, then the tab associated to the edited file disappears is clearing this edition and shows the same windows than the tab where I did cd ~/foo/: very strange.

I want to keep all the current path for all others tabs except for the new one which must be the same than the previous one from which I do a CMD+T.

I saw on different forums this issue sometimes occurs.

Update 1

From what I have seen, it seems that I have to find a way to create a new session when I do the shortcut CMD+T to get another tab independent from the current one (from which I do CMD+T).

But unfortunately, I didn't find how to create a new session in iTerm2 (inside the iTerm2 - Preferences - profile, I could execute a script that creates this new session). From the moment, you can see the command (/bin/bash that I launch when I open a new tab:

command /bin/bash launched for new tab

I tried also to build the binary iTerm2 from the sources but issue remains.

Update 2

I tried to use a little apple script to force a new session to be created from current window:

tell application "iTerm2"
    tell current window
        create tab with profile "Terminology2"
    end tell
end tell

(where Terminology2 is a duplicate of profile Terminology (default profile).

But always the same issue, the 2 tabs are not independent: each command in one of 2 is executed on the another one.

Update 3

I keep on trying a solution: for this I removed the macport package and hidden files and directory ~/.iTerm2/.

So I downloaded the iTerm2 zip archive from iTerm2 official website.

Here's a screen capture of my profile :

profile

Is shortcut key necessary in this profile to open new tabs : the issue seems to come from this option since it may not concern the shortcut for a new tab ? CMD+T is already a shortcut for opening an independent tab, isn't it ?

Update 4

Solution finally found. Coming from classic MacOS terminal, I was used to do a shortcut CMD+Shift+-> or CMD+Shift+<- to change of tab.

But by chance, I tried simply the shortcut CMD+-> or CMD+<- and so was able to switch between 2 tabs independent.

So this was an error of beginner into iTerm2's world since I was used to apply old classical shortcut of default terminal.

If someone else makes the same mistake, they will know that it is just a configuration issue of shortcut.

like image 526
youpilat13 Avatar asked Oct 22 '19 10:10

youpilat13


1 Answers

The OP already answered the question in Update 4, but in case anyone jumps right to the answers, the solution was to update the Key Mappings and create two new entries - CMD+SHIFT+LEFT & CMD+SHIFT+RIGHT - with assigned actions of Previous Tab and Next Tab, respectively.

These entries can be created in Preferences -> ${Your Profile} -> Keys, and then clicking on the + icon near the Presets... button.

like image 80
sudo soul Avatar answered Oct 13 '22 13:10

sudo soul