I want to make a gray box with some code inside but it should already appear a centered tilde followed by a dollar sign. Or how can I use a command inside the environment to obtain certain text like \newcommand{\prompt}{user@linux:\~\$}
\documentclass{book}
\usepackage{fontspec,listings,color}
\definecolor{verbgray}{gray}{0.9}
\newfontfamily\ubuntumono{Ubuntu Mono}
\lstnewenvironment{sh}{
\lstset{backgroundcolor=\color{verbgray},
frame=single,
framerule=1pt,
basicstyle=\ubuntumono,
columns=fullflexible}}{}
\begin{document}
\begin{sh}
user@linux:(centered tilde)$
\end{sh}
\end{document}
This must be built with XeLaTeX for the fontspec package.

\documentclass{...}, the required\usepackage's,\begin{document}, and\end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Jan 24 '15 at 16:59