How to make iTerm2 *cd* into a directory by clicking on *ls* results

bashitermshortcutterminal

Would it be possible to make some sort of remap where command-clicking or highlighting some text in the terminal triggers iTerm2 to attempt to cd <text>? Would make life somewhat easier when navigating around complex directory trees with long names.

I found these instructions for making command-click trigger an action on the clicked filename or word. But after trying the Run command... option with cd \1 (for "cd to this clicked item"), that doesn't seem to work.


The answer below evidently does not work on remote logins; if anyone has a solution that does so, I will accept your answer.

Best Answer

I've found that you need to go Preferences -> Profiles -> Advanced -> Semantic History and use Run coprocess... and echo cd \1 to get the desired result.

Don't ask me why this works or how I found this solution.

enter image description here