From 6a74231e7a3835a2e0d03644866158913e2d4547 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 12 Oct 2017 16:52:34 +0700 Subject: [PATCH 01/14] New Theme: ys-pep Created a new theme "ys-pep" derived from the "ys" theme --- themes/ys-pep.zsh-theme | 92 ++++++++++++++++++++++++++++++++++++ themes/ys-pep.zsh-theme.orig | 79 +++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 themes/ys-pep.zsh-theme create mode 100644 themes/ys-pep.zsh-theme.orig diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme new file mode 100644 index 000000000..6fa5e1350 --- /dev/null +++ b/themes/ys-pep.zsh-theme @@ -0,0 +1,92 @@ +# ys-pep Theme, based on ys Theme by Yad Smood +# +# ----- BEGIN Original Description ----- +# +# Clean, simple, compatible and meaningful. +# Tested on Linux, Unix and Windows under ANSI colors. +# It is recommended to use with a dark background. +# Colors: black, red, green, yellow, *blue, magenta, cyan, and white. +# +# Mar 2013 Yad Smood +# +# ----- END Original Description ----- +# +# Changes to ys theme: +# * Move timestamp to the front and make it darker +# * List current IP addresses +# * GCE hook (for controlling Google Cloud) +# * Virtualenv hook +# +# Sep-Oct 2017 Pandu POLUAN + +# VCS +YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} " +YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}" +YS_VCS_PROMPT_SUFFIX="%{$reset_color%}" +YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x" +YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o" + +# Git info +local git_info='$(git_prompt_info)' +ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}" +ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX" +ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY" +ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN" + +# HG info +local hg_info='$(ys_hg_prompt_info)' +ys_hg_prompt_info() { + # make sure this is a hg dir + if [ -d '.hg' ]; then + echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}" + echo -n $(hg branch 2>/dev/null) + if [ -n "$(hg status 2>/dev/null)" ]; then + echo -n "$YS_VCS_PROMPT_DIRTY" + else + echo -n "$YS_VCS_PROMPT_CLEAN" + fi + echo -n "$YS_VCS_PROMPT_SUFFIX" + fi +} + +local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%} )" + +### BEGIN: pepoluan changes ### +local dgrey="$terminfo[bold]$fg[black]" + +# Local need: Show the GCE_PROJECT var +local gce_env="%{\${GCE_PROJECT:+$fg[yellow] GCE:}\$GCE_PROJECT$reset_color%}" + +# Show my IP Address +yspep_my_ip() { + echo $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') +} +local ip_info='$(yspep_my_ip)' + +# Show Virtualenv +ZSH_THEME_VIRTUALENV_PREFIX=" V:" +ZSH_THEME_VIRTUALENV_SUFFIX=" " +local venv_info="%{$terminfo[bold]$fg[blue]\$(virtualenv_prompt_info)$reset_color%}" + +# Prompt format: +# +# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE V:VIRTUALENV +# $ COMMAND +# +# For example: +# +# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0 +# $ +PROMPT=" +%{$dgrey%}[%*]%{$reset_color%} \ +%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n)\ +%{$fg[white]%}@%{$fg[green]%}%m\ +%{$dgrey%}[%{$fg[green]%}$ip_info%{$dgrey%}]::%{$reset_color%}\ +%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ +${hg_info}\ +${git_info}\ + $exit_code$gce_env$venv_info +%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" + +unset RPROMPT + diff --git a/themes/ys-pep.zsh-theme.orig b/themes/ys-pep.zsh-theme.orig new file mode 100644 index 000000000..aa091bb8d --- /dev/null +++ b/themes/ys-pep.zsh-theme.orig @@ -0,0 +1,79 @@ +# Clean, simple, compatible and meaningful. +# Tested on Linux, Unix and Windows under ANSI colors. +# It is recommended to use with a dark background. +# Colors: black, red, green, yellow, *blue, magenta, cyan, and white. +# +# Mar 2013 Yad Smood + +# VCS +YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} " +YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}" +YS_VCS_PROMPT_SUFFIX="%{$reset_color%}" +YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x" +YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o" + +# Git info +local git_info='$(git_prompt_info)' +ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}" +ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX" +ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY" +ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN" + +# HG info +local hg_info='$(ys_hg_prompt_info)' +ys_hg_prompt_info() { + # make sure this is a hg dir + if [ -d '.hg' ]; then + echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}" + echo -n $(hg branch 2>/dev/null) + if [ -n "$(hg status 2>/dev/null)" ]; then + echo -n "$YS_VCS_PROMPT_DIRTY" + else + echo -n "$YS_VCS_PROMPT_CLEAN" + fi + echo -n "$YS_VCS_PROMPT_SUFFIX" + fi +} + +local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%} )" + +### BEGIN: pepoluan changes ### + +# Local need: Show the GCE_PROJECT var +local gce_env="%{\${GCE_PROJECT:+$fg[yellow]GCE:}\$GCE_PROJECT$reset_color%}" + +# Show my IP Address +yspep_my_ip() { + echo $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') +} +local ip_info='$(yspep_my_ip)' + +# Show Virtualenv +ZSH_THEME_VIRTUALENV_PREFIX=" V:" +ZSH_THEME_VIRTUALENV_SUFFIX=" " +local venv_info="%{$terminfo[bold]$fg[blue]\$(virtualenv_prompt_info)$reset_color%}" + +# Prompt format: +# +# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE V:VIRTUALENV +# $ COMMAND +# +# For example: +# +# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0 +# $ +PROMPT=" +%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \ +%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n)\ +%{$fg[white]%}@%{$fg[green]%}%m\ +%{$fg[white]%}[%{$fg[green]%}$ip_info\ +%{$fg[white]%}]::\ +%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ +${hg_info}\ +${git_info}\ + \ +%{$fg[white]%}[%*] $exit_code$gce_env$venv_info +%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" + +unset RPROMPT + From 56b830b69e37fa60ca74f0c9e09b929e042915ef Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 12 Oct 2017 22:16:03 +0700 Subject: [PATCH 02/14] Remove .orig files --- themes/ys-pep.zsh-theme.orig | 79 ------------------------------------ 1 file changed, 79 deletions(-) delete mode 100644 themes/ys-pep.zsh-theme.orig diff --git a/themes/ys-pep.zsh-theme.orig b/themes/ys-pep.zsh-theme.orig deleted file mode 100644 index aa091bb8d..000000000 --- a/themes/ys-pep.zsh-theme.orig +++ /dev/null @@ -1,79 +0,0 @@ -# Clean, simple, compatible and meaningful. -# Tested on Linux, Unix and Windows under ANSI colors. -# It is recommended to use with a dark background. -# Colors: black, red, green, yellow, *blue, magenta, cyan, and white. -# -# Mar 2013 Yad Smood - -# VCS -YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} " -YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}" -YS_VCS_PROMPT_SUFFIX="%{$reset_color%}" -YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x" -YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o" - -# Git info -local git_info='$(git_prompt_info)' -ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}" -ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX" -ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY" -ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN" - -# HG info -local hg_info='$(ys_hg_prompt_info)' -ys_hg_prompt_info() { - # make sure this is a hg dir - if [ -d '.hg' ]; then - echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}" - echo -n $(hg branch 2>/dev/null) - if [ -n "$(hg status 2>/dev/null)" ]; then - echo -n "$YS_VCS_PROMPT_DIRTY" - else - echo -n "$YS_VCS_PROMPT_CLEAN" - fi - echo -n "$YS_VCS_PROMPT_SUFFIX" - fi -} - -local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%} )" - -### BEGIN: pepoluan changes ### - -# Local need: Show the GCE_PROJECT var -local gce_env="%{\${GCE_PROJECT:+$fg[yellow]GCE:}\$GCE_PROJECT$reset_color%}" - -# Show my IP Address -yspep_my_ip() { - echo $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') -} -local ip_info='$(yspep_my_ip)' - -# Show Virtualenv -ZSH_THEME_VIRTUALENV_PREFIX=" V:" -ZSH_THEME_VIRTUALENV_SUFFIX=" " -local venv_info="%{$terminfo[bold]$fg[blue]\$(virtualenv_prompt_info)$reset_color%}" - -# Prompt format: -# -# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE V:VIRTUALENV -# $ COMMAND -# -# For example: -# -# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0 -# $ -PROMPT=" -%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \ -%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n)\ -%{$fg[white]%}@%{$fg[green]%}%m\ -%{$fg[white]%}[%{$fg[green]%}$ip_info\ -%{$fg[white]%}]::\ -%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ -${hg_info}\ -${git_info}\ - \ -%{$fg[white]%}[%*] $exit_code$gce_env$venv_info -%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" - -unset RPROMPT - From 238e0de053dcf1c3f407a679f962c93d5aff2788 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 12 Oct 2017 23:29:20 +0700 Subject: [PATCH 03/14] Fix Mercurial detection --- themes/ys-pep.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme index 6fa5e1350..3f3b56202 100644 --- a/themes/ys-pep.zsh-theme +++ b/themes/ys-pep.zsh-theme @@ -16,6 +16,7 @@ # * List current IP addresses # * GCE hook (for controlling Google Cloud) # * Virtualenv hook +# * Fix Mercurial detection # # Sep-Oct 2017 Pandu POLUAN @@ -36,8 +37,8 @@ ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN" # HG info local hg_info='$(ys_hg_prompt_info)' ys_hg_prompt_info() { - # make sure this is a hg dir - if [ -d '.hg' ]; then + # make sure this is a Mercurial project + if [ -d '.hg' ] || $(hg summary > /dev/null 2>&1) ; then echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}" echo -n $(hg branch 2>/dev/null) if [ -n "$(hg status 2>/dev/null)" ]; then From 504fcf3ecdb5e8b9cb3ad06c8d28f87657bc0f08 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 12 Oct 2017 23:30:39 +0700 Subject: [PATCH 04/14] Add vim modeline --- themes/ys-pep.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme index 3f3b56202..7ea5c93d4 100644 --- a/themes/ys-pep.zsh-theme +++ b/themes/ys-pep.zsh-theme @@ -91,3 +91,5 @@ ${git_info}\ unset RPROMPT +# vim: set ai ts=2 sts=2 et : +# From a5aaa83862c4dc7f57d79a49d9e686b1929ec6ea Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 12 Oct 2017 23:33:50 +0700 Subject: [PATCH 05/14] Improve IP Address Detection * Allow disabling of IP Addr detection * Accoutrements part of the chunk generation * Also works in Windows (under Cygwin) --- themes/ys-pep.zsh-theme | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme index 7ea5c93d4..86d9a2dbc 100644 --- a/themes/ys-pep.zsh-theme +++ b/themes/ys-pep.zsh-theme @@ -59,8 +59,17 @@ local dgrey="$terminfo[bold]$fg[black]" local gce_env="%{\${GCE_PROJECT:+$fg[yellow] GCE:}\$GCE_PROJECT$reset_color%}" # Show my IP Address +ZSH_THEME_SHOW_IP=1 yspep_my_ip() { - echo $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') + [[ $ZSH_THEME_SHOW_IP != 1 ]] && return + echo -n "%{$dgrey%}[%{$fg[green]%}" + local i + if [[ ${(L)_system_name} == cygwin ]]; then + echo -n $(ipconfig | awk '$1 ~ /IP/ && $2 ~ /[Aa]ddress/ {sub(/.*:/, "", $0); gsub(/[ \t\r]/, "", $0); print $0}') + else + echo -n $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') + fi + echo "%{$dgrey%}]" } local ip_info='$(yspep_my_ip)' @@ -81,8 +90,7 @@ local venv_info="%{$terminfo[bold]$fg[blue]\$(virtualenv_prompt_info)$reset_colo PROMPT=" %{$dgrey%}[%*]%{$reset_color%} \ %(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n)\ -%{$fg[white]%}@%{$fg[green]%}%m\ -%{$dgrey%}[%{$fg[green]%}$ip_info%{$dgrey%}]::%{$reset_color%}\ +%{$fg[white]%}@%{$fg[green]%}%m$ip_info%{$dgrey%}:%{$reset_color%}\ %{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ ${hg_info}\ ${git_info}\ From 1d99e87341078fee1ab965e89101b8abfa9666c9 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Fri, 13 Oct 2017 00:09:17 +0700 Subject: [PATCH 06/14] Replace GCE_PROJECT with something more generic GCE_PROJECT was a local need; it should be in .zshrc instead of in the theme. Replacing with an overridable system. --- themes/ys-pep.zsh-theme | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme index 86d9a2dbc..0f45d9470 100644 --- a/themes/ys-pep.zsh-theme +++ b/themes/ys-pep.zsh-theme @@ -55,9 +55,6 @@ local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%} )" ### BEGIN: pepoluan changes ### local dgrey="$terminfo[bold]$fg[black]" -# Local need: Show the GCE_PROJECT var -local gce_env="%{\${GCE_PROJECT:+$fg[yellow] GCE:}\$GCE_PROJECT$reset_color%}" - # Show my IP Address ZSH_THEME_SHOW_IP=1 yspep_my_ip() { @@ -78,6 +75,13 @@ ZSH_THEME_VIRTUALENV_PREFIX=" V:" ZSH_THEME_VIRTUALENV_SUFFIX=" " local venv_info="%{$terminfo[bold]$fg[blue]\$(virtualenv_prompt_info)$reset_color%}" +# Other info, you can override this function in .zshrc +yspep_other_info() { + # Example: Show the GCE_PROJECT variable in yellow: + : echo "%{\${GCE_PROJECT:+$fg[yellow] GCE:}\$GCE_PROJECT%}" +} +local other_info='$(yspep_other_info)' + # Prompt format: # # PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE V:VIRTUALENV @@ -94,7 +98,7 @@ PROMPT=" %{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ ${hg_info}\ ${git_info}\ - $exit_code$gce_env$venv_info + $exit_code$venv_info$other_info %{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" unset RPROMPT From 274462c558fc1efcf4594599a53a2594e4b68eb2 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Fri, 13 Oct 2017 00:16:45 +0700 Subject: [PATCH 07/14] Use %F instead of $fg In addition to more succinct, %F{color} is also MUCH more readable than %{$fg[color]%} --- themes/ys-pep.zsh-theme | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme index 0f45d9470..c16adb34b 100644 --- a/themes/ys-pep.zsh-theme +++ b/themes/ys-pep.zsh-theme @@ -21,11 +21,11 @@ # Sep-Oct 2017 Pandu POLUAN # VCS -YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} " -YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}" +YS_VCS_PROMPT_PREFIX1=" %F{white}on%{$reset_color%} " +YS_VCS_PROMPT_PREFIX2=":%F{cyan}" YS_VCS_PROMPT_SUFFIX="%{$reset_color%}" -YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x" -YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o" +YS_VCS_PROMPT_DIRTY=" %F{red}x" +YS_VCS_PROMPT_CLEAN=" %F{green}o" # Git info local git_info='$(git_prompt_info)' @@ -50,30 +50,30 @@ ys_hg_prompt_info() { fi } -local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%} )" +local exit_code="%(?,,C:%F{red}%?%{$reset_color%} )" ### BEGIN: pepoluan changes ### -local dgrey="$terminfo[bold]$fg[black]" +local dgrey="%B%F{black}" # Show my IP Address ZSH_THEME_SHOW_IP=1 yspep_my_ip() { [[ $ZSH_THEME_SHOW_IP != 1 ]] && return - echo -n "%{$dgrey%}[%{$fg[green]%}" + echo -n "${dgrey}[%F{green}" local i if [[ ${(L)_system_name} == cygwin ]]; then echo -n $(ipconfig | awk '$1 ~ /IP/ && $2 ~ /[Aa]ddress/ {sub(/.*:/, "", $0); gsub(/[ \t\r]/, "", $0); print $0}') else echo -n $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') fi - echo "%{$dgrey%}]" + echo "${dgrey}]" } local ip_info='$(yspep_my_ip)' # Show Virtualenv ZSH_THEME_VIRTUALENV_PREFIX=" V:" ZSH_THEME_VIRTUALENV_SUFFIX=" " -local venv_info="%{$terminfo[bold]$fg[blue]\$(virtualenv_prompt_info)$reset_color%}" +local venv_info="%B%F{blue}\$(virtualenv_prompt_info)%{$reset_color%}" # Other info, you can override this function in .zshrc yspep_other_info() { @@ -92,14 +92,14 @@ local other_info='$(yspep_other_info)' # % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0 # $ PROMPT=" -%{$dgrey%}[%*]%{$reset_color%} \ -%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n)\ -%{$fg[white]%}@%{$fg[green]%}%m$ip_info%{$dgrey%}:%{$reset_color%}\ -%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ +${dgrey}[%*]%{$reset_color%} \ +%(#,%K{yellow}%F{black}%n%{$reset_color%},%F{cyan}%n)\ +%F{white}@%F{green}%m$ip_info$dgrey:%{$reset_color%}\ +%B%F{yellow}%~%{$reset_color%}\ ${hg_info}\ ${git_info}\ $exit_code$venv_info$other_info -%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" +%B%F{red}%# %{$reset_color%}" unset RPROMPT From cd46ae521c9d06989800aa90b6404b7c165c238b Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Fri, 20 Oct 2017 22:04:38 +0700 Subject: [PATCH 08/14] Fix color bleed when list appears %B and %F had a side effect of coloring the redraw of the prompt when list appears underneath the active line. Added %b and %f to properly end the coloring. Not sure if %{ and %} are needed, but added just in case needed. --- themes/ys-pep.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme index c16adb34b..4bd088d30 100644 --- a/themes/ys-pep.zsh-theme +++ b/themes/ys-pep.zsh-theme @@ -99,7 +99,7 @@ ${dgrey}[%*]%{$reset_color%} \ ${hg_info}\ ${git_info}\ $exit_code$venv_info$other_info -%B%F{red}%# %{$reset_color%}" +%{%B%F{red}%}%#%{%b%f$reset_color%} " unset RPROMPT From 4ea3cebf5b0328487d00883d0f735423d824efd2 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Fri, 20 Oct 2017 22:29:33 +0700 Subject: [PATCH 09/14] Color simplification & bold-bleed fix Simplify coloring by using exclusively %b + %f (and %k) to perform color reset. Also removed an unused local variable. --- themes/ys-pep.zsh-theme | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/themes/ys-pep.zsh-theme b/themes/ys-pep.zsh-theme index 4bd088d30..4242d69ea 100644 --- a/themes/ys-pep.zsh-theme +++ b/themes/ys-pep.zsh-theme @@ -59,21 +59,20 @@ local dgrey="%B%F{black}" ZSH_THEME_SHOW_IP=1 yspep_my_ip() { [[ $ZSH_THEME_SHOW_IP != 1 ]] && return - echo -n "${dgrey}[%F{green}" - local i + echo -n "${dgrey}[%b%F{green}" if [[ ${(L)_system_name} == cygwin ]]; then echo -n $(ipconfig | awk '$1 ~ /IP/ && $2 ~ /[Aa]ddress/ {sub(/.*:/, "", $0); gsub(/[ \t\r]/, "", $0); print $0}') else echo -n $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') fi - echo "${dgrey}]" + echo "${dgrey}]%b" } local ip_info='$(yspep_my_ip)' # Show Virtualenv ZSH_THEME_VIRTUALENV_PREFIX=" V:" ZSH_THEME_VIRTUALENV_SUFFIX=" " -local venv_info="%B%F{blue}\$(virtualenv_prompt_info)%{$reset_color%}" +local venv_info="%B%F{blue}\$(virtualenv_prompt_info)%b" # Other info, you can override this function in .zshrc yspep_other_info() { @@ -92,14 +91,14 @@ local other_info='$(yspep_other_info)' # % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0 # $ PROMPT=" -${dgrey}[%*]%{$reset_color%} \ -%(#,%K{yellow}%F{black}%n%{$reset_color%},%F{cyan}%n)\ -%F{white}@%F{green}%m$ip_info$dgrey:%{$reset_color%}\ -%B%F{yellow}%~%{$reset_color%}\ +${dgrey}[%*]%b \ +%(#,%K{yellow}%F{black}%n%k,%F{cyan}%n)\ +%F{white}@%F{green}%m$ip_info$dgrey:%b\ +%B%F{yellow}%~%b\ ${hg_info}\ ${git_info}\ $exit_code$venv_info$other_info -%{%B%F{red}%}%#%{%b%f$reset_color%} " +%B%F{red}%#%b%f " unset RPROMPT From 2037e3fcf552bad7db27f2d52d7f44627fd7b089 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 30 Nov 2017 11:06:18 +0700 Subject: [PATCH 10/14] New Theme, derivative from ys-pep --- themes/ys-pep-2.zsh-theme | 126 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 themes/ys-pep-2.zsh-theme diff --git a/themes/ys-pep-2.zsh-theme b/themes/ys-pep-2.zsh-theme new file mode 100644 index 000000000..77dcf9290 --- /dev/null +++ b/themes/ys-pep-2.zsh-theme @@ -0,0 +1,126 @@ +# ys-pep Theme, based on ys Theme by Yad Smood +# +# ----- BEGIN Original Description ----- +# +# Clean, simple, compatible and meaningful. +# Tested on Linux, Unix and Windows under ANSI colors. +# It is recommended to use with a dark background. +# Colors: black, red, green, yellow, *blue, magenta, cyan, and white. +# +# Mar 2013 Yad Smood +# +# ----- END Original Description ----- +# +# Changes to ys theme: +# * Move timestamp to the front and make it darker +# * List current IP addresses +# * GCE hook (for controlling Google Cloud) +# * Virtualenv hook +# * Fix Mercurial detection +# +# Sep-Oct 2017 Pandu POLUAN + +# VCS +YS_VCS_PROMPT_PREFIX1=" %F{white}on%{$reset_color%} " +YS_VCS_PROMPT_PREFIX2=":%F{cyan}" +YS_VCS_PROMPT_SUFFIX="%{$reset_color%}" +YS_VCS_PROMPT_DIRTY=" %F{red}x" +YS_VCS_PROMPT_CLEAN=" %F{green}o" + +# Git info +local git_info='$(git_prompt_info)' +ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}" +ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX" +ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY" +ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN" + +# HG info +local hg_info='$(ys_hg_prompt_info)' +ys_hg_prompt_info() { + # make sure this is a Mercurial project + if [ -d '.hg' ] || $(hg summary > /dev/null 2>&1) ; then + echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}" + echo -n $(hg branch 2>/dev/null) + if [ -n "$(hg status 2>/dev/null)" ]; then + echo -n "$YS_VCS_PROMPT_DIRTY" + else + echo -n "$YS_VCS_PROMPT_CLEAN" + fi + echo -n "$YS_VCS_PROMPT_SUFFIX" + fi +} + +local exit_code="%(?,,C:%F{red}%?%{$reset_color%} )" + +### BEGIN: pepoluan changes ### +local dgrey="%B%F{black}" +local leftbar1="%F{148}┏%f" +local leftbar2="%F{148}┃%f" +local leftbar3="%F{148}┗%f" + +# Show my IP Address +ZSH_THEME_SHOW_IP=1 +yspep_my_ip() { + [[ $ZSH_THEME_SHOW_IP != 1 ]] && return + echo -n "${dgrey}[%b%F{green}" + if [[ ${(L)_system_name} == cygwin ]]; then + echo -n $(ipconfig | awk '$1 ~ /IP/ && $2 ~ /[Aa]ddress/ {sub(/.*:/, "", $0); gsub(/[ \t\r]/, "", $0); print $0}') + else + echo -n $( + while read num dev etc; do + ip -d -o addr sh ${dev:0: -1} | + awk '$3 == "inet" {sub(/\/[0-9]+/, "", $4); print "%F{022}"$2":%F{green}"$4}'; + done <<<"$( + ip -d -o link sh | + sed -r -e '/link\/loopback/d' -e '/state DOWN/d' + )" + ) + # echo -n $(ip -o addr show | awk -v atype=${1:-inet} '$2 != "lo" && $3 == atype {gsub(/\/[0-9]+/, "", $4); print $4}') + fi + echo "${dgrey}]%b" +} +local ip_info='$(yspep_my_ip)' + +# Show Virtualenv +ZSH_THEME_VIRTUALENV_PREFIX=" V:" +ZSH_THEME_VIRTUALENV_SUFFIX=" " +local venv_info="%B%F{blue}\$(virtualenv_prompt_info)%b" + +# Other info, you can override this function in .zshrc +yspep_other_info() { + # Example: Show the GCE_PROJECT variable in yellow: + : echo "%{\${GCE_PROJECT:+$fg[yellow] GCE:}\$GCE_PROJECT%}" +} +local other_info='$(yspep_other_info)' + +# Prompt format: +# +# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE V:VIRTUALENV +# $ COMMAND +# +# For example: +# +# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0 +# $ + +# First Line (notice the newline!) +PROMPT="$leftbar1$ip_info +" + +# Second Line (notice the newline!) +PROMPT+="$leftbar2${dgrey}[%*]%b \ +%(#,%K{yellow}%F{black}%n%k,%F{cyan}%n)\ +%F{white}@%F{green}%m$dgrey:%b\ +%B%F{yellow}%~%b\ +${hg_info}\ +${git_info}\ + $exit_code$venv_info$other_info +" + +# Third Line (NO newline!) +PROMPT+="$leftbar3%B%F{red}%#%b%f " + +unset RPROMPT + +# vim: set ai ts=2 sts=2 et ft=sh : +# From 424ca986d200dc04c992554d995b9de9486aab68 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Mon, 11 Dec 2017 12:27:32 +0700 Subject: [PATCH 11/14] YubiKey Plugin --- plugins/yubikey/README.md | 11 ++++++++ plugins/yubikey/yubikey.plugin.zsh | 45 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 plugins/yubikey/README.md create mode 100644 plugins/yubikey/yubikey.plugin.zsh diff --git a/plugins/yubikey/README.md b/plugins/yubikey/README.md new file mode 100644 index 000000000..85066c253 --- /dev/null +++ b/plugins/yubikey/README.md @@ -0,0 +1,11 @@ +# YubiKey Plugin + +YubiKey plugin -- Provides aliases to help use YubiKey tokens comfortably + +## Usage + +This plugin will first try to detect location of the 'opensc-pkcs11.so' library, unless already specified in the $OPENSC env var. + +Afterwards, it will try to detect if a 'shared ssh-agent' is already running, through a file in /run (preferred, but must be pre-created with the proper permissions), or in /tmp (fallback). + +Then it will define several aliases. diff --git a/plugins/yubikey/yubikey.plugin.zsh b/plugins/yubikey/yubikey.plugin.zsh new file mode 100644 index 000000000..ae60ad2bf --- /dev/null +++ b/plugins/yubikey/yubikey.plugin.zsh @@ -0,0 +1,45 @@ + + +local _libname='opensc-pkcs11.so' +local _sshfiledir="/run/user/$UID" +local _sshfile='ssh_agent' +local _sshpath='' + +if [[ -z $OPENSC ]]; then + for f in $(locate "/${_libname}"); do + [[ -L $f ]] && continue # Is a sublink + OPENSC="$f" + break + done +fi +export OPENSC + +if [[ -w $_sshfiledir ]]; then + _sshpath="$_sshfiledir/$_sshfile" +else + _sshpath="/tmp/$_sshfile" +fi + + +alias yubi-init="pkill ssh-agent; pkill gpg-agent; ssh-agent -s > $_sshpath; source $_sshpath" +alias yubi-insert="ssh-add -s $OPENSC" +alias yubi-eject="ssh-add -d $OPENSC" + +if [[ -r $_sshpath ]]; then + echo "Common SSH Agent detected." + source $_sshpath +else + echo -n "Common SSH Agent not detected." + case "${(U)YUBI_SSHAGENT_AUTOINIT}" in + 1|Y|YES) + echo -n " Auto-initializing... " + yubi-init + echo "done." + ;; + *) + echo " Autoinit not enabled. Use 'yubi-init' to manually init." + ;; + esac +fi + +# vim: set ft=zsh ts=4 sts=4 et ai : From 9defb728fc3f2f17953df320040ca813ac50fbcf Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 28 Dec 2017 11:53:25 +0700 Subject: [PATCH 12/14] BUGFIX: wrong switch for ssh-add --- plugins/yubikey/yubikey.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/yubikey/yubikey.plugin.zsh b/plugins/yubikey/yubikey.plugin.zsh index ae60ad2bf..4c9b5f895 100644 --- a/plugins/yubikey/yubikey.plugin.zsh +++ b/plugins/yubikey/yubikey.plugin.zsh @@ -23,7 +23,7 @@ fi alias yubi-init="pkill ssh-agent; pkill gpg-agent; ssh-agent -s > $_sshpath; source $_sshpath" alias yubi-insert="ssh-add -s $OPENSC" -alias yubi-eject="ssh-add -d $OPENSC" +alias yubi-eject="ssh-add -e $OPENSC" if [[ -r $_sshpath ]]; then echo "Common SSH Agent detected." From 304f65b537bdef213724798437144288ba286587 Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 28 Dec 2017 12:10:13 +0700 Subject: [PATCH 13/14] Update ys-pep-2 theme desc --- themes/ys-pep-2.zsh-theme | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/themes/ys-pep-2.zsh-theme b/themes/ys-pep-2.zsh-theme index 77dcf9290..372cb9d60 100644 --- a/themes/ys-pep-2.zsh-theme +++ b/themes/ys-pep-2.zsh-theme @@ -1,4 +1,4 @@ -# ys-pep Theme, based on ys Theme by Yad Smood +# ys-pep Theme version 2, based on ys Theme by Yad Smood # # ----- BEGIN Original Description ----- # @@ -19,6 +19,13 @@ # * Fix Mercurial detection # # Sep-Oct 2017 Pandu POLUAN +# +# Changes to ys-pep theme: +# * Split the prompt definition to 3 sections for better maintainability +# * Add "leftbar" to more easily identify the prompt after a monstrous scroll +# * Better IP address detection -- skips link-local, loopback, and DOWN ifaces +# +# Nov-Dec 2017 Pandu POLUAN # VCS YS_VCS_PROMPT_PREFIX1=" %F{white}on%{$reset_color%} " From 47400ebc285edaf81003eb98e3cac30dd2c1e7dc Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 28 Dec 2017 12:35:19 +0700 Subject: [PATCH 14/14] yubikey-plugin Enhancement * Update the README.md file * Add key listing logic (auto-truncating if too long) * Some output cosmetics --- plugins/yubikey/README.md | 11 +++++++++++ plugins/yubikey/yubikey.plugin.zsh | 22 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/plugins/yubikey/README.md b/plugins/yubikey/README.md index 85066c253..ef8312dd8 100644 --- a/plugins/yubikey/README.md +++ b/plugins/yubikey/README.md @@ -9,3 +9,14 @@ This plugin will first try to detect location of the 'opensc-pkcs11.so' library, Afterwards, it will try to detect if a 'shared ssh-agent' is already running, through a file in /run (preferred, but must be pre-created with the proper permissions), or in /tmp (fallback). Then it will define several aliases. + +## Optional Parameters + +These parameters can be set before source-ing oh-my-zsh to customize the settings: + +`YUBI_SHOWKEYS` +> If set to '1' or 'y' or 'yes', will list the keys contained in the 'shared ssh-agent' + +`YUBI_SSHAGENT_AUTOINIT` +> If set to '1' or 'y' or 'yes', will automatically initialize the 'shared ssh-agent' if one is not found + diff --git a/plugins/yubikey/yubikey.plugin.zsh b/plugins/yubikey/yubikey.plugin.zsh index 4c9b5f895..11ccf48a1 100644 --- a/plugins/yubikey/yubikey.plugin.zsh +++ b/plugins/yubikey/yubikey.plugin.zsh @@ -4,6 +4,7 @@ local _libname='opensc-pkcs11.so' local _sshfiledir="/run/user/$UID" local _sshfile='ssh_agent' local _sshpath='' +local _ellipsis='......' if [[ -z $OPENSC ]]; then for f in $(locate "/${_libname}"); do @@ -26,20 +27,33 @@ alias yubi-insert="ssh-add -s $OPENSC" alias yubi-eject="ssh-add -e $OPENSC" if [[ -r $_sshpath ]]; then - echo "Common SSH Agent detected." + echo -n "Common SSH Agent detected. " source $_sshpath else - echo -n "Common SSH Agent not detected." + echo -n "Common SSH Agent not detected. " case "${(U)YUBI_SSHAGENT_AUTOINIT}" in 1|Y|YES) - echo -n " Auto-initializing... " + echo -n "Auto-initializing... " yubi-init echo "done." ;; *) - echo " Autoinit not enabled. Use 'yubi-init' to manually init." + echo "Autoinit not enabled. Use 'yubi-init' to manually init." ;; esac fi +case "${(U)YUBI_SHOWKEYS}" in + 1|Y|YES) + ssh-add -L | while read ln; do + if (( ${#ln} >= COLUMNS )); then + newlen=$(( COLUMNS - ${#_ellipsis} - 1 )) + halflen=$(( newlen / 2 )) + ln="${ln:0:$halflen}${_ellipsis}${ln: -$halflen}" + fi + echo "$ln" + done + ;; +esac + # vim: set ft=zsh ts=4 sts=4 et ai :