-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor nixos/bash prompt using bash function #389305
base: master
Are you sure you want to change the base?
Refactor nixos/bash prompt using bash function #389305
Conversation
nixos/modules/programs/bash/bash.nix
Outdated
set_prompt() { | ||
if [ "$TERM" == "dumb" ] || [ ! -n "$INSIDE_EMACS" ]; then | ||
return | ||
fi | ||
|
||
local PROMPT_COLOR="1;31m" | ||
((UID)) && PROMPT_COLOR="1;32m" | ||
if [ -n "$INSIDE_EMACS" ]; then | ||
# Emacs term mode doesn't support xterm title escape sequence (\e]0;) | ||
PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] " | ||
else | ||
PS1="\n\[\033[$PROMPT_COLOR\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\\$\[\033[0m\] " | ||
|
||
# Emacs term mode doesn't support xterm title escape sequence (\e]0;) | ||
if [ ! -n "$INSIDE_EMACS" ]; then | ||
local TITLE="\[\e]0;\u@\h: \w\a\]" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait, forgot inverting the ors to ands...
as the same condition[ ! -n "$INSIDE_EMACS" ]
is showing up in both these blocks, and it being true in first block results in return
rightaway; so, does it mean that the latter block (setting title) will never be run and so can be eliminated?
i tried git-blaming with github's UI, and sifted through these commits; but couldn't figure out the reason for the existence of second block:
if [ "$TERM" == "dumb" ] || [ ! -n "$INSIDE_EMACS" ]; then
return
fi
if [ ! -n "$INSIDE_EMACS" ]; then
local TITLE="\[\e]0;\u@\h: \w\a\]"
fi
... for dumb prompt using guard clause (invert-select logic) rather than nested if-s.
48f852a
to
87460a5
Compare
@@ -87,7 +87,7 @@ in | |||
return | |||
fi | |||
PROMPT_COLOR="1;31m" | |||
local PROMPT_COLOR="1;31m" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this use of local
is based on the observation that this bash variable ain't used anywhere outside this prompt configuration (atleast in this file).
It simplifies the flow of logic and makes it easier to understand.
i was using this value (though read from a
.sh
file) in myprograms.bash.promptInit
for 6 months, and it (seems) to work well with the default gnome terminal emulator and also theAlt-F2
terminals.however, i have not tested it anywhere else nor tested it in this form (i.e. making changes to the underlying implementation itself)
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.