Please review this patch instead of the one I earlier.
In the last patch, zsh will have a red end character if the last
command has non-zero exit code. And I added this functionality to
bash as well.
I also wrap the code in functions so and made the variable local.
Also, I used the hooks in bash and zsh.
---
50-prompt.sh | 84 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 60 insertions(+), 24 deletions(-)
diff --git a/50-prompt.sh b/50-prompt.sh
index 753f418..5fba2de 100644
--- a/50-prompt.sh
+++ b/50-prompt.sh
@@ -1,25 +1,61 @@
-if [ -n "$ZSH_VERSION" ]; then
- exit 0
+# Set prompt and title (for interactive shells only)
+if [ "$(expr $- : '.*i')" -ne 0 ]; then
+ # this works for sh and bash
+ if [ -z "$ZSH_VERSION" ]; then
+ __stateless_prompt() {
+ local EXIT="$?" # exit code of last command
+ local BLUE="\[\e[38;5;39m\]"
+ local RED="\[\e[31m\]"
+ local ORANGE="\[\e[38;5;208m\]"
+ local WHITE="\[\e[0m\]"
+ # endchar and username
+ local endchar="\$${WHITE}" # $ for non-root users
+ local username="${BLUE}\u${WHITE}" # blue(39) for non-root
+ if [ "$UID" = "0" ]; then
+ endchar="#${WHITE}" # # for root user
+ username="${RED}\u${WHITE}" # red for root
+ fi
+ if [ "$EXIT" -eq 0 ]; then
+ endchar="${WHITE}$endchar" # White enchar as default
+ else
+ endchar="${RED}$endchar" # Red endchar for error
+ fi
+ # hostname in orange
+ local host="${ORANGE}\H${WHITE}"
+ # current directory in blue(39)
+ local dir="${BLUE}\w${WHITE}"
+ # set prompt
+ export PS1="${username}@${host} ${dir} ${endchar} "
+ # set window title for xterm
+ if [ "${TERM:0:5}" = "xterm" ]; then
+ export PS1="\[\e]2;\u@\H :: \w\a\]$PS1"
+ fi
+ }
+ export PROMPT_COMMAND=__stateless_prompt
+ else
+ # this works for zsh
+ __stateless_prompt() { # set prompt
+ # endchar
+ # use red if last command has non-zero exit
+ # use # for root and $ for non-root users
+ local root_endch="%(?.#.%F{red}#%f)"
+ local other_endch="%(?.$.%F{red}$%f)"
+ local endchar="%(#.${root_endch}.${other_endch})"
+ # use red for root and blue(39) for non-root users
+ local username="%F{%(#.red.39)}%n%f"
+ # hostname in orange
+ local host="%F{208}%m%f"
+ # current directory in blue(39)
+ local dir="%F{39}%~%f"
+ export PS1="${username}@${host} ${dir} ${endchar} "
+ }
+ __stateless_title () { # for xterm, set window title
+ if [ "${TERM:0:5}" = "xterm" ]; then
+ print -Pn "\e]2;%n@%m :: %~\a"
+ fi
+ }
+ autoload -Uz add-zsh-hook
+ add-zsh-hook preexec __stateless_prompt
+ add-zsh-hook precmd __stateless_title
+ fi
fi
-
-endchar="\$"
-if [ "$UID" = "0" ]; then
- endchar="#"
-fi
-
-# Blue
-BG="\[\e[38;5;39m\]"
-# RGBA index:
-#BG="\[\e[38;2;255;142;58m\]"
-
-# Orange
-FG="\[\e[38;5;208m\]"
-# RGBA index:
-#FG="\[\e[38;2;0;174;255m\]"
-
-export PS1="$BG\u\[\e[0m\]@$FG\H ${BG}\w ${BG}$endchar \[\e[0;0m\]"
-if [ "${TERM:0:5}" = "xterm" ]; then
- export PS1="\[\e]2;\u@\H :: \w\a\]$PS1"
-fi
-
-shopt -s checkwinsize
--
2.21.0
The 'futures' package provides concurrent.futures, which has been
available since Python 3.2. OpenStack is currently using Python 3.6, so
this bundle does not require the package.
Signed-off-by: Patrick McCarty <patrick.mccarty(a)intel.com>
---
bundles/openstack-common | 1 -
1 file changed, 1 deletion(-)
diff --git a/bundles/openstack-common b/bundles/openstack-common
index 836e14ee..dc08c82e 100644
--- a/bundles/openstack-common
+++ b/bundles/openstack-common
@@ -18,7 +18,6 @@ debtcollector
elixir
funcsigs
functools32
-futures
include(haproxy)
iso8601
jsonschema
--
2.21.0
This is a part of a bigger plan that bourne compatible shells shall
have a same set of default profiles.
This patch shall be applied on `50-prompt.sh` in
`clearlinux-pkgs/filesystem`, it includes the following:
1. It would be set the prompt correctly for both bash and zsh.
Currently the prompt for bash is defined here, but the prompt for
zsh is set in `/usr/share/defaults/. Moreover, their prompts are
not identical.
2. The color for bash prompt is not set correctly, it's fixed here.
3. The end character for zsh is not set correctly, as well as the
color, which are both fixed now.
4. When the terminal is xterm*, this file sets the title for both
bash and zsh. Currently the prompt for bash is defined here, but
it's not set for zsh.
5. Refactored variable names to increase readability.
This patch will requires the changes in the following:
1. `profile.x86_64` and `profile.i386` in `clearlinux-pkgs/filesystem`
shall not set anything related to prompt.
2. `0001-stateless-configuration.patch` in `clearlinux-pkgs/zsh`
shall be patched so that `zshrc` won't set the prompt.
This has been tested locally for sh (aliased to bash), bash, and zsh.
---
50-prompt.sh | 70 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 46 insertions(+), 24 deletions(-)
diff --git a/50-prompt.sh b/50-prompt.sh
index 753f418..94709ae 100644
--- a/50-prompt.sh
+++ b/50-prompt.sh
@@ -1,25 +1,47 @@
-if [ -n "$ZSH_VERSION" ]; then
- exit 0
+# Set prompt (for interactive bash and zsh shells only)
+if [ "$PS1" ]; then
+ if [ -n "$BASH_VERSION" ]; then
+ BLUE="\[\e[38;5;39m\]" # Blue
+ RED="\[\e[31m\]" #Red
+ ORANGE="\[\e[38;5;208m\]" # Orange
+ WHITE="\[\e[0m\]"
+ # endchar and username
+ # Use red for root and blue(39) for non-root users
+ username="${BLUE}\u${WHITE}"
+ endchar="${BLUE}\$${WHITE}" # $ for normal users
+ if [ "$UID" = "0" ]; then
+ username="${BLUE}\u${WHITE}"
+ endchar="${RED}#${WHITE}" # # for root user
+ fi
+ # host in orange
+ host="${ORANGE}\H${WHITE}"
+ # current directory in blue(39)
+ dir="${BLUE}\w${WHITE}"
+ # set prompt
+ export PS1="${username}@${host} ${dir} ${endchar} "
+ # set window title for xterm
+ if [ "${TERM:0:5}" = "xterm" ]; then
+ export PS1="\[\e]2;\u@\H :: \w\a\]$PS1"
+ fi
+ elif [ -n "$ZSH_VERSION" ]; then
+ # endchar
+ root_endch="%(?.#.%F{red}#%f)"
+ other_endch="%(?.$.%F{red}$%f)"
+ endchar="%(#.${root_endch}.${other_endch})"
+ # use red for root and blue(39) for non-root users
+ username="%F{%(#.red.39)}%n%f"
+ # host in orange
+ host="%F{208}%m%f"
+ # current directory in blue(39)
+ dir="%F{39}%~%f"
+ export PS1="${username}@${host} ${dir} ${endchar} "
+ # For xterm, set window title
+ if [ "${TERM:0:5}" = "xterm" ]; then
+ autoload -Uz add-zsh-hook
+ _stateless_precmd () {
+ print -Pn "\e]0;%n@%m :: %~\a$PS1"
+ }
+ add-zsh-hook precmd _stateless_precmd
+ fi
+ fi
fi
-
-endchar="\$"
-if [ "$UID" = "0" ]; then
- endchar="#"
-fi
-
-# Blue
-BG="\[\e[38;5;39m\]"
-# RGBA index:
-#BG="\[\e[38;2;255;142;58m\]"
-
-# Orange
-FG="\[\e[38;5;208m\]"
-# RGBA index:
-#FG="\[\e[38;2;0;174;255m\]"
-
-export PS1="$BG\u\[\e[0m\]@$FG\H ${BG}\w ${BG}$endchar \[\e[0;0m\]"
-if [ "${TERM:0:5}" = "xterm" ]; then
- export PS1="\[\e]2;\u@\H :: \w\a\]$PS1"
-fi
-
-shopt -s checkwinsize
--
2.21.0
On Tuesday, 28 May 2019 11:16:25 PDT Douglas, William wrote:
> I'm really not eager to add our own file formats that have to have
> more custom parsing done on them, just more things for users to mixup
> and our code to get wrong (which is why I went with an existing format
> to begin with). Being able to reuse the current parser is the main
> benefit I see to moving to a flatter file structure. My aversion to
> writing specfile like excerpts as config is also pretty high.
>
> What do you think about having autospec format the config files
> consistently (always have files and requires config sections in the
> same order and lays out the entries of each section in a shell
> friendly way)?
What I really want is the shell-friendliness. Basically, that each line is an
exact file name, no quoting, no escaping.
I am ok with enforcing the file format for all of our input files. Of course,
not all of them make sense with all content (excludes has no Requires, for
example).
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel System Software Products
From: Lucius Hu <lebensterben(a)users.noreply.github.com>
Please disregard my previous submit.
The correct order of profiles to be sourced shall be the default profile
'/usr/share/defaults/etc/profile', the system admin overrides
'/etc/profile', and the per-user profile '$HOME/.profile'.
---
lightdm-session | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lightdm-session b/lightdm-session
index 4a2a25e..6934da9 100644
--- a/lightdm-session
+++ b/lightdm-session
@@ -5,7 +5,7 @@
echo "Running X session wrapper"
# Load profile
-for file in "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
+for file in "/usr/share/defaults/etc/profile" "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
if [ -f "$file" ]; then
echo "Loading profile from $file";
. "$file"
--
2.21.0
This makes the `lightdm-session` to be consistent with `Xsession` of `gdm`.
---
lightdm-session | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lightdm-session b/lightdm-session
index 4a2a25e..d8fa964 100644
--- a/lightdm-session
+++ b/lightdm-session
@@ -5,7 +5,7 @@
echo "Running X session wrapper"
# Load profile
-for file in "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
+for file in "/etc/profile" "/usr/share/defaults/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
if [ -f "$file" ]; then
echo "Loading profile from $file";
. "$file"
--
2.21.0