Any quick ideas on how to write a program that extends the terminal's basic functionality? I want to do everything the terminal does but additionally do some custom processing on whatever the user types on my terminal derivative.
3 Answers
Download the gnome-terminal source, add your custom processing and recompile. Source is at https://git.gnome.org/browse/gnome-terminal/ Not clear what the 'custom processing' entails, from your original question.

- 21,892
-
I want to look out for certain kinds of text in the commands and send them over the internet for some machine learning tasks. – Minaj Jun 03 '16 at 21:50
From your description of what you want to achieve it sounds like it's not so much the terminal as it's you shell (and judging from your tags that's bash) that you want to extend.
The way to that is by modifying the source code, you can find that on the project's home page.
Another way of achieving what you want might be to make sure that every users shells run inside script
, that program saves both in- and output of every command (and for commands that provide changing output (like progress bars) the output can be hard to read). You'll probably have to write some kind of wrapper that makes for a command suitable for placing in /etc/passwd
and saves in a uniquely named file (I would suggest using a combination of uid and time). If you use the option -f
, the file is written after each write to stdout/stderr. It's an absolutely non-trivial task to determine what's input and what's output, but it might still be simpler to achieve something satisfactory than by modifying bash.
-
Oh, so there is a big difference between these two options? What I want is to be able to type a command such as ifconfig on the terminal, and process it the same exact way that is supposed to be processed, but additionally do my own custom things with the text in this command. Such custom things could include editing the string ifconfig and sending the result of my edit over the internet to some server which could send me some result back. Would I be extending bash in such a case; or would I be extending the terminal being used to communicate with bash? – Minaj Jun 03 '16 at 22:20
-
-
@Minaj, it doesn't have to be. From what you describe you could just write a shell function called
ifconfig
and make it do your processing before calling the external command. – Wildcard Jun 04 '16 at 00:05 -
If you don't need "live" data, you could, by reading man bash
, use per-PID $HISTFILE
s and send the saved commands off to the internet later. A simple matter of scripting rather than source modification. However, uncooperative users can defeat this approach.
One of my answers on AskUbuntu discusses the first part of the method. ~/.bash_logout
(man bash
again) can do the rest.

- 4,865
-
I dont exactly want live data, but I need it as soon as a command has been made. Can I access $HISTFILE after every command typed? Does it update immediately after every command so I could just parse it every second perhaps? – Minaj Jun 03 '16 at 23:40
-
The standard behaviour of shells is to only write their history when exiting. I don't know if bash (or any other shell) can be configured to write to it every time a command is executed. Even if they could that's probably one of the ways uncooperative users could use to interfere with it. – Henrik supports the community Jun 04 '16 at 09:01