Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'ben/master' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
dritter committed Feb 3, 2019
2 parents 40e04e0 + 0b2990b commit 06151ee
Show file tree
Hide file tree
Showing 35 changed files with 220 additions and 166 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ The segments that are currently available are:
* `go_version` - Show the current GO version.
* **Javascript / Node.js Segments:**
* `node_version` - Show the version number of the installed Node.js.
* `nodeenv` - [nodeenv](https://github.com/ekalinin/nodeenv) prompt for displaying node version and environment name.
* [`nodeenv`](#nodeenv) - [nodeenv](https://github.com/ekalinin/nodeenv) prompt for displaying node version and environment name.
* `nvm` - Show the version of Node that is currently active, if it differs from the version used by NVM
* **PHP Segments:**
* `php_version` - Show the current PHP version.
* `laravel_version` - Show the current Laravel version.
* [`symfony2_tests`](#symfony2_tests) - Show a ratio of test classes vs code classes for Symfony2.
* `symfony2_version` - Show the current Symfony2 version, if you are in a Symfony2-Project dir.
* **Python Segments:**
* `virtualenv` - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/).
* [`virtualenv`](#virtualenv) - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/).
* [`anaconda`](#anaconda) - Your active [Anaconda](https://www.continuum.io/why-anaconda) environment.
* `pyenv` - Your active python version as reported by the first word of [`pyenv version`](https://github.com/yyuu/pyenv). Note that the segment is not displayed if that word is _system_ i.e. the segment is inactive if you are using system python.
* **Ruby Segments:**
Expand Down Expand Up @@ -557,6 +557,12 @@ prompt itself.

This only works on the left side. On the right side it does nothing.

##### nodeenv

Shows the currently used [nodeenv](https://github.com/ekalinin/nodeenv). To avoid
Nodeenvs activate command from interfering with Powerlevel9k, you should set
`NODE_VIRTUAL_ENV_DISABLE_PROMPT=1` in your `~/.zshrc`.

##### rbenv

This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack.
Expand Down Expand Up @@ -725,6 +731,12 @@ you are using the [ZSH Line Editor](http://zsh.sourceforge.net/Doc/Release/Zsh-L

To hide the segment entirely when in `INSERT` mode, set `POWERLEVEL9K_VI_INSERT_MODE_STRING=''`

##### virtualenv

This segment shows your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). To avoid
VirtualEnvs activate command from interfering with Powerlevel9k, you should set
`VIRTUAL_ENV_DISABLE_PROMPT=1` in your `~/.zshrc`.

#### Unit Test Ratios

The `symfony2_tests` and `rspec_stats` segments both show a ratio of "real"
Expand Down
70 changes: 34 additions & 36 deletions debug/font-issues.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ trim() {
set +f
}

trim_quotes() {
trim_output="${1//\'}"
trim_output="${trim_output//\"}"
printf "%s" "$trim_output"
}

get_ppid() {
# Get parent process ID of PID.
case "$os" in
Expand Down Expand Up @@ -113,18 +119,19 @@ get_term() {
}

get_term_font() {
local confs term_font mateterm_config role profile xrdb child profile_filename
local term="${1}"
# ((term_run != 1)) && get_term

case "$term" in
"alacritty"*)
shopt -s nullglob
setopt nullglob
confs=({$XDG_CONFIG_HOME,$HOME}/{alacritty,}/{.,}alacritty.ym?)
shopt -u nullglob
unsetopt nullglob

[[ -f "${confs[0]}" ]] || return
[[ -f "${confs[1]}" ]] || return

term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[0]}")"
term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[1]}")"
term_font="${term_font/*family:}"
term_font="${term_font/$'\n'*}"
term_font="${term_font/\#*}"
Expand Down Expand Up @@ -156,26 +163,26 @@ END
font_file="${HOME}/Library/Preferences/com.googlecode.iterm2.plist"

# Count Guids in "New Bookmarks"; they should be unique
profiles_count="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:'" "$font_file" | \
profiles_count="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:'" "$font_file" 2>/dev/null | \
grep -w -c "Guid")"

for ((i=0; i<profiles_count; i++)); do
profile_name="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Name:'" "$font_file")"
profile_name="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Name:'" "$font_file" 2>/dev/null)"

if [[ "$profile_name" == "$current_profile_name" ]]; then
# "Normal Font"
term_font="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Normal Font:'" \
"$font_file")"
"$font_file" 2>/dev/null)"

# Font for non-ascii characters
# Only check for a different non-ascii font, if the user checked
# the "use a different font for non-ascii text" switch.
diff_font="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Use Non-ASCII Font:'" \
"$font_file")"
"$font_file" 2>/dev/null)"

if [[ "$diff_font" == "true" ]]; then
non_ascii="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Non Ascii Font:'" \
"$font_file")"
"$font_file" 2>/dev/null)"

[[ "$term_font" != "$non_ascii" ]] && \
term_font="$term_font (normal) / $non_ascii (non-ascii)"
Expand All @@ -185,13 +192,13 @@ END
;;

"deepin-terminal"*)
term_font="$(awk -F '=' '/font=/ {a=$2} /font_size/ {b=$2} END {print a " " b}' \
term_font="$(awk -F '=' '/font=/ {a=$2} /font_size/ {b=$2} END {print a,b}' \
"${XDG_CONFIG_HOME}/deepin/deepin-terminal/config.conf")"
;;

"GNUstep_Terminal")
term_font="$(awk -F '>|<' '/>TerminalFont</ {getline; f=$3}
/>TerminalFontSize</ {getline; s=$3} END {print f " " s}' \
/>TerminalFontSize</ {getline; s=$3} END {print f,s}' \
"${HOME}/GNUstep/Defaults/Terminal.plist")"
;;

Expand All @@ -201,34 +208,26 @@ END
;;

"kitty"*)
shopt -s nullglob
confs=({$KITTY_CONFIG_DIRECTORY,$XDG_CONFIG_HOME,~/Library/Preferences}/kitty/kitty.con?)
shopt -u nullglob

[[ -f "${confs[0]}" ]] || return

term_font="$(awk '/^([[:space:]]*|[^#_])font_family[[:space:]]+/ {
$1 = "";
gsub(/^[[:space:]]/, "");
font = $0
}
/^([[:space:]]*|[^#_])font_size[[:space:]]+/ {
size = $2
}
END { print font " " size}' "${confs[0]}")"
kitty_config="$(kitty --debug-config)"
[[ "$kitty_config" != *font_family* ]] && return

term_font_size="${kitty_config/*font_size}"
term_font_size="${term_font_size/$'\n'*}"
term_font="${kitty_config/*font_family}"
term_font="${term_font/$'\n'*} $term_font_size"
;;

"konsole"*)
"konsole" | "yakuake")
# Get Process ID of current konsole window / tab
child="$(get_ppid "$$")"

IFS=$'\n' read -d "" -ra konsole_instances < <(qdbus | grep -F 'org.kde.konsole')
declare -a konsole_instances; konsole_instances=( "${(@f)"$(qdbus | grep -F 'org.kde.konsole')"/ /}" )

for i in "${konsole_instances[@]}"; do
IFS=$'\n' read -d "" -ra konsole_sessions < <(qdbus "$i" | grep -F '/Sessions/')
declare -a konsole_sessions; konsole_sessions=( "${(@f)"$(qdbus "$i" | grep -F '/Sessions/')"}" )

for session in "${konsole_sessions[@]}"; do
if ((child == "$(qdbus "$i" "$session" processId)")); then
if ((child == $(qdbus "$i" "$session" processId))); then
profile="$(qdbus "$i" "$session" environment |\
awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')"
break
Expand All @@ -242,7 +241,7 @@ END
profile_filename="${profile_filename/$'\n'*}"

[[ "$profile_filename" ]] && \
term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "$profile_filename")"
term_font="$(awk -F '=|,' '/Font=/ {print $2,$3}' "$profile_filename")"
;;

"lxterminal"*)
Expand All @@ -256,7 +255,7 @@ END
mateterm_config="/tmp/mateterm.cfg"

# Ensure /tmp exists and we do not overwrite anything.
if [[ -d /tmp && ! -f "$mateterm_config" ]]; then
if [[ -d "/tmp" && ! -f "$mateterm_config" ]]; then
mate-terminal --save-config="$mateterm_config"

role="$(xprop -id "${WINDOWID}" WM_WINDOW_ROLE)"
Expand Down Expand Up @@ -301,7 +300,7 @@ END
;;

"qterminal")
term_font="$(awk -F '=' '/fontFamily=/ {a=$2} /fontSize=/ {b=$2} END {print a " " b}' \
term_font="$(awk -F '=' '/fontFamily=/ {a=$2} /fontSize=/ {b=$2} END {print a,b}' \
"${XDG_CONFIG_HOME}/qterminal.org/qterminal.ini")"
;;

Expand All @@ -321,7 +320,7 @@ END
# On Linux we can get the exact path to the running binary through the procfs
# (in case `st` is launched from outside of $PATH) on other systems we just
# have to guess and assume `st` is invoked from somewhere in the users $PATH
[[ -L /proc/$parent/exe ]] && binary="/proc/$parent/exe" || binary="$(type -p st)"
[[ -L "/proc/$parent/exe" ]] && binary="/proc/$parent/exe" || binary="$(type -p st)"

# Grep the output of strings on the `st` binary for anything that looks vaguely
# like a font definition. NOTE: There is a slight limitation in this approach.
Expand Down Expand Up @@ -374,8 +373,7 @@ END
term_font="$(trim "${term_font/*"faceName:"}")"

# xft: isn't required at the beginning so we prepend it if it's missing
[[ "${term_font:0:1}" != "-" && \
"${term_font:0:4}" != "xft:" ]] && \
[[ "${term_font:0:1}" != "-" && "${term_font:0:4}" != "xft:" ]] && \
term_font="xft:$term_font"

# Xresources has two different font formats, this checks which
Expand Down
4 changes: 3 additions & 1 deletion functions/utilities.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ case $(uname) in
;;
Linux)
OS='Linux'
os_release_id="$(grep -E '^ID=([a-zA-Z]*)' /etc/os-release | cut -d '=' -f 2)"
if [ -f /etc/os-release ]; then
[[ ${(f)"$((</etc/os-release) 2>/dev/null)"} =~ "ID=([A-Za-z]+)" ]] && os_release_id="${match[1]}"
fi
case "$os_release_id" in
*arch*)
OS_ICON=$(print_icon 'LINUX_ARCH_ICON')
Expand Down
22 changes: 12 additions & 10 deletions powerlevel9k.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ left_prompt_segment() {
# Allow users to overwrite the color for the visual identifier only.
local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR
set_default $visual_identifier_color_variable "${foregroundColor}"
visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}%f"
visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}"
fi
fi

Expand Down Expand Up @@ -274,7 +274,7 @@ right_prompt_segment() {
# Allow users to overwrite the color for the visual identifier only.
local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR
set_default $visual_identifier_color_variable "${foregroundColor}"
visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}%f"
visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}"
fi
fi

Expand Down Expand Up @@ -363,7 +363,8 @@ prompt_newline() {
"$1_prompt_segment" \
"$0" \
"$2" \
"NONE" "NONE" "${newline}"
"" "" "${newline}"
CURRENT_BG='NONE'
POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws
}

Expand Down Expand Up @@ -798,7 +799,7 @@ prompt_dir() {
# using $PWD instead of "$(print -P '%~')" to allow use of POWERLEVEL9K_DIR_PATH_ABSOLUTE
local current_path=$PWD # WAS: local current_path="$(print -P '%~')"
# check if the user wants to use absolute paths or "~" paths
[[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path//$HOME/"~"}
[[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path/#$HOME/"~"}
# declare all local variables
local paths directory test_dir test_dir_length trunc_path threshhold
# if we are not in "~" or "/", split the paths into an array and exclude "~"
Expand Down Expand Up @@ -1217,9 +1218,8 @@ prompt_nvm() {
################################################################
# Segment to display NodeEnv
prompt_nodeenv() {
local nodeenv_path="$NODE_VIRTUAL_ENV"
if [[ -n "$nodeenv_path" && "$NODE_VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then
local info="$(node -v)[$(basename "$nodeenv_path")]"
if [[ -n "$NODE_VIRTUAL_ENV" ]]; then
local info="$(node -v)[${NODE_VIRTUAL_ENV:t}]"
"$1_prompt_segment" "$0" "$2" "black" "green" "$info" 'NODE_ICON'
fi
}
Expand Down Expand Up @@ -1627,9 +1627,11 @@ prompt_vi_mode() {
# https://virtualenv.pypa.io/en/latest/
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n "$virtualenv_path" && -z "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON'
fi

# Early exit; $virtualenv_path must always be set.
[[ -z "$virtualenv_path" ]] && return

"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${virtualenv_path:t}" 'PYTHON_ICON'
}

################################################################
Expand Down
10 changes: 5 additions & 5 deletions test/core/color_overriding.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ function testDynamicColoringOfSegmentsWork() {
local POWERLEVEL9K_DATE_ICON="date-icon"
local POWERLEVEL9K_DATE_BACKGROUND='red'

assertEquals "%K{001} %F{000}date-icon %f%F{000}%D{%d.%m.%y} %k%F{001}%f " "$(build_left_prompt)"
assertEquals "%K{001} %F{000}date-icon %F{000}%D{%d.%m.%y} %k%F{001}%f " "$(build_left_prompt)"
}

function testDynamicColoringOfVisualIdentifiersWork() {
local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date)
local POWERLEVEL9K_DATE_ICON="date-icon"
local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green'

assertEquals "%K{007} %F{002}date-icon %f%F{000}%D{%d.%m.%y} %k%F{007}%f " "$(build_left_prompt)"
assertEquals "%K{007} %F{002}date-icon %F{000}%D{%d.%m.%y} %k%F{007}%f " "$(build_left_prompt)"
}

function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
Expand All @@ -34,7 +34,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
local POWERLEVEL9K_DATE_FOREGROUND='red'
local POWERLEVEL9K_DATE_BACKGROUND='yellow'

assertEquals "%K{003} %F{002}date-icon %f%F{001}%D{%d.%m.%y} %k%F{003}%f " "$(build_left_prompt)"
assertEquals "%K{003} %F{002}date-icon %F{001}%D{%d.%m.%y} %k%F{003}%f " "$(build_left_prompt)"
}

function testColorOverridingOfStatefulSegment() {
Expand All @@ -45,7 +45,7 @@ function testColorOverridingOfStatefulSegment() {
# Provoke state
local SSH_CLIENT="x"

assertEquals "%K{001} %F{002}ssh-icon %f%F{002}%m %k%F{001}%f " "$(build_left_prompt)"
assertEquals "%K{001} %F{002}ssh-icon %F{002}%m %k%F{001}%f " "$(build_left_prompt)"
}

function testColorOverridingOfCustomSegment() {
Expand All @@ -56,7 +56,7 @@ function testColorOverridingOfCustomSegment() {
local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND='red'
local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND='red'

assertEquals "%K{001} %F{002}CW %f%F{001}world %k%F{001}%f " "$(build_left_prompt)"
assertEquals "%K{001} %F{002}CW %F{001}world %k%F{001}%f " "$(build_left_prompt)"
}

source shunit2/shunit2
8 changes: 4 additions & 4 deletions test/core/visual_identifier.spec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function testOverwritingIconsWork() {
local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here'

assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)"
assertEquals "%K{007} %F{000}icon-here %F{000}world1 %k%F{007}%f " "$(build_left_prompt)"
}

function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() {
Expand All @@ -27,7 +27,7 @@ function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() {
local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here'

assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)"
assertEquals "%K{007} %F{000}icon-here %F{000}world1 %k%F{007}%f " "$(build_left_prompt)"
}

function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() {
Expand All @@ -36,7 +36,7 @@ function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() {
local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here'

assertEquals "%F{007}%f%K{007}%F{000} world1%F{000} icon-here%f%E" "$(build_right_prompt)"
assertEquals "%F{007}%f%K{007}%F{000} world1%F{000} icon-here%E" "$(build_right_prompt)"
}

function testVisualIdentifierPrintsNothingIfNotAvailable() {
Expand All @@ -54,7 +54,7 @@ function testVisualIdentifierIsPrintedInNumericalColorCode() {
local POWERLEVEL9K_CUSTOM_WORLD1_ICON="xxx"
local POWERLEVEL9K_CUSTOM_WORLD1_VISUAL_IDENTIFIER_COLOR="purple3"

assertEquals "%K{007} %F{056}xxx %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)"
assertEquals "%K{007} %F{056}xxx %F{000}world1 %k%F{007}%f " "$(build_left_prompt)"
}

source shunit2/shunit2
Loading

0 comments on commit 06151ee

Please sign in to comment.