cmderdev / cmder

Lovely console emulator package for Windows
https://cmder.app
MIT License
25.68k stars 2.02k forks source link

Question: Is there a way to get the output of the last command? #2950

Open Perverance opened 2 weeks ago

Perverance commented 2 weeks ago

Question

I know this might be a silly question, but, is there a way to achieve the following?

λ command1
# command1 output
λ <shortcut_or_command>
# command1 output

Where shortcut_or_command would be what I'm looking for, a way to retrieve the last output (not the last exit code, just the last output).

I found a shortcut named "Show alternative console buffer (last command output)", but I don't know what it does.

Thanks!

Checklist

daxgames commented 2 weeks ago

You mean like a command alias?

alias lsar=ls -lar

lsar
# ls -lar output
Perverance commented 2 weeks ago

You mean like a command alias?

alias lsar=ls -lar

lsar
# ls -lar output

Hi! Either way would be fine, because I don't know how it could be achieved. What I'm looking for is a way for CMDER to resend its last output, be it with a command or a keyboard shortcut.

λ echo hey
hey
λ <command/shortcut to resend the last console output>
hey
chrisant996 commented 2 weeks ago

What do you mean by "resend the last output"?

Resend it where, how? You can scroll up to view it, so you must be asking about something other than viewing the output that's on the screen.

Also, the output is from other console mode programs launched from inside ConEmu/Cmder. The output is not actually from ConEmu/Cmder.

(Or are you asking how to access command history and rerun a command? But the command may produce different output the next time, so that wouldn't "resend the last output".)

DRSDavidSoft commented 2 weeks ago

@Perverance is it possible to append something like: | tee last_output.txt to the end of your command?

Then you can do cat last_output.txt later to see the ouput again. You can bind this to a shortcut key using Clink, too.

Alternatively, we need a shell that would capture the output of every command that is run, the have something like show last output command to retireve it. A bit unfeasible, but perfectly doable nonetheless.

chrisant996 commented 2 weeks ago

Alternatively, we need a shell that would capture the output of every command that is run, the have something like show last output command to retireve it. A bit unfeasible, but perfectly doable nonetheless.

A shell can't capture output without using redirection, and redirection alters how programs operate.

"Always-on output capture" is something that would have to be provided by the terminal itself, otherwise it would create compatibility problems in programs.