From 8ce9d8daa56de7998b853c1151c4faa291119145 Mon Sep 17 00:00:00 2001 From: Kan Li Date: Sat, 28 Nov 2020 12:05:36 -0800 Subject: [PATCH 1/2] Add in_toolbox prompt to powerline themes [Toolbox](https://github.com/containers/toolbox) is an containerized development environment. This commit adds a promot to powerline when it is running inside a toolbox. --- themes/gitline/gitline.theme.bash | 3 +++ themes/gitline/powerline.base.bash | 18 +++++++++++++----- themes/powerline-multiline/README.md | 1 + .../powerline-multiline.theme.bash | 3 +++ themes/powerline-naked/README.md | 1 + .../powerline-naked/powerline-naked.theme.bash | 3 +++ themes/powerline-plain/README.md | 1 + .../powerline-plain/powerline-plain.theme.bash | 3 +++ themes/powerline/README.md | 1 + themes/powerline/powerline.base.bash | 6 ++++++ themes/powerline/powerline.theme.bash | 3 +++ themes/redline/redline.theme.bash | 3 +++ 12 files changed, 41 insertions(+), 5 deletions(-) diff --git a/themes/gitline/gitline.theme.bash b/themes/gitline/gitline.theme.bash index 995b8c0744..ef0bdae0b9 100644 --- a/themes/gitline/gitline.theme.bash +++ b/themes/gitline/gitline.theme.bash @@ -64,5 +64,8 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} IN_VIM_THEME_PROMPT_COLOR=245 IN_VIM_THEME_PROMPT_TEXT="vim" +IN_TOOLBOX_THEME_PROMPT_COLOR=125 +IN_TOOLBOX_THEME_PROMPT_TEXT=" " + safe_append_prompt_command __powerline_prompt_command diff --git a/themes/gitline/powerline.base.bash b/themes/gitline/powerline.base.bash index 0f8a30281e..93be7d2f24 100644 --- a/themes/gitline/powerline.base.bash +++ b/themes/gitline/powerline.base.bash @@ -120,13 +120,13 @@ function __powerline_cwd_prompt { } function __powerline_hostname_prompt { - local fg_color=206 + local fg_color=206 - echo "$(hostname -s)|${HOST_THEME_PROMPT_COLOR}|${fg_color}" + echo "$(hostname -s)|${HOST_THEME_PROMPT_COLOR}|${fg_color}" } function __powerline_wd_prompt { - local fg_color=206 + local fg_color=206 echo "\W|${CWD_THEME_PROMPT_COLOR}|${fg_color}" } @@ -158,7 +158,7 @@ function __powerline_battery_prompt { } function __powerline_in_vim_prompt { - local fg_color=206 + local fg_color=206 if [ -n "$VIMRUNTIME" ]; then echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}|${fg_color}" @@ -166,13 +166,21 @@ function __powerline_in_vim_prompt { } function __powerline_aws_profile_prompt { - local fg_color=206 + local fg_color=206 if [[ -n "${AWS_PROFILE}" ]]; then echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}|${fg_color}" fi } +function __powerline_in_toolbox_prompt { + local fg_color=206 + + if [[ -e /run/.toolboxenv ]]; then + echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}|${fg_color}" + fi +} + function __powerline_left_segment { local OLD_IFS="${IFS}"; IFS="|" local params=( $1 ) diff --git a/themes/powerline-multiline/README.md b/themes/powerline-multiline/README.md index da66d4ef24..2654ff1c57 100644 --- a/themes/powerline-multiline/README.md +++ b/themes/powerline-multiline/README.md @@ -59,6 +59,7 @@ The contents of both prompt sides can be "reordered", all the "segments" (every * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine +* `in_toolbox` - Show identifier if running inside a toolbox * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 54651cb638..da874718c1 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -74,6 +74,9 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} +IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="❲T❳ "} + HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=0} SHLVL_THEME_PROMPT_COLOR=${POWERLINE_SHLVL_COLOR:=${HOST_THEME_PROMPT_COLOR}} diff --git a/themes/powerline-naked/README.md b/themes/powerline-naked/README.md index ec3b8fac59..debdc1bde3 100644 --- a/themes/powerline-naked/README.md +++ b/themes/powerline-naked/README.md @@ -52,6 +52,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine +* `in_toolbox` - Show identifier if running inside a toolbox * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 5c5fed269e..89713d4a53 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -69,6 +69,9 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} +IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="❲T❳ "} + HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=254} SHLVL_THEME_PROMPT_COLOR=${POWERLINE_SHLVL_COLOR:=${HOST_THEME_PROMPT_COLOR}} diff --git a/themes/powerline-plain/README.md b/themes/powerline-plain/README.md index 0a8a75addc..019078c4bf 100644 --- a/themes/powerline-plain/README.md +++ b/themes/powerline-plain/README.md @@ -50,6 +50,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine +* `in_toolbox` - Show identifier if running inside a toolbox * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 6ae81a5680..c65d57601b 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -66,6 +66,9 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} +IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="Ⓣ "} + HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=0} SHLVL_THEME_PROMPT_COLOR=${POWERLINE_SHLVL_COLOR:=${HOST_THEME_PROMPT_COLOR}} diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 587e0788ff..251a1b5024 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -58,6 +58,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine +* `in_toolbox` - Show identifier if running inside a toolbox * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index b259679360..aca9f1e356 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -169,6 +169,12 @@ function __powerline_aws_profile_prompt() { fi } +function __powerline_in_toolbox_prompt() { + if [[ -e /run/.toolboxenv ]]; then + echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}" + fi +} + function __powerline_shlvl_prompt() { if [[ "${SHLVL}" -gt 1 ]]; then local prompt="${SHLVL_THEME_PROMPT_CHAR}" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 1463d7778f..09fb67472e 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -71,6 +71,9 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} +IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="❲T❳ "} + HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=0} SHLVL_THEME_PROMPT_COLOR=${POWERLINE_SHLVL_COLOR:=${HOST_THEME_PROMPT_COLOR}} diff --git a/themes/redline/redline.theme.bash b/themes/redline/redline.theme.bash index 3d67e8a5ae..e1f2a283c7 100644 --- a/themes/redline/redline.theme.bash +++ b/themes/redline/redline.theme.bash @@ -55,6 +55,9 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} IN_VIM_THEME_PROMPT_COLOR=245 IN_VIM_THEME_PROMPT_TEXT="vim" +IN_TOOLBOX_THEME_PROMPT_COLOR=125 +IN_TOOLBOX_THEME_PROMPT_TEXT=" " + POWERLINE_PROMPT=${POWERLINE_PROMPT:="python_venv ruby user_info hostname cwd scm"} safe_append_prompt_command __powerline_prompt_command From c13850faa2a3eef8ac9f10bf62ad3c41e0f37f48 Mon Sep 17 00:00:00 2001 From: Kan Li Date: Sat, 28 Nov 2020 18:49:25 -0800 Subject: [PATCH 2/2] Address some comments. --- themes/gitline/gitline.theme.bash | 2 +- themes/gitline/powerline.base.bash | 2 +- themes/powerline-multiline/README.md | 2 +- themes/powerline-multiline/powerline-multiline.theme.bash | 2 +- themes/powerline-naked/README.md | 2 +- themes/powerline-naked/powerline-naked.theme.bash | 2 +- themes/powerline-plain/README.md | 2 +- themes/powerline-plain/powerline-plain.theme.bash | 2 +- themes/powerline/README.md | 2 +- themes/powerline/powerline.base.bash | 2 +- themes/powerline/powerline.theme.bash | 2 +- themes/redline/redline.theme.bash | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/themes/gitline/gitline.theme.bash b/themes/gitline/gitline.theme.bash index ef0bdae0b9..9a68f3703f 100644 --- a/themes/gitline/gitline.theme.bash +++ b/themes/gitline/gitline.theme.bash @@ -65,7 +65,7 @@ IN_VIM_THEME_PROMPT_COLOR=245 IN_VIM_THEME_PROMPT_TEXT="vim" IN_TOOLBOX_THEME_PROMPT_COLOR=125 -IN_TOOLBOX_THEME_PROMPT_TEXT=" " +IN_TOOLBOX_THEME_PROMPT_TEXT="⬢ " safe_append_prompt_command __powerline_prompt_command diff --git a/themes/gitline/powerline.base.bash b/themes/gitline/powerline.base.bash index 93be7d2f24..4f6b17b06b 100644 --- a/themes/gitline/powerline.base.bash +++ b/themes/gitline/powerline.base.bash @@ -176,7 +176,7 @@ function __powerline_aws_profile_prompt { function __powerline_in_toolbox_prompt { local fg_color=206 - if [[ -e /run/.toolboxenv ]]; then + if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}|${fg_color}" fi } diff --git a/themes/powerline-multiline/README.md b/themes/powerline-multiline/README.md index 2654ff1c57..8f29f0088e 100644 --- a/themes/powerline-multiline/README.md +++ b/themes/powerline-multiline/README.md @@ -59,7 +59,7 @@ The contents of both prompt sides can be "reordered", all the "segments" (every * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine -* `in_toolbox` - Show identifier if running inside a toolbox +* `in_toolbox` - Show identifier if running inside a [toolbox](https://github.com/containers/toolbox) * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index da874718c1..a86eac3cbd 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -75,7 +75,7 @@ IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} -IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="❲T❳ "} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="⬢ "} HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=0} diff --git a/themes/powerline-naked/README.md b/themes/powerline-naked/README.md index debdc1bde3..bb70986965 100644 --- a/themes/powerline-naked/README.md +++ b/themes/powerline-naked/README.md @@ -52,7 +52,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine -* `in_toolbox` - Show identifier if running inside a toolbox +* `in_toolbox` - Show identifier if running inside a [toolbox](https://github.com/containers/toolbox) * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 89713d4a53..7a5bd4ed74 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -70,7 +70,7 @@ IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} -IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="❲T❳ "} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="⬢ "} HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=254} diff --git a/themes/powerline-plain/README.md b/themes/powerline-plain/README.md index 019078c4bf..bdd9fdd8aa 100644 --- a/themes/powerline-plain/README.md +++ b/themes/powerline-plain/README.md @@ -50,7 +50,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine -* `in_toolbox` - Show identifier if running inside a toolbox +* `in_toolbox` - Show identifier if running inside a [toolbox](https://github.com/containers/toolbox) * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index c65d57601b..b2a290a518 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -67,7 +67,7 @@ IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} -IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="Ⓣ "} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="⬢ "} HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=0} diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 251a1b5024..edb87de922 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -58,7 +58,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * `clock` - Current time in `HH:MM:SS` format * `cwd` - Current working directory including full folder hierarchy (c.f. `wd`) * `hostname` - Host name of machine -* `in_toolbox` - Show identifier if running inside a toolbox +* `in_toolbox` - Show identifier if running inside a [toolbox](https://github.com/containers/toolbox) * `in_vim` - Show identifier if running in `:terminal` from vim * `k8s_context` - Show current kubernetes context * `last_status` - Exit status of last run command diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index aca9f1e356..38c5c89526 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -170,7 +170,7 @@ function __powerline_aws_profile_prompt() { } function __powerline_in_toolbox_prompt() { - if [[ -e /run/.toolboxenv ]]; then + if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}" fi } diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 09fb67472e..83731614cc 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -72,7 +72,7 @@ IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245} IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"} IN_TOOLBOX_THEME_PROMPT_COLOR=${POWERLINE_IN_TOOLBOX_COLOR:=125} -IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="❲T❳ "} +IN_TOOLBOX_THEME_PROMPT_TEXT=${POWERLINE_IN_TOOLBOX_TEXT:="⬢ "} HOST_THEME_PROMPT_COLOR=${POWERLINE_HOST_COLOR:=0} diff --git a/themes/redline/redline.theme.bash b/themes/redline/redline.theme.bash index e1f2a283c7..e8810106b4 100644 --- a/themes/redline/redline.theme.bash +++ b/themes/redline/redline.theme.bash @@ -56,7 +56,7 @@ IN_VIM_THEME_PROMPT_COLOR=245 IN_VIM_THEME_PROMPT_TEXT="vim" IN_TOOLBOX_THEME_PROMPT_COLOR=125 -IN_TOOLBOX_THEME_PROMPT_TEXT=" " +IN_TOOLBOX_THEME_PROMPT_TEXT="⬢ " POWERLINE_PROMPT=${POWERLINE_PROMPT:="python_venv ruby user_info hostname cwd scm"}