0

The tcolorbox manual shows a nice example of prepending a command prompt on every line of a shell input (page 317), but it apparently only works for the listings library. Is there a similar option for the minted library? I searched through the manual for minted, but the only option I found that might offer this option was the formatcom option… but I don't think that is going to work.

For the record, I would be fine with the output in this answer, but I

  1. can't figure out how to format this inside the definition for a \newtcblisting (color, font weight, etc.), and
  2. don't want to have to include my prompt info on every line throughout my file.

My current MWE is as follows:

\documentclass{article}
\usepackage{tcolorbox}
  \tcbuselibrary{minted}

\newtcblisting{bashinput}[1][]{
  listing engine=minted,
  minted language=bash,
  minted options={
    fontsize=\small,
    breaklines,
    autogobble,
    numbersep=2mm},
  listing only,
  ,#1}

\begin{document}

\begin{bashinput}
user ~$ vi /etc/sysconfig/network
user ~$ grep Dipole file-name -A1 | tail -n1 | awk '\{print \$8\}'
\end{bashinput}

\end{document}

Ideally, I could just add a line after listing only, containing something like every listing line={\textcolor{red}{\small\ttfamily\bfseries ~$}}

1

Taken from this answer, using the formatcom option of the minted package:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{minted}

% < ADDED CODE >
\newcommand{\BashFancyFormatLine}{%
  \def\FancyVerbFormatLine##1{\textcolor{red}{\small\$}\ ##1}%
}
% </ADDED CODE >

\newtcblisting{bashinput}[1][]{
  listing engine=minted,
  minted language=bash,
  minted options={
    fontsize=\small,
    breaklines,
    autogobble,
    numbersep=2mm,
    formatcom=\BashFancyFormatLine}, % ADDED LINE
  listing only,
  ,#1}

\begin{document}

\begin{bashinput}
some text
\end{bashinput}

\end{document}

enter image description here

  • Ugh, can't believe I missed that answer. This is perfect, thank you! – Dustin Wheeler Apr 20 '20 at 15:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.