Mittwoch, 14. Oktober 2015

Using the last command in the Bash prompt

Today I had the idea that it might be useful to have the return value of the last command in the PUtty title. And next step is to put also the last command into the title.

The command history 1 prints the last command from the Bash history of commands. The Output is prefixed by a number and two spaces. The following Bash expression removes the prefix and prints just the command.

$(h=$(history 1);n=${h/% */};echo "${h#$n }")

First h is initialized with the whole history line. Then n is set to the remaining part of h after the longest match from the right up the a space is removed from h. And in the end h without the prefix stored in n is printed.

Keine Kommentare: