Skip to content
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

Add terminal title codes to PS1 #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ Type `fancygit -h` to see all available feature switchers on **"FEATURE SWITCHER
| fancygit --disable-host-name | Hide host name.
| fancygit --enable-user-symbol | Show user symbol.
| fancygit --disable-user-symbol | Hide user symbol.
| fancygit --enable-term-title-host | Enables setting the hostname in the terminal title bar.
| fancygit --disable-term-title-host | Disables setting the hostname in the terminal title bar.
| fancygit --enable-term-title-path | Enables setting the path in the terminal title bar.
| fancygit --disable-term-title-path | Disables setting the path in the terminal title bar.
| fancygit --set-user-name {name} | Set the user name.
| fancygit --unset-user-name | Restore the user name to default.
| fancygit --set-host-name {name} | Set the host name.
Expand Down
4 changes: 4 additions & 0 deletions commands-handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ case "$1" in
"--disable-bold-prompt") fancygit_config_save "bold_prompt" "false";;
"--enable-host-name") fancygit_config_save "show_host_prompt" "true";;
"--disable-host-name") fancygit_config_save "show_host_prompt" "false";;
"--enable-term-title-host") fancygit_config_save "set_term_title_host" "true";;
"--disable-term-title-host") fancygit_config_save "set_term_title_host" "false";;
"--enable-term-title-path") fancygit_config_save "set_term_title_path" "true";;
"--disable-term-title-path") fancygit_config_save "set_term_title_path" "false";;
"--enable-user-symbol") fancygit_config_save "show_user_symbol_prompt" "true";;
"--disable-user-symbol") fancygit_config_save "show_user_symbol_prompt" "false";;

Expand Down
4 changes: 4 additions & 0 deletions fancygit-completion
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ _fancygit() {
--disable-host-name \
--enable-user-symbol \
--disable-user-symbol \
--enable-term-title-host \
--disable-term-title-host \
--enable-term-title-path \
--disable-term-title-path \
--set-user-name \
--unset-user-name \
--set-host-name \
Expand Down
4 changes: 4 additions & 0 deletions help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ FEATURE SWITCHER COMMANDS:
fancygit --disable-bold-prompt Show regular prompt font.
fancygit --enable-host-name Show host name. (It works for human theme only)
fancygit --disable-host-name Hide host name. (It works for human theme only)
fancygit --enable-term-title-host Enables setting the hostname in the terminal title bar.
fancygit --disable-term-title-host Disables setting the hostname in the terminal title bar.
fancygit --enable-term-title-path Enables setting the path in the terminal title bar.
fancygit --disable-term-title-path Disables setting the path in the terminal title bar.

THEME COMMANDS:
fancygit --theme-default Change prompt to the default theme.
Expand Down
16 changes: 14 additions & 2 deletions themes/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fancygit_theme_builder() {
local time_end=""
local prompt_time
local prompt_user
local term_title
local prompt_env
local prompt_path
local prompt_double_line
Expand Down Expand Up @@ -118,13 +119,24 @@ fancygit_theme_builder() {
prompt_user="${user_at_host}${user}${user_name}${none}${none} ${user_at_host_end}"
fi

local term_title_tag="\\[\\e]0;"
if fancygit_config_is "set_term_title_host" "true"
then
term_title_tag="${term_title_tag}\\h:"
fi
if fancygit_config_is "set_term_title_path" "true"
then
term_title_tag="${term_title_tag}\\w"
fi
term_title="${term_title_tag}\\a\\]"

branch_name=$(fancygit_git_get_branch)
if [ "" = "$branch_name" ]
then
# 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="${term_title}${clear}${bold_prompt}${prompt_time}${prompt_user}${prompt_symbol}${prompt_path}${clear}${normal_prompt}${prompt_double_line} "
return
fi

Expand Down Expand Up @@ -156,7 +168,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="${term_title}${clear}${bold_prompt}${prompt_time}${prompt_user}${prompt_symbol}${prompt_path}${prompt_branch}${clear}${normal_prompt}${prompt_double_line} "
}

# Here's where the magic happens!
Expand Down
16 changes: 14 additions & 2 deletions themes/human.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fancygit_theme_builder() {
local venv_name
local prompt_symbol
local prompt_path
local term_title
local bold_prompt=""
local normal_prompt=""

Expand Down Expand Up @@ -90,6 +91,17 @@ fancygit_theme_builder() {
prompt_symbol=""
fi

local term_title_tag="\\[\\e]0;"
if fancygit_config_is "set_term_title_host" "true"
then
term_title_tag="${term_title_tag}\\h:"
fi
if fancygit_config_is "set_term_title_path" "true"
then
term_title_tag="${term_title_tag}\\w"
fi
term_title="${term_title_tag}\\a\\]"

if [ "$branch_status" != "" ]
then
branch="${branch_color_changed_files_font_tag}"
Expand Down Expand Up @@ -136,11 +148,11 @@ fancygit_theme_builder() {
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="${bold_prompt}${PS1}${prompt_symbol}${is_double_line}${normal_prompt} "
PS1="${term_title}${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="${term_title}${bold_prompt}${prompt_time}${prompt_user_at_host}${prompt_path}${venv_name}${prompt_symbol}${is_double_line}${normal_prompt} "
}

# Here's where the magic happens!
Expand Down
14 changes: 13 additions & 1 deletion themes/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fancygit_theme_builder() {
local at="${at_color_font_tag}@${color_reset}"
local path="${workdir_color_font_tag}"
local prompt_time
local term_title
local path_sign
local is_double_line
local venv_name
Expand Down Expand Up @@ -73,12 +74,23 @@ fancygit_theme_builder() {
user_at_host="$user:"
fi

local term_title_tag="\\[\\e]0;"
if fancygit_config_is "set_term_title_host" "true"
then
term_title_tag="${term_title_tag}\\h:"
fi
if fancygit_config_is "set_term_title_path" "true"
then
term_title_tag="${term_title_tag}\\w"
fi
term_title="${term_title_tag}\\a\\]"

if [ "" != "$venv_name" ]
then
venv_name="($venv_name) "
fi

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

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