Gentoo Archives: gentoo-user

From: Grant Taylor <gtaylor@×××××××××××××××××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Bash prompt colours
Date: Tue, 07 Dec 2021 17:26:14
Message-Id: d5cdcf94-a90f-4a15-9d25-c110dc85ed39@spamtrap.tnetconsulting.net
In Reply to: Re: [gentoo-user] Bash prompt colours by Frank Steinmetzger
1 Some drive-by after-the-fact comments:
2
3 On 12/6/21 4:03 PM, Frank Steinmetzger wrote:
4 > [ "$MC_SID" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}MC "
5 > [ "$RANGER_LEVEL" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}R "
6
7 I've taken to using things like the following:
8
9 PS1_JOBS_COUNT="${PS1_JOBS_COUNT}${MC_SID:+MC }${RANGER_LEVEL:+R }"
10
11 Leverage Bash's (and Zsh's) expansion conditional. If the variable is
12 set, then expand it to a different value.
13
14 ${VARIABLE:+alternate text to show if VARIABLE is set}
15
16 > if [[ -z "$PROMPT_COMMAND" ]]; then
17 > PROMPT_COMMAND=__jobsprompt
18 > else
19 > PROMPT_COMMAND="$PROMPT_COMMAND ; __jobsprompt"
20 > fi
21
22 Is there a reason to not simply do the following, eliminating the if
23 conditional:
24
25 PROMPT_COMMAND=${PROMPT_COMMAND:+${PROMPT_COMMAND} ; __jobsprompt}
26
27
28
29 --
30 Grant. . . .
31 unix || die

Replies

Subject Author
Re: [gentoo-user] Bash prompt colours Frank Steinmetzger <Warp_7@×××.de>