[Tex/LaTex] Bold code in listings environment

boldlistingssourcecode

I want to do a box like this
enter image description here

but the bold text doesn't appear.

Edited:

\documentclass{article}
\usepackage{listings,xcolor,etoolbox,lmodern}
\definecolor{verbgray}{gray}{0.9}
\newcommand*\prompt{}% empty default
\lstnewenvironment{sh}{%
  % redefine bash prompt:
  \def\prompt{user@linux:\textasciitilde\$\space}%
  \lstset{backgroundcolor=\color{verbgray},
    frame=single,
    framerule=1pt,
    basicstyle=\ttfamily,
    columns=fullflexible,
    escapechar=@
  }%
}{}
\begin{document}
    \begin{sh}
    @\prompt\space\textbf{date}@
    Thu Oct 25 13:51:54 EDT 2007
    \end{sh}
\end{document}

Best Answer

Here's a slightly modified version of what you wrote:

\documentclass{article}
\usepackage{lmodern}
\usepackage{listings,xcolor,etoolbox}
\definecolor{verbgray}{gray}{0.9}
\newcommand*\prompt{}% empty default
\lstnewenvironment{sh}{%
  % redefine bash prompt:
  \def\prompt{user@linux:\textasciitilde\$\space}%
  \lstset{backgroundcolor=\color{verbgray},
    frame=single,
    framerule=1pt,
    basicstyle=\ttfamily,
    columns=fullflexible,
    escapechar=@
  }%
}{}
% patch \lst@NewLine:
\makeatletter
\patchcmd\lst@NewLine
  {\hbox{}}% search
  {\hbox{}\prompt}% replace
  {}% success
  {}% failure
\makeatother
\begin{document}
    \begin{sh}
    @\textbf{date}@
    Thu Oct 25 13:51:54 EDT 2007
    \end{sh}
\end{document}

enter image description here

You need fonts which will allow bold when creating ttfamily. Hence the loading of

\usepackage{lmodern}
Related Question