Pierre-Antoine Guillaume
Pierre-Antoine Guillaume

Reputation: 1126

How to get the content of a terminal in bash?

I am trying to make a software that determines my PS1 (my prompt) depending on the content of what's written in the terminal (limited to what I can see), to avoid cluttering my work space. For instance, if the terminal seems cluttered or are missing, reprint some info (path, user, host)

I am using GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu), though I don't know if it will change anything

Let's say my terminal looks like this right now :

terminal buffer

I would like to get a variable with this content as a single string:

$ echo 1
1
$ echo 2
2
$ LANG= git status
fatal: not a git repository (or any of the parent directories): .git
$ echo 3
3
$ time

real    0m0,000s
user    0m0,000s
sys 0m0,000s
$ LANG= date
Fri Jan  6 13:17:37 CET 2023
$ 

Which I would forward to my program.

This question states it is impossible, but it seems to use the curses lib, so I don't know if it is related.

Read screen character from terminal

Bonus questions:

Upvotes: 0

Views: 124

Answers (1)

Calvin Kim
Calvin Kim

Reputation: 364

Sometimes, you need to stop chasing dragon. Stop what you are doing, step back and think what you really want to do. There maybe another approach which could be easier and better. The fact that you have to read from the terminal tells me you are poking a sleeping dragon. You can try, but expect undesirable outcome.

If you want clear indication where your prompt is, try something like

Upvotes: 1

Related Questions