[Tex/LaTex] A package for formatting Linux terminal excerpts

formattingpackagessyntax

I know about minted and listings, but either of those are intended for formatting of programming languages excerpts. Is there a package that would do the same for Linux terminal excerpts?

Such as:

peter@kbpet:~$ echo $(uname -i)
x86_64

The minimal solution would be to automatically embolden the peter@kbpet: to every line and indent the leading line of each block.

The other major convenience sought is math symbols like $ and _ should be automatically interpreted as escaped.

Best Answer

What do you think about this suggestion:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstdefinestyle{Bash}
{language=bash,
keywordstyle=\color{blue},
basicstyle=\ttfamily,
morekeywords={peter@kbpet},
alsoletter={:~$},
morekeywords=[2]{peter@kbpet:},
keywordstyle=[2]{\color{red}},
literate={\$}{{\textcolor{red}{\$}}}1 
         {:}{{\textcolor{red}{:}}}1
         {~}{{\textcolor{red}{\textasciitilde}}}1,
}



\begin{document}

\begin{lstlisting}[style=Bash]
peter@kbpet:~$ echo $(uname -i)
x86_64

\end{lstlisting}
\end{document}

enter image description here

Related Question