2

Typing clear into a shell creates a bunch of new lines until the output history above is all but hidden. Is there a command or method that does the opposite of clear? That essentially moves your current line you are editting to the middle or bottom of the screen, displaying the latest history of your shell above it?

The backstory to this, is that I am trying to map a key in bash/zsh's vi-mode to display previous history or previous output, but without losing the current command I am editting.

Anon
  • 12,339

2 Answers2

2

Navigating the output history is not the job of the shell (Bash/ZSH); they don't keep a record of the output the commands within them have produced. Output history is handled by the terminal, which today is typically either GNOME Terminal or xterm. Both of these support at least these shortcuts, as mentioned by @kos:

  • Shift-Page Up to move at most one $LINES up
  • Shift-Page Down to move at most one $LINES down
l0b0
  • 9,271
1

In bash you can bind a key to a command and so, for example, list the command history whilst in the middle of typing a new command. After the command runs your input line is restored at the point you were originally at.

Eg, give the command

bind -x '"\C-a": history'

Then controla will dump the history.

For permanence add to your ~/.inputc file

"\C-a": history

You can replace history by any command.


In zsh you have a built-in mechanism which pushes the current input buffer onto a stack and allows you to give a new command. When it finishes, the previous input buffer is restored. So you type: escapeq history return.

If you prefer you can setup a zsh widget binding to show the history below the current input buffer you are typing. Eg, for controla again (in your ~/.zshrc):

zle -N myhistory  
myhistory(){zle -M "$(history)";}
bindkey '^a' myhistory

To keep output history you might like to use screen -L which keeps a log of all the output in a file, which you can tail with a binding as above. You might want to filter through cat -e or something, as the file includes all terminal escape sequences.

meuh
  • 3,444