From c7c488f0b08f69a58b136da82fbeb4c0f7e3d994 Mon Sep 17 00:00:00 2001 From: Ari Mourao Date: Thu, 9 Feb 2017 14:45:25 -0200 Subject: [PATCH 1/4] enable powerscript to check if user can sudo his workstation --- themes/powerline/README.md | 3 +++ themes/powerline/powerline.base.bash | 6 ++++-- themes/powerline/powerline.theme.bash | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 9ee38271..0f871cdb 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -4,6 +4,9 @@ A colorful theme, where shows a lot information about your shell session. **IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator. +**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If it's not the case (i.e you are running on +a corporate network) you can set the flag 'CAN_SUDO=false' in powerbase.theme.bash + ## Provided Information * Current path diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 3abeda8d..108304e9 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -13,8 +13,10 @@ function __powerline_user_info_prompt { local user_info="" local color=${USER_INFO_THEME_PROMPT_COLOR} - if sudo -n uptime 2>&1 | grep -q "load"; then - color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + if ${CAN_SUDO}; then + if sudo -n uptime 2>&1 | grep -q "load"; then + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + fi fi case "${POWERLINE_PROMPT_USER_INFO_MODE}" in "sudo") diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 12de9cbe..c71b9c1a 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -2,6 +2,8 @@ . "$BASH_IT/themes/powerline/powerline.base.bash" +CAN_SUDO=true + PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""} POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""} From 7415c85ed818321a7564c566d58dbc11e68af9b9 Mon Sep 17 00:00:00 2001 From: Ari Mourao Date: Thu, 9 Feb 2017 15:22:49 -0200 Subject: [PATCH 2/4] corrected typo --- themes/powerline/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 0f871cdb..c92ecd36 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -5,7 +5,7 @@ A colorful theme, where shows a lot information about your shell session. **IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator. **NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If it's not the case (i.e you are running on -a corporate network) you can set the flag 'CAN_SUDO=false' in powerbase.theme.bash +a corporate network) you can set the flag 'CAN_SUDO=false' in powerline.theme.bash ## Provided Information From 4eeb98772b687ff51b5838f1eb2f601d0d985010 Mon Sep 17 00:00:00 2001 From: Ari Mourao Date: Fri, 10 Feb 2017 16:43:22 -0200 Subject: [PATCH 3/4] added suggested improvements --- themes/powerline/README.md | 2 +- themes/powerline/powerline.base.bash | 2 +- themes/powerline/powerline.theme.bash | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/powerline/README.md b/themes/powerline/README.md index c92ecd36..96108f1f 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -5,7 +5,7 @@ A colorful theme, where shows a lot information about your shell session. **IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator. **NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If it's not the case (i.e you are running on -a corporate network) you can set the flag 'CAN_SUDO=false' in powerline.theme.bash +a corporate network) you can set the flag 'THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=false}' in powerline.theme.bash ## Provided Information diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 108304e9..a911d12b 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -13,7 +13,7 @@ function __powerline_user_info_prompt { local user_info="" local color=${USER_INFO_THEME_PROMPT_COLOR} - if ${CAN_SUDO}; then + if [[ "THEME_CHECK_SUDO" = true ]]; then if sudo -n uptime 2>&1 | grep -q "load"; then color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} fi diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index c71b9c1a..d2338fc7 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -2,7 +2,7 @@ . "$BASH_IT/themes/powerline/powerline.base.bash" -CAN_SUDO=true +THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""} POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""} From 7d9628d4f507952dabe88fd502292ca863ae5a70 Mon Sep 17 00:00:00 2001 From: Ari Mourao Date: Sun, 12 Feb 2017 14:03:45 -0200 Subject: [PATCH 4/4] refactoring to comply with standards --- themes/powerline/README.md | 2 +- themes/powerline/powerline.base.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/powerline/README.md b/themes/powerline/README.md index 96108f1f..512461fb 100644 --- a/themes/powerline/README.md +++ b/themes/powerline/README.md @@ -5,7 +5,7 @@ A colorful theme, where shows a lot information about your shell session. **IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator. **NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If it's not the case (i.e you are running on -a corporate network) you can set the flag 'THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=false}' in powerline.theme.bash +a corporate network) you can set the flag 'THEME_CHECK_SUDO=false' in your ~/.bashrc or ~/.bash_profile ## Provided Information diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index a911d12b..ff039c7a 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -13,7 +13,7 @@ function __powerline_user_info_prompt { local user_info="" local color=${USER_INFO_THEME_PROMPT_COLOR} - if [[ "THEME_CHECK_SUDO" = true ]]; then + if [[ "${THEME_CHECK_SUDO}" = true ]]; then if sudo -n uptime 2>&1 | grep -q "load"; then color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} fi