So for simple things like finding out of the network, CPU, memory or disk usage is my bottleneck, I wrote this really nifty script to connect the world of Minecraft and the Linux shell.
My completed solution for what I needed can be found at [https://github.com/TTWNO/termcraft](https://github.com/TTWNO/termcraft/).
If you want some of the implementation details, stick around.
## Solution
So to solve this interesting problem, I decided to use `tmux`.
This is very valuable when running command line applications that need to have an active console connection, like a Minecraft server.
So first I looked at the `tmux` command `send-keys`.
#### `send-keys`
`send-keys` allows you to send text, and key presses to a `tmux` session.
Now assuming this `tmux` session is attached to a Minecraft server,
there is no reason you could not run a command like this:
<preclass="terminal">
$ tmux send-keys "tell @a This is a Test" Enter
</pre>
This will send the text "tell @a This is a Test" to the Minecraft server.
Then, it will hit the newline character, this will execute the command.
So now we can send information to the server and have it tell the users something.
But how do we get information about who is typing what in the Minecraft chat?
### `tmux`'s `capture-pane` is painful
So in the manual page for `tmux` I can see a section recorded below for options I can give to the `capture-pane` subcommand.
<preclass="terminal">
-S and -E specify the starting and ending line numbers,
zero is the first line of the visible pane and negative
numbers are lines in the history. ‘-’ to -S is the start
of the history and to -E the end of the visible pane. The
default is to capture only the visible contents of the pane.
</pre>
What it seems to be saying is I can start at line `-S n` and end at line `-E n`.
Negative numbers start from the bottom, so *in theory* I can do the following: `tmux capture-pane -S -1` should capture only the last line, because I'm starting from the last line. Right?
No. It just doesn't work. Negative numbers do *not* work with the `tmux capture-pane` subcommand.
So I did some simple UNIX piping, like so, to get just the last thing in the chat.