Copy the output of the last command in iTerm2

7,805

Solution 1

I figured out the solution:

  • Install Shell Integration: iTerm2 > Install Shell Integration
  • Restart iTerm2
  • Run some command that produces output, e.g. pwd
  • Verify that Edit > Select Output of Last Command is enabled, and that the shortcut Cmd + Shift + A works as well.

Note: the solution also works over SSH if you source the shell integration script

Solution 2

It works exactly the same for iTerm2 at least in El Capitan.

Share:
7,805
Juuso Ohtonen
Author by

Juuso Ohtonen

Interests: Android, Python, Continuous integration (Jenkins) Android developer database by their location: http://www.androidtalents.com Some references on Android apps: Word Game http://goo.gl/F86Qnd and the Finnish web site: http://www.sanapeli.net/ Shopping List: https://play.google.com/store/apps/details?id=net.sanapeli.shoppinglist ADB Change Language helper app for developers: https://play.google.com/store/apps/details?id=net.sanapeli.adbchangelanguage Base Converter: https://play.google.com/store/apps/details?id=net.sanapeli.baseconverter Barcode to Price Comparison application (in Finland): https://play.google.com/store/apps/details?id=net.sanapeli.hintavertailu SOreadytohelp

Updated on September 18, 2022

Comments

  • Juuso Ohtonen
    Juuso Ohtonen almost 2 years

    With the default Terminal.app, one can select the previous command output with Cmd + Shift + A and then copy it with Cmd + C (source).

    Is there a similar shortcut for iTerm2?

  • Juuso Ohtonen
    Juuso Ohtonen almost 7 years
    It does not work for me on El Capitan. Or is it a configuration issue in iTerm2?
  • Juuso Ohtonen
    Juuso Ohtonen almost 7 years
    Thanks to you @Vivien, I figured out what the problem was and added it as an answer.
  • Vivien Garcia
    Vivien Garcia almost 7 years
    Nice clarification @JuusoOhtonen. I didn't thought about Shell Integration. It seems I had all the steps done right without trying :)
  • Harrison Cramer
    Harrison Cramer over 4 years
    This is great. Thanks!
  • Sida Zhou
    Sida Zhou almost 4 years
    Note that this doesnt seem to work on remote machines
  • Franklin Yu
    Franklin Yu almost 3 years
    @SidaZhou It does work when you SSH to a machine, as long as the remote shell also sources the shell integration script.
  • Sida Zhou
    Sida Zhou almost 3 years
    @FranklinYu Holy **** *****, IT WORKS!! This is the answer I've been searching all my life. Can you edit the answer to highlight this? Documentation doesnt seem to mention this case.
  • Giuseppe
    Giuseppe over 2 years
    Please note that restarting iTerm2 is not necessary, as long as the shell integration script is sourced after installation