Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ Type `fancygit -h` to see all available feature switchers on **"FEATURE SWITCHER
| fancygit --unset-host-name | Restore the host name to default.
| fancygit --enable-git-clear | Clear the terminal as part of some git aliases
| fancygit --disable-git-clear | Do not clear the terminal with any git aliases
| fancygit --enable-k8s-info | Show current Kubernetes context and namespace.
| fancygit --disable-k8s-info | Hide Kubernetes context and namespace.
| fancygit --separator-default | Change the separator to default style.
| fancygit --separator-blocks | Change the separator to blocks style.
| fancygit --separator-blocks-tiny | Change the separator to blocks-tiny style.
Expand Down
1 change: 1 addition & 0 deletions app_config_sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ host_name:
bold_prompt:false
show_host_prompt:false
show_user_symbol_prompt:false
show_k8s_info:false
fresh_file
2 changes: 2 additions & 0 deletions commands-handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ case "$1" in
"--disable-user-symbol") fancygit_config_save "show_user_symbol_prompt" "false";;
"--enable-git-clear") fancygit_config_save "git_use_clear" "true";;
"--disable-git-clear") fancygit_config_save "git_use_clear" "false";;
"--enable-k8s-info") fancygit_config_save "show_k8s_info" "true";;
"--disable-k8s-info") fancygit_config_save "show_k8s_info" "false";;

# Set Name and Host.
"--set-user-name") fancygit_config_save "user_name" "$2";;
Expand Down
2 changes: 2 additions & 0 deletions fancygit-completion
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ _fancygit() {
--disable-user-symbol \
--enable-git-clear \
--disable-git-clear \
--enable-k8s-info \
--disable-k8s-info \
--set-user-name \
--unset-user-name \
--set-host-name \
Expand Down
2 changes: 2 additions & 0 deletions help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ FEATURE SWITCHER COMMANDS:
fancygit --disable-host-name Hide host name. (It works for human theme only)
fancygit --enable-git-clear Clear the terminal as part of some git aliases
fancygit --disable-git-clear Do not clear the terminal with any git aliases
fancygit --enable-k8s-info Show current Kubernetes context and namespace.
fancygit --disable-k8s-info Hide Kubernetes context and namespace.

THEME COMMANDS:
fancygit --theme-default Change prompt to the default theme.
Expand Down
42 changes: 42 additions & 0 deletions theme-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,48 @@ fancygit_theme_get_double_line() {
echo ""
}

# ----------------------------------------------------------------------------------------------------------------------
# Return the prompt time.
#
# return string Formated time.
# ----------------------------------------------------------------------------------------------------------------------
fancygit_theme_get_k8s_info() {
local show_k8s_info
local context
local namespace

show_k8s_info=$(fancygit_config_get "show_k8s_info" "false")

if [ "true" != "$show_k8s_info" ]
then
echo ""
return
fi

if ! command -v kubectl > /dev/null 2>&1
then
echo ""
return
fi

context=$(kubectl config current-context 2> /dev/null)

if [ "" = "$context" ]
then
echo ""
return
fi

namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)

if [ "" = "$namespace" ]
then
namespace="default"
fi

echo "[$context:$namespace] "
}

# ----------------------------------------------------------------------------------------------------------------------
# Change color scheme.
# Show a warning in case the requested color scheme is not supported by current theme.
Expand Down
6 changes: 4 additions & 2 deletions themes/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fancygit_theme_builder() {
local time="${time_color_bg_tag}${time_color_tag}"
local time_end=""
local prompt_time
local prompt_k8s
local prompt_user
local prompt_env
local prompt_path
Expand Down Expand Up @@ -107,6 +108,7 @@ fancygit_theme_builder() {
prompt_path=$(fancygit_theme_get_path_sign)
prompt_symbol="${user_symbol} \$ ${user_symbol_end}"
prompt_double_line=$(fancygit_theme_get_double_line)
prompt_k8s=$(fancygit_theme_get_k8s_info)

if fancygit_config_is "show_user_at_machine" "true"
then
Expand All @@ -124,7 +126,7 @@ fancygit_theme_builder() {
# No branch found, so we're not in a git repo.
prompt_env=$(__fancygit_get_venv_icon)
prompt_path="${path}${prompt_env} ${prompt_path} ${path_end}${workdir_color_tag}${bg_none}${separator}${none}"
PS1="${clear}${bold_prompt}${prompt_time}${prompt_user}${prompt_symbol}${prompt_path}${clear}${normal_prompt}${prompt_double_line} "
PS1="${clear}${bold_prompt}${prompt_time}${prompt_k8s}${prompt_user}${prompt_symbol}${prompt_path}${clear}${normal_prompt}${prompt_double_line} "
return
fi

Expand Down Expand Up @@ -156,7 +158,7 @@ fancygit_theme_builder() {
notification_area=$(fancygit_get_notification_area "$is_rich_notification")
prompt_path="${path_git}${notification_area} ${prompt_path} ${path_end}"
prompt_branch="${branch} $(fancygit_git_get_branch_icon "${branch_name}") ${branch_name} ${branch_end}"
PS1="${clear}${bold_prompt}${prompt_time}${prompt_user}${prompt_symbol}${prompt_path}${prompt_branch}${clear}${normal_prompt}${prompt_double_line} "
PS1="${clear}${bold_prompt}${prompt_time}${prompt_k8s}${prompt_user}${prompt_symbol}${prompt_path}${prompt_branch}${clear}${normal_prompt}${prompt_double_line} "
}

# Here's where the magic happens!
Expand Down
6 changes: 4 additions & 2 deletions themes/human.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fancygit_theme_builder() {
local staged_files
local is_rich_notification
local prompt_time
local prompt_k8s
local path_sign
local is_double_line
local venv_name
Expand All @@ -81,6 +82,7 @@ fancygit_theme_builder() {
path_sign=$(fancygit_theme_get_path_sign)
is_double_line=$(fancygit_theme_get_double_line)
venv_name=$(fancygit_theme_get_venv_name)
prompt_k8s=$(fancygit_theme_get_k8s_info)

prompt_symbol="${user_symbol}\$${user_symbol_end}"
prompt_path="${path}${path_sign}${path_end}${color_reset}"
Expand Down Expand Up @@ -135,12 +137,12 @@ fancygit_theme_builder() {
then
prompt_path="${path_git}${path_sign}${path_end}"
prompt_branch="${branch}${branch_name}${branch_end}"
PS1="${prompt_time}${prompt_user_at_host}${prompt_path}${venv_name}${preposition_color} on ${prompt_branch}$(fancygit_get_notification_area "$is_rich_notification")"
PS1="${prompt_time}${prompt_k8s}${prompt_user_at_host}${prompt_path}${venv_name}${preposition_color} on ${prompt_branch}$(fancygit_get_notification_area "$is_rich_notification")"
PS1="${bold_prompt}${PS1}${prompt_symbol}${is_double_line}${normal_prompt} "
return
fi

PS1="${bold_prompt}${prompt_time}${prompt_user_at_host}${prompt_path}${venv_name}${prompt_symbol}${is_double_line}${normal_prompt} "
PS1="${bold_prompt}${prompt_time}${prompt_k8s}${prompt_user_at_host}${prompt_path}${venv_name}${prompt_symbol}${is_double_line}${normal_prompt} "
}

# Here's where the magic happens!
Expand Down
5 changes: 4 additions & 1 deletion themes/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fancygit_theme_builder() {
local host_color_font_tag="\\[\\e[38;5;${FANCYGIT_COLOR_SCHEME_HOST_FOREGROUND}m\\]"
local at_color_font_tag="\\[\\e[38;5;${FANCYGIT_COLOR_SCHEME_AT_FOREGROUND}m\\]"
local workdir_color_font_tag="\\[\\e[38;5;${FANCYGIT_COLOR_SCHEME_WORKDIR_FOREGROUND}m\\]"
local k8s_color_font_tag
local color_reset="\\[\\e[39m\\]"

local user_name
Expand All @@ -41,6 +42,7 @@ fancygit_theme_builder() {
local at="${at_color_font_tag}@${color_reset}"
local path="${workdir_color_font_tag}"
local prompt_time
local prompt_k8s
local path_sign
local is_double_line
local venv_name
Expand All @@ -62,6 +64,7 @@ fancygit_theme_builder() {
venv_name=$(fancygit_theme_get_venv_name)
branch_area=$(__fancygit_theme_get_branch_area)
where="${path}${path_sign}${color_reset}"
prompt_k8s=$(fancygit_theme_get_k8s_info)

if fancygit_config_is "show_user_at_machine" "true"
then
Expand All @@ -78,7 +81,7 @@ fancygit_theme_builder() {
venv_name="($venv_name) "
fi

PS1="${bold_prompt}${venv_name}${prompt_time}${user_at_host}$where\$${branch_area}${is_double_line}${normal_prompt} "
PS1="${bold_prompt}${venv_name}${prompt_time}${prompt_k8s}${user_at_host}$where\$${branch_area}${is_double_line}${normal_prompt} "
}

# ----------------------------------------------------------------------------------------------------------------------
Expand Down