0

Is it possible to grab the previous line in a terminal (xterm-256color alone would do) via ANSI sequences, tput or the like? Say I have

$ pwd
/some/long/path
$ cd $(result)

i.e. a programmatic copy-paste (or something akin to Out[1] in ipython). There's https://github.com/rcaloras/bash-preexec (see https://superuser.com/a/175802/1193313) but I'm curious if there's a less invasive way.

usretc
  • 723
  • 4
  • 9
  • 1
    No, I don't think there is a simple way to do that. – tripleee Apr 10 '21 at 11:05
  • 1
    In general, no. It greatly depends on your terminal. You could scrape the pane with `tmux capture-pane`. – William Pursell Apr 12 '21 at 16:35
  • Good find. I'm not looking for anything more general than xterm-256color, but I realize this may not be precise enough – usretc Apr 12 '21 at 16:49
  • 1
    See also: [Can zsh access the stdout of last run program?](https://unix.stackexchange.com/questions/117054/can-zsh-access-the-stdout-of-last-run-program) – Hans Lub Apr 12 '21 at 16:51

0 Answers0