From: Grant Taylor via COFF <coff@minnie.tuhs.org>
To: coff@minnie.tuhs.org
Subject: Re: [COFF] What is your prompt?
Date: Fri, 24 Dec 2021 10:17:07 -0700 [thread overview]
Message-ID: <b8df4957-0834-ad5b-7ff2-d44c9cbcacdd@spamtrap.tnetconsulting.net> (raw)
In-Reply-To: <CALMnNGjpf2vwL6brDM3jOuawrrspiaFG=+X8cZem+y25WWvrsA@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 3927 bytes --]
On 12/22/21 11:59 PM, Andy Kosela wrote:
> What is your prompt?
Pre-Script: Seeing as how this is COFF and it's supposed to be a slow
day at work (holding down the fort while others celebrate) I'll chime
in. What follows is what the type of thing that I'd be interested in
reading from others.
I've been a *LONG* *TIME* advocate for having at the very minimum 1) the
(current) username and 2) the hostname in the prompt. This became
exceedingly apparent at my last job with a bunch of junior admins, too
many of which (read: > 0), inadvertently issued commands as the wrong
user and / or on the wrong host.
I personally like having the current working directory in the prompt.
After some other incidents at my previous job, I started advocating for
having the leading character in the prompt be a "#" so that most shells
would not interpret it as a command pasted with trailing carriage return.
This brings me to the quintessential Bash / Zsh PS1 prompt of:
PS1="#[\u@\h:\w]\$ "
The square brackets are effectively eye candy. The \$ evaluates to
indication of if you're running as a normal user or root. It's largely
superfluous with \u in the prompt. But it makes things uniform and
reduces questions when others are learning things.
When I migrated to Zsh, my prompt got a bit more complex. The base
prompt in a new terminal window still looks mostly the same as the above
PS1. The biggest difference is that I use Zsh's RPROMPT for transient
things like the previous commands return code ($?) and date & time (the
prompt was printed). The RPROMPT has the nice feature of it leaves the
screen when when the current command is executed, thus it doesn't
clutter screen scroll back.
I'm leveraging Zsh's conditional prompt features to make the return code
($?) stand out in bright white on bright red when $? != 0.
My shell initialization files conditionally set various environment
variables which are used in the prompt. Conditionally on things like:
- the TERM type
- my terminal emulator's answer back - used for terminal specific features
- shell level
- if the shell is forked from inside of screen / tmux
- if the shell is forked from inside of vim
Depending on the TERM type and my terminal's answer back I'll either
include control sequences to set the window title to (simplified version
of) the PS1 prompt. This way I have a good idea from the window title
when selecting minimized windows from lists, where the terminal therein is.
I'm leveraging Zsh's preexec() function to conditionally set the window
title to the command that's being executed if answer back indicates a
supported terminal emulator.
I'm comparing the host name to the value of answer back to set the
prompt color as a simple indicator if I'm on my local system or not.
- Green = terminal to local system
- Yellow = terminal to a non-local system
- Red = terminal as root window somewhere, BE CAREFUL
So ... my Zsh prompt has a fair bit behind it. But the bulk of what's
printed is still the comment character, the username, the hostname, the
current working directory, and the (non)root indicator.
One deviation is that I now have my root prompt (via sudo / su) slightly
different in that after the effective user name, root, the prompt also
includes my real user name in parenthesis.
#[root(gtaylor)@host:~]#
As I do more with containers, I'm getting ready to implement a similar
permutation on the host portion such that the host name portion reflects
the container's / network namespace's value of \h with parent host OS's
name in side of parenthesis, much like the effective / logged in user pair.
#[root(gtaylor)@netns(host):~]#
Post-Script: Happy holidays. Here's hoping that things are going well
for you and yours.
--
Grant. . . .
unix || die
[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4017 bytes --]
[-- Attachment #2: Type: text/plain, Size: 141 bytes --]
_______________________________________________
COFF mailing list
COFF@minnie.tuhs.org
https://minnie.tuhs.org/cgi-bin/mailman/listinfo/coff
next prev parent reply other threads:[~2021-12-24 17:27 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-23 6:59 [COFF] What is your prompt? (was: ksh88 source code?) Andy Kosela
2021-12-23 12:04 ` John P. Linderman
2021-12-23 19:30 ` Nemo Nusquam
2021-12-24 17:17 ` Grant Taylor via COFF [this message]
2021-12-26 22:17 ` [COFF] What is your prompt? Mike Markowski
2021-12-25 2:50 Rudi Blom
2021-12-25 4:40 ` Theodore Ts'o
2021-12-25 17:39 ` Steffen Nurpmeso
2021-12-25 18:28 ` Grant Taylor via COFF
2021-12-25 19:14 ` Steffen Nurpmeso
2021-12-26 3:44 ` Grant Taylor via COFF
2021-12-25 23:19 ` Greg 'groggy' Lehey
2021-12-25 23:43 ` Steffen Nurpmeso
2021-12-26 21:18 ` Theodore Ts'o
2021-12-26 21:33 ` Warner Losh
2021-12-27 1:33 ` Theodore Ts'o
2021-12-27 2:52 ` Rudi Blom
2021-12-27 3:43 ` Greg 'groggy' Lehey
2021-12-27 4:06 ` Rudi Blom
2021-12-27 4:12 ` Greg 'groggy' Lehey
2021-12-27 4:28 ` Rudi Blom
2021-12-27 18:44 ` Steffen Nurpmeso
2021-12-27 18:55 ` Warner Losh
2021-12-27 19:07 ` Grant Taylor via COFF
2021-12-27 19:25 ` Steffen Nurpmeso
2021-12-27 18:37 ` Steffen Nurpmeso
2021-12-26 3:29 ` Grant Taylor via COFF
2021-12-26 3:54 ` Greg 'groggy' Lehey
2021-12-26 5:27 ` Grant Taylor via COFF
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b8df4957-0834-ad5b-7ff2-d44c9cbcacdd@spamtrap.tnetconsulting.net \
--to=coff@minnie.tuhs.org \
--cc=gtaylor@tnetconsulting.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).