Merge remote-tracking branch 'ben/master' into merge_067

This commit is contained in:
Dominik Ritter 2019-03-11 02:07:35 +01:00
commit d4b3867bc7
57 changed files with 805 additions and 483 deletions

View File

@ -1,3 +1,12 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
Thanks for opening an issue! For a project that deals with as many different things as P9k, debugging problems can be difficult. Please follow the guide, below, to create a bug report that will help us help you!
### Before Opening a Bug
@ -14,11 +23,11 @@ Most issues are best explained with a screenshot. Please share one if you can!
#### Have you tried to debug or fix it?
Have you tinkered with your settings, and what happened when you did? Did you find a bit of code that you think might be the culprit? Let us know what you've done so far!
#### Environment Information
This information will help us understand your configuration.
This information will help us understand your configuration.
- What version of ZSH are you using? You can use `zsh --version` to see this.
- Do you use a ZSH framework (e.g., Oh-My-ZSH, Antigen)?

View File

@ -0,0 +1,38 @@
---
name: Performance Issue
about: For performance Issues
title: "[Performance]"
labels: performance
assignees: ''
---
Sorry to hear that the performance of P9K is not adequate. To fix this, please provide us with some hints.
### Your Hardware
Disk I/O is critical for P9K, so do you use a spinning disk, or a SSD?
### Virtualization
Do you use P9K in some sort of virtualization? This is also the case, if you use WSL on Windows..
### How Fast is Fast
Could you quantify how fast the specific segment is, that you think is slow?
For example, if you think the `vcs` segment is slow, could you execute this command in the directory, where the segment is slow:
```zsh
time (repeat 10; do; prompt_vcs left 1 false >/dev/null; done;)
```
Also, please provide us with some context around the segment. In the `vcs` example:
- How big is the repo?
- Does it contain a lot of untracked files?
- Does it contain a lot of git submodules?
- Does it contain a lot of files in general?
Additionally, you could install [zsh-prompt-benchmark](https://github.com/romkatv/zsh-prompt-benchmark), to benchmark the general performance of ZSH and P9K.
If you don't know which segment is slow, could you remove one by one, and spot the one that made the greatest impact?

View File

@ -14,19 +14,20 @@ Once you have submitted your PR, P9k core contributors will review the code and
Please follow this template for creating your PR:
#### Title
Please make the title of your PR descriptive! If appropriate, please prefix the title with one of these tags:
- [Bugfix]
- [New Segment]
- [Docs]
- [Enhancement]
- [Bugfix]
- [New Segment]
- [Docs]
- [Enhancement]
#### Description
Please describe the contribution your PR makes! Screenshots are especially helpful, here, if it's a new segment.
If your PR is addressing an issue, please reference the Issue number here.
#### Questions
Is there something in your PR you're not sure about or need help with? Is there a particular piece of code you would like feedback on? Let us know here!

View File

@ -54,6 +54,32 @@
- Replaced all tabs with spaces
- Removed `rbenv` from default segments
## v0.6.7
- PR #1175 - Fix home dir shortening when using package_name truncation strategy
- PR #1158 - [Bugfix] dir: Fix package name path truncation inside home dir
- PR #1157 - Hide stderr from git ls-files
- PR #1154 - Fix issues with debug/fonts script in Konsole
- PR #1151 - [Bugfix] Only abbreviate $HOME at the beginning of cwd
- PR #1148 - Remove checking for NODEENV_DISABLE_PROMPT
- PR #1147 - Fix newlines in ZSH 5.7
- PR #1149 - Fix RVM
- PR #1128 - [Bugfix] virtualenv prompt displaying
- PR #981 - [Bugfix] Fix for #974
- PR #1126 - Use ip command for VPN segment
- PR #1079 - [Bugfix] Update VIRTUAL_ENV_DISABLE_PROMPT value
- PR #1080 - [Bugfix] Port #1071 to `master` (Fix fatal errors emitted by untracked file check in vcs.zsh)
- PR #1074 - Add vcs vulnerability tests master
- PR #1070 - [Docs] Uniformly apply inline code formatting in README
- PR #1065 - Protect locale
- PR #1048 - Speedup Improvements in `vcs` segment
- PR #1037 - Fix vpn_ip segment
- PR #1036 - Make truncate with package name work without setting shorten length
- PR #1020 - Fix context spec
- PR #990 - [Docs] Add forgotten backtick
- PR #981 - Avoid error if `/etc/os-release` does not exist
- PR #966 - [Bugfix] Fix icons cut off in RPROMPT segments
## v0.6.6
- The `rbenv` segment is no longer a default segment in the LPROMPT.

View File

@ -192,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")"
;;
@ -208,34 +208,26 @@ END
;;
"kitty"*)
setopt nullglob
confs=({$KITTY_CONFIG_DIRECTORY,$XDG_CONFIG_HOME,~/Library/Preferences,~/.config}/kitty/kitty.con?)
unsetopt nullglob
kitty_config="$(kitty --debug-config)"
[[ "$kitty_config" != *font_family* ]] && return
[[ -f "${confs[1]}" ]] || return
term_font="$(awk '/^([[:space:]]*|[^#_])font_family[[:space:]]+/ {
$1 = "";
gsub(/^[[:space:]]/, "");
font = $0
}
/^([[:space:]]*|[^#_])font_size[[:space:]]+/ {
size = $2
}
END { print font " " size}' "${confs[1]}")"
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" | "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
@ -249,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"*)
@ -263,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)"
@ -308,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")"
;;
@ -328,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.
@ -381,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

View File

@ -394,3 +394,58 @@ function p9k::find_first_non_empty() {
shift
done
}
# Parse IP address from ifconfig on OSX and from IP on Linux
# Parameters:
# $1 - string The desired Interface
# $2 - string A root prefix for testing purposes
function p9k::parseIp() {
local desiredInterface="${1}"
if [[ -z "${desiredInterface}" ]]; then
desiredInterface="^[^ ]+"
fi
local ROOT_PREFIX="${2}"
if [[ "$OS" == "OSX" ]]; then
# Get a plain list of all interfaces
local rawInterfaces="$(${ROOT_PREFIX}/sbin/ifconfig -l 2>/dev/null)"
# Parse into array (split by whitespace)
local -a interfaces
interfaces=(${=rawInterfaces})
# Parse only relevant interface names
local pattern="${desiredInterface}[^ ]?"
local -a relevantInterfaces
for rawInterface in $interfaces; do
[[ "$rawInterface" =~ $pattern ]] && relevantInterfaces+=( $MATCH )
done
local newline=$'\n'
for interfaceName in $relevantInterfaces; do
local interface="$(${ROOT_PREFIX}/sbin/ifconfig $interfaceName 2>/dev/null)"
if [[ "${interface}" =~ "lo[0-9]*" ]]; then
continue
fi
# Check if interface is UP.
if [[ "${interface//${newline}/}" =~ "<([^>]*)>(.*)inet[ ]+([^ ]*)" ]]; then
local ipFound="${match[3]}"
local -a interfaceStates=(${(s:,:)match[1]})
if [[ "${interfaceStates[(r)UP]}" == "UP" ]]; then
echo "${ipFound}"
return 0
fi
fi
done
else
local -a interfaces
interfaces=( "${(f)$(${ROOT_PREFIX}/sbin/ip -brief -4 a show 2>/dev/null)}" )
local pattern="^${desiredInterface}[ ]+UP[ ]+([^/ ]+)"
for interface in "${(@)interfaces}"; do
if [[ "$interface" =~ $pattern ]]; then
echo "${match[1]}"
return 0
fi
done
fi
return 1
}

View File

@ -92,7 +92,7 @@ function __p9k_left_prompt_segment() {
# Print the visual identifier and content if any
local visual_identifier
[[ -n "${SEGMENT_ICON}" ]] && visual_identifier="$__P9K_DATA[${STATEFUL_NAME}_VI]${SEGMENT_ICON}%f"
[[ -n "${SEGMENT_ICON}" ]] && visual_identifier="$__P9K_DATA[${STATEFUL_NAME}_VI]${SEGMENT_ICON}"
[[ -n "${content}" ]] && content="${fg}${content}"
[[ -n "${visual_identifier}" && -n "${content}" ]] && visual_identifier="${visual_identifier}${middle_ws}"
echo -n "${visual_identifier}${content}${right_ws}"

View File

@ -38,7 +38,7 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() {
CONDA_ENV_PATH=/tmp
unset CONDA_PREFIX
assertEquals "%K{004} %F{000}icon-here%f %F{000}(tmp) %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}icon-here %F{000}(tmp) %k%F{004}%f " "$(__p9k_build_left_prompt)"
}
function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() {
@ -52,7 +52,7 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() {
unset CONDA_ENV_PATH
local CONDA_PREFIX="test"
assertEquals "%K{004} %F{000}icon-here%f %F{000}(test) %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}icon-here %F{000}(test) %k%F{004}%f " "$(__p9k_build_left_prompt)"
}
function testAnacondaSegmentWorks() {
@ -66,7 +66,7 @@ function testAnacondaSegmentWorks() {
local CONDA_ENV_PATH=/tmp
local CONDA_PREFIX="test"
assertEquals "%K{004} %F{000}icon-here%f %F{000}(tmptest) %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}icon-here %F{000}(tmptest) %k%F{004}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -34,7 +34,7 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() {
echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml
cd /tmp/powerlevel9k-test
assertEquals "%K{000} %F{002}🌱 %f %F{002}test %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{002}🌱 %F{002}test %k%F{000}%f " "$(__p9k_build_left_prompt)"
rm -fr /tmp/powerlevel9k-test
cd -
@ -55,7 +55,7 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirec
echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml
cd /tmp/powerlevel9k-test/1/12/123/1234/12345
assertEquals "%K{000} %F{002}🌱 %f %F{002}test %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{002}🌱 %F{002}test %k%F{000}%f " "$(__p9k_build_left_prompt)"
rm -fr /tmp/powerlevel9k-test
cd -

View File

@ -35,7 +35,7 @@ function testBackgroundJobsSegmentVerboseAlwaysPrintsZeroWithoutBackgroundJobs()
# Load Powerlevel9k
source segments/background_jobs/background_jobs.p9k
assertEquals "%K{003} %F{000}%f %F{000}0 %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{000} %F{000}0 %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
function testBackgroundJobsSegmentWorksWithOneBackgroundJob() {
@ -47,7 +47,7 @@ function testBackgroundJobsSegmentWorksWithOneBackgroundJob() {
# Load Powerlevel9k
source segments/background_jobs/background_jobs.p9k
assertEquals "%K{003} %F{000}%f %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{000} %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() {
@ -60,7 +60,7 @@ function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() {
# Load Powerlevel9k
source segments/background_jobs/background_jobs.p9k
assertEquals "%K{003} %F{000}%f %F{000}3 %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{000} %F{000}3 %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
function testBackgroundJobsSegmentWithVerboseMode() {
@ -73,7 +73,7 @@ function testBackgroundJobsSegmentWithVerboseMode() {
# Load Powerlevel9k
source segments/background_jobs/background_jobs.p9k
assertEquals "%K{003} %F{000}%f %F{000}3 %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{000} %F{000}3 %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
function testBackgroundJobsSegmentWorksWithExpandedMode() {
@ -87,7 +87,7 @@ function testBackgroundJobsSegmentWorksWithExpandedMode() {
# Load Powerlevel9k
source segments/background_jobs/background_jobs.p9k
assertEquals "%K{003} %F{000}%f %F{000}1r 2s %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{000} %F{000}1r 2s %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -28,6 +28,7 @@ systems without a battery). It is supported on both OSX and Linux.
|`P9K_BATTERY_LOW_THRESHOLD`|`10`|Threshold to consider battery level critical.|
|`P9K_BATTERY_LOW_COLOR`|`"red"`|Color to indicate critically low charge level.|
|`P9K_BATTERY_VERBOSE`|`true`|Display time remaining next to battery level.|
|`P9K_BATTERY_HIDE_ABOVE_THRESHOLD`|`unset`|Threshold from which the battery segment should not be displayed.|
Note that you can modify the `_FOREGROUND` color without affecting the icon color.

View File

@ -32,6 +32,7 @@
# $1 string Alignment - left | right
# $2 integer Segment index
# $3 boolean Whether the segment should be joined
# $4 Root Prefix: string - Root prefix for testing purposes
##
prompt_battery() {
local ROOT_PREFIX="${4}"

View File

@ -152,7 +152,7 @@ function testBatterySegmentIfBatteryIsLowWhileDischargingOnOSX() {
makeBatterySay "Now drawing from 'Battery Power'
-InternalBattery-0 (id=1234567) 4%; discharging; 0:05 remaining present: true"
assertEquals "%K{000} %F{001}🔋%f %F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{001}🔋 %F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() {
@ -160,7 +160,7 @@ function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() {
makeBatterySay "Now drawing from 'Battery Power'
-InternalBattery-0 (id=1234567) 4%; charging; 0:05 remaining present: true"
assertEquals "%K{000} %F{003}🔋%f %F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{003}🔋 %F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsNormalWhileDischargingOnOSX() {
@ -168,7 +168,7 @@ function testBatterySegmentIfBatteryIsNormalWhileDischargingOnOSX() {
makeBatterySay "Now drawing from 'Battery Power'
-InternalBattery-0 (id=1234567) 98%; discharging; 3:57 remaining present: true"
assertEquals "%K{000} %F{015}🔋%f %F{015}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{015}🔋 %F{015}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsNormalWhileChargingOnOSX() {
@ -176,7 +176,7 @@ function testBatterySegmentIfBatteryIsNormalWhileChargingOnOSX() {
makeBatterySay "Now drawing from 'Battery Power'
-InternalBattery-0 (id=1234567) 98%; charging; 3:57 remaining present: true"
assertEquals "%K{000} %F{003}🔋%f %F{003}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{003}🔋 %F{003}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsFullOnOSX() {
@ -184,7 +184,7 @@ function testBatterySegmentIfBatteryIsFullOnOSX() {
makeBatterySay "Now drawing from 'AC Power'
-InternalBattery-0 (id=1234567) 99%; charged; 0:00 remaining present: true"
assertEquals "%K{000} %F{002}🔋%f %F{002}99%% " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{002}🔋 %F{002}99%% " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsCalculatingOnOSX() {
@ -192,119 +192,119 @@ function testBatterySegmentIfBatteryIsCalculatingOnOSX() {
makeBatterySay "Now drawing from 'Battery Power'
-InternalBattery-0 (id=1234567) 99%; discharging; (no estimate) present: true"
assertEquals "%K{000} %F{015}🔋%f %F{015}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{015}🔋 %F{015}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsLowWhileDischargingOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "4" "Discharging"
assertEquals "%K{000} %F{001}🔋%f %F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{001}🔋 %F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsLowWhileChargingOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "4" "Charging"
assertEquals "%K{000} %F{003}🔋%f %F{003}4%% (2:14) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{003}🔋 %F{003}4%% (2:14) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsLowWhileUnknownOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "4" "Unknown"
assertEquals "%K{000} %F{001}🔋%f %F{001}4%% " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{001}🔋 %F{001}4%% " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsNormalWhileDischargingOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "98" "Discharging"
assertEquals "%K{000} %F{015}🔋%f %F{015}98%% (2:17) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{015}🔋 %F{015}98%% (2:17) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsNormalWhileChargingOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "98" "Charging"
assertEquals "%K{000} %F{003}🔋%f %F{003}98%% (0:02) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{003}🔋 %F{003}98%% (0:02) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsNormalWhileUnknownOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "98" "Unknown"
assertEquals "%K{000} %F{015}🔋%f %F{015}98%% " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{015}🔋 %F{015}98%% " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsFullOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "100" "Full"
assertEquals "%K{000} %F{002}🔋%f %F{002}100%% " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{002}🔋 %F{002}100%% " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryNearlyFullButNotChargingOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "98" "Unknown" "0"
assertEquals "%K{000} %F{015}🔋%f %F{015}98%% " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{015}🔋 %F{015}98%% " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsCalculatingOnLinux() {
local __P9K_OS='Linux' # Fake Linux
makeBatterySay "99" "Charging" "0"
assertEquals "%K{000} %F{003}🔋%f %F{003}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
assertEquals "%K{000} %F{003}🔋 %F{003}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
}
function testBatterySegmentIfBatteryIsLowWhileDischargingOnWindows() {
local __P9K_OS='Windows' # Fake Windows
makeBatterySay "4" "5" "4"
assertEquals "%K{000} %F{001}🔋%f %F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
assertEquals "%K{000} %F{001}🔋 %F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
}
function testBatterySegmentIfBatteryIsLowWhileChargingOnWindows() {
local __P9K_OS='Windows' # Fake Windows
makeBatterySay "4" "5" "7"
assertEquals "%K{000} %F{003}🔋%f %F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
assertEquals "%K{000} %F{003}🔋 %F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
}
function testBatterySegmentIfBatteryIsLowWhileUnknownOnWindows() {
local __P9K_OS='Windows' # Fake Windows
makeBatterySay "4" "Unknown" "5"
assertEquals "%K{000} %F{001}🔋%f %F{001}4%% (...) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
assertEquals "%K{000} %F{001}🔋 %F{001}4%% (...) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
}
function testBatterySegmentIfBatteryIsNormalWhileDischargingOnWindows() {
local __P9K_OS='Windows' # Fake Windows
makeBatterySay "98" "215" "1"
assertEquals "%K{000} %F{015}🔋%f %F{015}98%% (3:35) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
assertEquals "%K{000} %F{015}🔋 %F{015}98%% (3:35) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
}
function testBatterySegmentIfBatteryIsNormalWhileChargingOnWindows() {
local __P9K_OS='Windows' # Fake Windows
makeBatterySay "98" "298" "2"
assertEquals "%K{000} %F{003}🔋%f %F{003}98%% (4:58) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
assertEquals "%K{000} %F{003}🔋 %F{003}98%% (4:58) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
}
function testBatterySegmentIfBatteryIsFullOnWindows() {
local __P9K_OS='Windows' # Fake Windows
makeBatterySay "100" "181" "1"
assertEquals "%K{000} %F{015}🔋%f %F{015}100%% (3:01) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
assertEquals "%K{000} %F{015}🔋 %F{015}100%% (3:01) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
}
function testBatterySegmentIfBatteryIsCalculatingOnWindows() {
local __P9K_OS='Windows' # Fake Windows
makeBatterySay "99" "" "2"
assertEquals "%K{000} %F{003}🔋%f %F{003}99%% (...) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
assertEquals "%K{000} %F{003}🔋 %F{003}99%% (...) " "$(prompt_battery left 1 false ${FOLDER}/usr/bin/)"
}
source shunit2/shunit2

View File

@ -33,7 +33,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() {
local P9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
local _P9K_COMMAND_DURATION=2.03
assertEquals "%K{001} %F{226}Dur%f %F{226}2.03 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226}Dur %F{226}2.03 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testCommandExecutionTimeThresholdCouldBeSetToZero() {
@ -42,7 +42,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() {
local P9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
local _P9K_COMMAND_DURATION=0.03
assertEquals "%K{001} %F{226}Dur%f %F{226}0.03 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226}Dur %F{226}0.03 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testCommandExecutionTimePrecisionCouldBeChanged() {
@ -52,7 +52,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() {
local P9K_COMMAND_EXECUTION_TIME_PRECISION=4
local _P9K_COMMAND_DURATION=0.0001
assertEquals "%K{001} %F{226}Dur%f %F{226}0.0001 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226}Dur %F{226}0.0001 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testCommandExecutionTimePrecisionCouldBeSetToZero() {
@ -61,7 +61,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() {
local P9K_COMMAND_EXECUTION_TIME_PRECISION=0
local _P9K_COMMAND_DURATION=23.5001
assertEquals "%K{001} %F{226}Dur%f %F{226}23 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226}Dur %F{226}23 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() {
@ -69,7 +69,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand()
P9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
local _P9K_COMMAND_DURATION=180
assertEquals "%K{001} %F{226}Dur%f %F{226}03:00 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226}Dur %F{226}03:00 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
@ -77,7 +77,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
P9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
local _P9K_COMMAND_DURATION=7200
assertEquals "%K{001} %F{226}Dur%f %F{226}02:00:00 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226}Dur %F{226}02:00:00 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -54,8 +54,8 @@ Customizations available are:
|Default|Truncate whole directories from left. How many is defined by `P9K_DIR_SHORTEN_LENGTH`|
|`truncate_absolute_chars`|Truncates an absolute number of characters from the left such that the number of characters that your path displays (with or without `P9K_DIR_SHORTEN_DELIMITER`) is no more than `P9K_DIR_SHORTEN_LENGTH` + the length of `P9K_DIR_SHORTEN_DELIMITER` |
|`truncate_middle`|Truncates the middle part of a folder. E.g. you are in a folder named `~/MySuperProjects/AwesomeFiles/BoringOffice`, then it will truncated to `~/MyS..cts/Awe..les/BoringOffice`, if `P9K_DIR_SHORTEN_LENGTH=3` is also set (controls the amount of characters to be left).|
|`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `P9K_DIR_SHORTEN_LENGTH`.|
|`truncate_absolute`|Truncates everything exept the last few characters in the path. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `P9K_DIR_SHORTEN_LENGTH=3`, you will get "..l9k".|
|`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: `/ro../Pr../office`. How many characters will be untouched is controlled by `P9K_DIR_SHORTEN_LENGTH`.|
|`truncate_absolute`|Truncates everything exept the last few characters in the path. E.g. if you are in a folder named `~/Projects/powerlevel9k` and you have set `P9K_DIR_SHORTEN_LENGTH=3`, you will get `..l9k`.|
|`truncate_to_last`|Truncates everything before the last folder in the path.|
|`truncate_to_first_and_last`|Truncate middle directories from the path. How many directories will be untouched is controlled by `P9K_DIR_SHORTEN_LENGTH`. E.g. if you are in a folder named `~/Projects/powerlevel9k` and you have set `P9K_DIR_SHORTEN_LENGTH=1`, you will get `~/../powerlevel9k`.||
|`truncate_to_unique`|Parse all parent path components and truncate them to the shortest unique length. If you copy & paste the result to a shell, after hitting `TAB` it should expand to the original path unambiguously.|

View File

@ -19,8 +19,8 @@
p9k::register_segment "DIR" 'HOME_SUBFOLDER' "blue" "$DEFAULT_COLOR" '' $'\uE18D' $'\uF07C' '\u'${CODEPOINT_OF_AWESOME_FOLDER_OPEN} $'\uF07C'
#    
p9k::register_segment "DIR" 'NOT_WRITABLE' "blue" "$DEFAULT_COLOR" $'\uE0A2' $'\uE138' $'\uF023' '\u'${CODEPOINT_OF_AWESOME_LOCK} $'\uF023'
#     
p9k::register_segment "DIR" 'ETC' "blue" "$DEFAULT_COLOR" $'\uE818' $'\uF013' $'\uF013' '\u'${CODEPOINT_OF_AWESOME_COG} $'\uF013'
#     ⚙
p9k::register_segment "DIR" 'ETC' "blue" "$DEFAULT_COLOR" $'\uE82F' $'\uF013 ' $'\uF013' '\u'${CODEPOINT_OF_AWESOME_COG}' ' $'\u2699'
p9k::set_default P9K_DIR_PATH_SEPARATOR "/"
p9k::set_default P9K_DIR_HOME_FOLDER_ABBREVIATION "~"
@ -51,14 +51,14 @@ prompt_dir() {
[[ ${current_path} == "${HOME}"* ]] && pathPrefix="~/" || pathPrefix="/"
# check if the user wants to use absolute paths or "~" paths
[[ ${(L)P9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path//$HOME/"~"}
[[ ${(L)P9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path/#$HOME/"~"}
# declare all local variables
local directory test_dir test_dir_length trunc_path threshold
# if we are not in "~" or "/", split the paths into an array and exclude "~"
(( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=()
# only run the code if SHORTEN_DIR_LENGTH is set, or we are using the two strategies that don't rely on it.
if (( ${#current_path} > 1 )) && [[ -n "$P9K_DIR_SHORTEN_LENGTH" || "$P9K_DIR_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$P9K_DIR_SHORTEN_STRATEGY" == "truncate_to_last" ]]; then
if (( ${#current_path} > 1 )) && [[ -n "$P9K_DIR_SHORTEN_LENGTH" || "$P9K_DIR_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$P9K_DIR_SHORTEN_STRATEGY" == "truncate_to_last" || "$P9K_SHORTEN_STRATEGY" == "truncate_with_package_name" ]]; then
case "$P9K_DIR_SHORTEN_STRATEGY" in
truncate_from_right)
# truncate characters from the right of the path
@ -135,7 +135,7 @@ prompt_dir() {
local -a markedFolders
markedFolders=( $(__p9k_upsearch "(${(j:|:)P9K_DIR_PACKAGE_FILES})") )
local package_path="${markedFolders[1]}"
[[ ${(L)P9K_DIR_PATH_ABSOLUTE} != "true" ]] && package_path=${package_path//$HOME/"~"}
[[ ${(L)P9K_DIR_PATH_ABSOLUTE} != "true" ]] && package_path=${package_path/$HOME/"~"}
# Replace the shortest possible match of the marked folder from
# the current path. Remove the amount of characters up to the

View File

@ -426,7 +426,7 @@ function testHomeFolderDetectionWorks() {
source segments/dir/dir.p9k
cd ~
assertEquals "%K{004} %F{000}home-icon%f %F{000}~ %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}home-icon %F{000}~ %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
}
@ -441,7 +441,7 @@ function testHomeSubfolderDetectionWorks() {
local FOLDER=~/powerlevel9k-test
mkdir $FOLDER
cd $FOLDER
assertEquals "%K{004} %F{000}sub-icon%f %F{000}~/powerlevel9k-test %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}sub-icon %F{000}~/powerlevel9k-test %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
rm -fr $FOLDER
@ -457,7 +457,7 @@ function testOtherFolderDetectionWorks() {
local FOLDER=/tmp/powerlevel9k-test
mkdir $FOLDER
cd $FOLDER
assertEquals "%K{004} %F{000}folder-icon%f %F{000}/tmp/powerlevel9k-test %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}folder-icon %F{000}/tmp/powerlevel9k-test %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
rm -fr $FOLDER
@ -515,7 +515,7 @@ function testOmittingFirstCharacterWorks() {
cd /tmp
assertEquals "%K{004} %F{000}folder-icon%f %F{000}tmp %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}folder-icon %F{000}tmp %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
}
@ -532,7 +532,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() {
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
assertEquals "%K{004} %F{000}folder-icon%f %F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}folder-icon %F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
rm -fr /tmp/powerlevel9k-test
@ -763,4 +763,22 @@ function testDirSeparatorColorRootSubSubdirWorks() {
rm -fr /tmp/powerlevel9k-test
}
function testDirHomeTruncationWorksOnlyAtTheBeginning() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(dir)
local FOLDER=/tmp/p9ktest
local SAVED_HOME="${HOME}"
HOME="/p9ktest"
mkdir -p $FOLDER
# Setup folder marker
cd $FOLDER
assertEquals "%K{004} %F{000}/tmp/p9ktest %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
rm -fr $FOLDER
HOME="${SAVED_HOME}"
}
source shunit2/shunit2

View File

@ -21,10 +21,10 @@ The `disk_usage` segment will show the usage level of the partition that your cu
| Variable | Default Value | Description |
|----------|---------------|-------------|
|P9K_DISK_USAGE_ONLY_WARNING|false|Hide the segment except when usage levels have hit warning or critical levels.|
|P9K_DISK_USAGE_WARNING_LEVEL|90|The usage level that triggers a warning state.|
|P9K_DISK_USAGE_CRITICAL_LEVEL|95|The usage level that triggers a critical state.|
|P9K_DISK_USAGE_PATH|`.` (working directory)|Set a path to use a fixed directory instead of the working
|`P9K_DISK_USAGE_ONLY_WARNING`|false|Hide the segment except when usage levels have hit warning or critical levels.|
|`P9K_DISK_USAGE_WARNING_LEVEL`|90|The usage level that triggers a warning state.|
|`P9K_DISK_USAGE_CRITICAL_LEVEL`|95|The usage level that triggers a critical state.|
|`P9K_DISK_USAGE_PATH`|`.` (working directory)|Set a path to use a fixed directory instead of the working
### Color Customization

View File

@ -41,7 +41,7 @@ function testDiskUsageSegmentWhenDiskIsAlmostFull() {
/dev/disk1 487219288 471466944 15496344 97% /"
}
assertEquals "%K{001} %F{015}hdd %f %F{015}97%% %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{015}hdd %F{015}97%% %k%F{001}%f " "$(__p9k_build_left_prompt)"
unfunction df
}
@ -54,7 +54,7 @@ function testDiskUsageSegmentWhenDiskIsVeryFull() {
/dev/disk1 487219288 471466944 15496344 94% /"
}
assertEquals "%K{003} %F{000}hdd %f %F{000}94%% %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{000}hdd %F{000}94%% %k%F{003}%f " "$(__p9k_build_left_prompt)"
unfunction df
}
@ -67,7 +67,7 @@ function testDiskUsageSegmentWhenDiskIsQuiteEmpty() {
/dev/disk1 487219288 471466944 15496344 4% /"
}
assertEquals "%K{000} %F{046}hdd %f %F{046}4%% %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{046}hdd %F{046}4%% %k%F{000}%f " "$(__p9k_build_left_prompt)"
unfunction df
}
@ -97,7 +97,7 @@ function testDiskUsageSegmentWarningLevelCouldBeAdjusted() {
/dev/disk1 487219288 471466944 15496344 11% /"
}
assertEquals "%K{003} %F{000}hdd %f %F{000}11%% %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{000}hdd %F{000}11%% %k%F{003}%f " "$(__p9k_build_left_prompt)"
unfunction df
}
@ -112,7 +112,7 @@ function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() {
/dev/disk1 487219288 471466944 15496344 11% /"
}
assertEquals "%K{001} %F{015}hdd %f %F{015}11%% %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{015}hdd %F{015}11%% %k%F{001}%f " "$(__p9k_build_left_prompt)"
unfunction df
}

View File

@ -44,7 +44,7 @@ function testGo() {
PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"
assertEquals "%K{002} %F{255}Go%f %F{255}go1.5.3 %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{255}Go %F{255}go1.5.3 %k%F{002}%f " "$(__p9k_build_left_prompt)"
unset P9K_GO_ICON
unset PWD

View File

@ -23,33 +23,11 @@
# $1 string Alignment - left | right
# $2 integer Segment index
# $3 boolean Whether the segment should be joined
# $4 Root Prefix: string - Root prefix for testing purposes
##
prompt_ip() {
if [[ "$__P9K_OS" == "OSX" ]]; then
if p9k::defined P9K_IP_INTERFACE; then
# Get the IP address of the specified interface.
ip=$(ipconfig getifaddr "$P9K_IP_INTERFACE")
else
local interfaces callback
# Get network interface names ordered by service precedence.
interfaces=$(networksetup -listnetworkserviceorder | grep -o "Device:\s*[a-z0-9]*" | grep -o -E '[a-z0-9]*$')
callback='ipconfig getifaddr $item'
ip=$(p9k::get_relevant_item "$interfaces" "$callback")
fi
else
if p9k::defined P9K_IP_INTERFACE; then
# Get the IP address of the specified interface.
ip=$(ip -4 a show "$P9K_IP_INTERFACE" | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+")
else
local interfaces callback
# Get all network interface names that are up
interfaces=$(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9.]+")
callback='ip -4 a show ${item} | grep -o -E "inet\s*[0-9.]+" | grep -o -E "[0-9.]+"'
ip=$(p9k::get_relevant_item "$interfaces" "$callback")
fi
fi
local ROOT_PREFIX="${4}"
local ip=$(p9k::parseIp "${P9K_IP_INTERFACE}" "${ROOT_PREFIX}")
p9k::prepare_segment "$0" "" $1 "$2" $3 "$ip"
}

View File

@ -7,214 +7,245 @@ SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
local -a P9K_RIGHT_PROMPT_ELEMENTS
P9K_RIGHT_PROMPT_ELEMENTS=()
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/ip/ip.p9k
# Test specific
P9K_HOME=$(pwd)
FOLDER=/tmp/powerlevel9k-test
mkdir -p $FOLDER
mkdir $FOLDER/sbin
}
function tearDown() {
# Go back to powerlevel9k folder
cd "${P9K_HOME}"
# Remove eventually created test-specific folder
rm -fr "${FOLDER}"
unset FOLDER
unset P9K_HOME
}
function fakeIfconfig() {
local INTERFACE1="${1}"
[[ -z "${INTERFACE1}" ]] && INTERFACE1="eth0"
local INTERFACE1_IP="1.2.3.4"
local INTERFACE2="${2}"
[[ -z "${INTERFACE2}" ]] && INTERFACE2="disabled-if2"
local INTERFACE2_IP="5.6.7.8"
# Fake ifconfig
cat > $FOLDER/sbin/ifconfig <<EOF
#!/usr/bin/env zsh
if [[ "\$*" =~ '-l' ]]; then
echo "docker0 tun1 ${INTERFACE1} ${INTERFACE2} lo"
exit 0
fi
if [[ "\$*" =~ '${INTERFACE1}' ]]; then
cat <<INNER
tun1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet ${INTERFACE1_IP} txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
INNER
exit 0
fi
if [[ "\$*" =~ '${INTERFACE2}' ]]; then
cat <<INNER
tun1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet ${INTERFACE2_IP} txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
INNER
exit 0
fi
# If neither INTERFACE1 nor INTERFACE2 is queried, fake a offline (DOWN) interface.
# We assume if there is at least one argument, we queried for a specific interface.
if [[ "\$#" -gt 0 ]]; then
cat <<INNER
tun1: flags=4099<DOWN,BROADCAST,MULTICAST> mtu 1500
inet 5.5.5.5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
INNER
exit 0
fi
if [[ "\$#" -eq 0 ]]; then
cat <<INNER
docker0: flags=4099<DOWN,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:8f:5c:ed:51 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tun1: flags=4099<DOWN,BROADCAST,MULTICAST> mtu 1500
inet 10.20.30.40 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
${INTERFACE1}: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet ${INTERFACE1_IP} txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
${INTERFACE2}: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet ${INTERFACE2_IP} txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 5136 bytes 328651 (320.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5136 bytes 328651 (320.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
INNER
exit 0
fi
EOF
chmod +x $FOLDER/sbin/ifconfig
}
function fakeIp() {
local INTERFACE1="${1}"
[[ -z "${INTERFACE1}" ]] && INTERFACE1="eth0"
local INTERFACE2="${2}"
[[ -z "${INTERFACE2}" ]] && INTERFACE2="disabled-if2"
cat > $FOLDER/sbin/ip <<EOF
#!/usr/bin/env zsh
if [[ "\$*" =~ '-brief.*show' ]]; then
cat <<INNER
lo UNKNOWN 127.0.0.1/8
${INTERFACE1} UP 1.2.3.4/24
${INTERFACE2} UP 5.4.3.2/16
docker0 DOWN 172.17.0.1/16
INNER
fi
if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then
cat <<INNER
2: ${INTERFACE1}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever
INNER
fi
if [[ "\$*" =~ 'show ${INTERFACE2}' ]]; then
cat <<INNER
3: ${INTERFACE2}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 1.2.3.4 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever
INNER
fi
EOF
chmod +x $FOLDER/sbin/ip
}
function testIpSegmentPrintsNothingOnOsxIfNotConnected() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(ip custom_world)
alias networksetup='echo "not connected"'
local P9K_CUSTOM_WORLD='echo world'
cat > $FOLDER/sbin/ifconfig <<EOF
#!/usr/bin/env zsh
local __P9K_OS="OSX" # Fake OSX
echo "not connected"
EOF
assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/ip/ip.p9k
local OS="OSX" # Fake OSX
unalias networksetup
assertEquals "" "$(prompt_ip left 1 false "$FOLDER")"
}
function testIpSegmentPrintsNothingOnLinuxIfNotConnected() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(ip custom_world)
alias ip='echo "not connected"'
local P9K_CUSTOM_WORLD='echo world'
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/ip/ip.p9k
local OS="Linux" # Fake Linux
local __P9K_OS="Linux" # Fake Linux
cat > $FOLDER/sbin/ip <<EOF
#!/usr/bin/env zsh
assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
echo "not connected"
EOF
chmod +x $FOLDER/sbin/ip
unalias ip
assertEquals "" "$(prompt_ip left 1 false "$FOLDER")"
}
function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(ip)
alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled.
(1) Ethernet
(Hardware Port: Ethernet, Device: en0)
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/ip/ip.p9k
local OS='OSX' # Fake OSX
(2) FireWire
(Hardware Port: FireWire, Device: fw0)
fakeIfconfig "eth1" "eth2"
(3) Wi-Fi
(Hardware Port: Wi-Fi, Device: en1)
(4) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en3)
(5) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)
(6) Apple USB Ethernet Adapter
(Hardware Port: Apple USB Ethernet Adapter, Device: en4)
'"
alias ipconfig="_(){ echo '1.2.3.4'; };_"
local __P9K_OS='OSX' # Fake OSX
assertEquals "%K{006} %F{000}IP%f %F{000}1.2.3.4 %k%F{006}%f " "$(__p9k_build_left_prompt)"
unalias ipconfig
unalias networksetup
}
# There could be more than one confiured network interfaces.
# `networksetup -listnetworkserviceorder` lists the interfaces
# in hierarchical order, but from outside this is not obvious
# (implementation detail). So we need a test for this case.
function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(ip)
alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled.
(1) Ethernet
(Hardware Port: Ethernet, Device: en0)
(2) FireWire
(Hardware Port: FireWire, Device: fw0)
(3) Wi-Fi
(Hardware Port: Wi-Fi, Device: en1)
(4) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en3)
(5) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)
(6) Apple USB Ethernet Adapter
(Hardware Port: Apple USB Ethernet Adapter, Device: en4)
'"
# Return a unique IP address for every interface
ipconfig() {
case "${2}" {
en0)
echo 1.2.3.4
;;
fw0)
echo 2.3.4.5
;;
en1)
echo 3.4.5.6
;;
en3)
echo 4.5.6.7
;;
}
}
local __P9K_OS='OSX' # Fake OSX
assertEquals "%K{006} %F{000}IP%f %F{000}1.2.3.4 %k%F{006}%f " "$(__p9k_build_left_prompt)"
unfunction ipconfig
unalias networksetup
assertEquals "%K{006} %F{000}IP %F{000}1.2.3.4 " "$(prompt_ip left 1 false "$FOLDER")"
}
function testIpSegmentWorksOnOsxWithInterfaceSpecified() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(ip)
local P9K_IP_INTERFACE='xxx'
alias ipconfig="_(){ echo '1.2.3.4'; };_"
fakeIfconfig "eth1"
local __P9K_OS='OSX' # Fake OSX
local P9K_IP_INTERFACE="eth1"
assertEquals "%K{006} %F{000}IP%f %F{000}1.2.3.4 %k%F{006}%f " "$(__p9k_build_left_prompt)"
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/ip/ip.p9k
local OS='OSX' # Fake OSX
unalias ipconfig
assertEquals "%K{006} %F{000}IP %F{000}1.2.3.4 " "$(prompt_ip left 1 false "$FOLDER")"
}
function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() {
setopt aliases
local P9K_LEFT_PROMPT_ELEMENTS=(ip)
# That command is harder to test, as it is used at first
# to get all relevant network interfaces and then for
# getting the configuration of that segment..
ip(){
if [[ "$*" == 'link ls up' ]]; then
echo "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff";
fi
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/ip/ip.p9k
local OS='Linux' # Fake Linux
if [[ "$*" == '-4 a show eth0' ]]; then
echo '2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever';
fi
}
fakeIp "eth0"
local __P9K_OS='Linux' # Fake Linux
assertEquals "%K{006} %F{000}IP%f %F{000}10.0.2.15 %k%F{006}%f " "$(__p9k_build_left_prompt)"
unfunction ip
}
function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() {
setopt aliases
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(ip)
# That command is harder to test, as it is used at first
# to get all relevant network interfaces and then for
# getting the configuration of that segment..
ip(){
if [[ "$*" == 'link ls up' ]]; then
echo "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff";
fi
if [[ "$*" == '-4 a show eth1' ]]; then
echo '3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever';
fi
}
local __P9K_OS='Linux' # Fake Linux
assertEquals "%K{006} %F{000}IP%f %F{000}10.0.2.15 %k%F{006}%f " "$(__p9k_build_left_prompt)"
unfunction ip
assertEquals "%K{006} %F{000}IP %F{000}1.2.3.4 " "$(prompt_ip left 1 false "$FOLDER")"
}
function testIpSegmentWorksOnLinuxWithInterfaceSpecified() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(ip)
local P9K_IP_INTERFACE='xxx'
ip(){
echo '2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever';
}
fakeIp "eth3"
local __P9K_OS='Linux' # Fake Linux
local P9K_IP_INTERFACE="eth3"
assertEquals "%K{006} %F{000}IP%f %F{000}10.0.2.15 %k%F{006}%f " "$(__p9k_build_left_prompt)"
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/ip/ip.p9k
local OS='Linux' # Fake Linux
unfunction ip
assertEquals "%K{006} %F{000}IP %F{000}1.2.3.4 " "$(prompt_ip left 1 false "$FOLDER")"
}
source shunit2/shunit2
source shunit2/shunit2

View File

@ -73,7 +73,7 @@ function testKubeContext() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
assertEquals "%K{004} %F{015}%f %F{015}minikube/default %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{015} %F{015}minikube/default %k%F{004}%f " "$(__p9k_build_left_prompt)"
unset P9K_LEFT_PROMPT_ELEMENTS
unalias kubectl
@ -83,7 +83,7 @@ function testKubeContextOtherNamespace() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
assertEquals "%K{004} %F{015}%f %F{015}minikube/kube-system %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{015} %F{015}minikube/kube-system %k%F{004}%f " "$(__p9k_build_left_prompt)"
unset P9K_LEFT_PROMPT_ELEMENTS
unalias kubectl

View File

@ -35,7 +35,7 @@ function testLaravelVersionSegment() {
P9K_LEFT_PROMPT_ELEMENTS=(laravel_version)
source segments/laravel_version/laravel_version.p9k
assertEquals "%K{001} %F{015}x%f %F{015}5.4.23 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{015}x %F{015}5.4.23 %k%F{001}%f " "$(__p9k_build_left_prompt)"
unalias php
}

View File

@ -45,7 +45,7 @@ function testLoadSegmentWorksOnOsx() {
local __P9K_OS="OSX" # Fake OSX
assertEquals "%K{002} %F{000}L%f %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})"
assertEquals "%K{002} %F{000}L %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})"
unfunction sysctl
}
@ -65,7 +65,7 @@ function testLoadSegmentWorksOnBsd() {
local __P9K_OS="BSD" # Fake BSD
assertEquals "%K{002} %F{000}L%f %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})"
assertEquals "%K{002} %F{000}L %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})"
unfunction sysctl
}
@ -80,7 +80,7 @@ function testLoadSegmentWorksOnLinux() {
local __P9K_OS="Linux" # Fake Linux
assertEquals "%K{002} %F{000}L%f %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})"
assertEquals "%K{002} %F{000}L %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})"
unalias nproc
}
@ -98,7 +98,7 @@ function testLoadSegmentNormalState() {
local __P9K_OS="Linux" # Fake Linux
assertEquals "%K{002} %F{000}L%f %F{000}1.00 " "$(prompt_load left 1 false ${FOLDER})"
assertEquals "%K{002} %F{000}L %F{000}1.00 " "$(prompt_load left 1 false ${FOLDER})"
unalias nproc
}
@ -116,7 +116,7 @@ function testLoadSegmentWarningState() {
local __P9K_OS="Linux" # Fake Linux
assertEquals "%K{003} %F{000}L%f %F{000}2.01 " "$(prompt_load left 1 false ${FOLDER})"
assertEquals "%K{003} %F{000}L %F{000}2.01 " "$(prompt_load left 1 false ${FOLDER})"
unalias nproc
}
@ -134,7 +134,7 @@ function testLoadSegmentCriticalState() {
local __P9K_OS="Linux" # Fake Linux
assertEquals "%K{001} %F{000}L%f %F{000}2.81 " "$(prompt_load left 1 false ${FOLDER})"
assertEquals "%K{001} %F{000}L %F{000}2.81 " "$(prompt_load left 1 false ${FOLDER})"
unalias nproc
}

42
segments/newline/newline.spec Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env zsh
#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
# Required for shunit2 to run correctly
setopt shwordsplit
SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
P9K_HOME=$(pwd)
### Test specific
}
function testNewlineDoesNotCreateExtraSegmentSeparator() {
local P9K_CUSTOM_WORLD1="echo world1"
local P9K_CUSTOM_WORLD2="echo world2"
local -a P9K_LEFT_PROMPT_ELEMENTS=(custom_world1 newline newline newline custom_world2)
# Load Powerlevel9k
source ${P9K_HOME}/powerlevel9k.zsh-theme
local OS="OSX" # Fake OSX
local newline=$'\n'
assertEquals "%K{015} %F{000}world1 %k%F{015}${newline}%k ${newline}%k ${newline}%K{015} %F{000}world2 %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testNewlineMakesPreviousSegmentEndWell() {
local P9K_CUSTOM_WORLD1="echo world1"
local -a P9K_LEFT_PROMPT_ELEMENTS=(custom_world1 newline)
# Load Powerlevel9k
source ${P9K_HOME}/powerlevel9k.zsh-theme
local OS="OSX" # Fake OSX
local newline=$'\n'
assertEquals "%K{015} %F{000}world1 %k%F{015}${newline}%k%FNONE%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -32,7 +32,7 @@ function testNodeVersionSegmentWorks() {
echo "v1.2.3"
}
assertEquals "%K{002} %F{015}%f %F{015}1.2.3 %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{015} %F{015}1.2.3 %k%F{002}%f " "$(__p9k_build_left_prompt)"
unfunction node
}

View File

@ -21,4 +21,9 @@ P9K_NODEENV_BACKGROUND='blue'
### Customize Icon
The main Icon can be changed by setting `P9K_NODEENV_ICON="my_icon"`. To change the
icon color only, set `P9K_NODEENV_ICON_COLOR="red"`.
icon color only, set `P9K_NODEENV_ICON_COLOR="red"`.
### Caveat
To avoid Nodeenvs activate command from interfering with Powerlevel9k, you should
set `NODE_VIRTUAL_ENV_DISABLE_PROMPT=1` in your `~/.zshrc`.

View File

@ -25,7 +25,7 @@
# $3 boolean Whether the segment should be joined
##
prompt_nodeenv() {
if [[ -n "${NODE_VIRTUAL_ENV}" && "$NODE_VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then
if [[ -n "$NODE_VIRTUAL_ENV" ]]; then
local info="$(node -v)[${NODE_VIRTUAL_ENV:t}]"
p9k::prepare_segment "$0" "" $1 "$2" $3 "$info"
fi

View File

@ -44,30 +44,13 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() {
unfunction node
}
function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world)
local P9K_CUSTOM_WORLD='echo world'
node() {
echo "v1.2.3"
}
NODE_VIRTUAL_ENV="node-env"
NODE_VIRTUAL_ENV_DISABLE_PROMPT=true
assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
unset NODE_VIRTUAL_ENV_DISABLE_PROMPT
unset NODE_VIRTUAL_ENV
unfunction node
}
function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(nodeenv)
alias node="nonode 2>/dev/null"
NODE_VIRTUAL_ENV="node-env"
assertEquals "%K{000} %F{002}%f %F{002}[node-env] %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{002} %F{002}[node-env] %k%F{000}%f " "$(__p9k_build_left_prompt)"
unset NODE_VIRTUAL_ENV
unalias node
@ -81,7 +64,7 @@ function testNodeenvSegmentWorks() {
}
NODE_VIRTUAL_ENV="node-env"
assertEquals "%K{000} %F{002}%f %F{002}v1.2.3[node-env] %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{002} %F{002}v1.2.3[node-env] %k%F{000}%f " "$(__p9k_build_left_prompt)"
unfunction node
unset NODE_VIRTUAL_ENV

View File

@ -50,7 +50,7 @@ function testNvmSegmentWorksWithoutHavingADefaultAlias() {
[[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0'
}
assertEquals "%K{005} %F{000}%f %F{000}4.6.0 %k%F{005}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{005} %F{000} %F{000}4.6.0 %k%F{005}%f " "$(__p9k_build_left_prompt)"
}
function testNvmSegmentPrintsNothingWhenOnDefaultVersion() {
@ -82,7 +82,7 @@ function testNvmSegmentAppendsSystemWhenUsingSystem() {
[[ ${1} == 'current' ]] && echo 'system' || echo 'v1.4.0'
}
assertEquals "%K{005} %F{000}%f %F{000}11.3.0 system %k%F{005}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{005} %F{000} %F{000}11.3.0 system %k%F{005}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -22,10 +22,16 @@
# DragonFly) ;;
"Linux")
case "$__P9K_OS_ID" in
#    
"alpine") p9k::register_segment "OS_ICON" "" "black" "white" 'Alp' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF300' ;;
#    
"aosc") p9k::register_segment "OS_ICON" "" "black" "white" 'Aos' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF301' ;;
#    
"arch") p9k::register_segment "OS_ICON" "" "black" "white" 'Arc' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF303' ;;
#    
"debian") p9k::register_segment "OS_ICON" "" "black" "white" 'Deb' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uE77D' ;;
#    
"devuan") p9k::register_segment "OS_ICON" "" "black" "white" 'Dev' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF307' ;;
#    
"ubuntu") p9k::register_segment "OS_ICON" "" "black" "white" 'Ubu' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF31B' ;;
#    
@ -40,6 +46,10 @@
"gentoo") p9k::register_segment "OS_ICON" "" "black" "white" 'Gen' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF30D' ;;
#    
"mageia") p9k::register_segment "OS_ICON" "" "black" "white" 'Mag' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF310' ;;
#    
"manjaro") p9k::register_segment "OS_ICON" "" "black" "white" 'Man' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF312' ;;
#    
"nixos") p9k::register_segment "OS_ICON" "" "black" "white" 'Nix' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF313' ;;
#    
"centos") p9k::register_segment "OS_ICON" "" "black" "white" 'Cen' $'\uE271' $'\uF17C' '\u'$CODEPOINT_OF_AWESOME_LINUX $'\uF304' ;;
#    

View File

@ -33,7 +33,7 @@ Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
'"
assertEquals "%K{013} %F{255}PHP%f %F{255}5.6.27 %k%F{013}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{013} %F{255}PHP %F{255}5.6.27 %k%F{013}%f " "$(__p9k_build_left_prompt)"
unalias php
}

View File

@ -34,12 +34,16 @@
[[ $(which stat) == "/usr/bin/stat" ]] && local stat_version="OSX"
################################################################
# Public IP segment
# Parameters:
# * $1 Alignment: string - left|right
# * $2 Index: integer
# * $3 Joined: bool - If the segment should be joined
# @description
# Public IP segment
##
# @args
# $1 Alignment: string - left | right
# $2 Index: integer
# $3 Joined: bool - If the segment should be joined
# $4 Root Prefix: string - Root prefix for testing purposes
prompt_public_ip() {
local ROOT_PREFIX="${4}"
# Do we need a fresh IP?
local refresh_ip=false
if [[ -f $P9K_PUBLIC_IP_FILE ]]; then
@ -60,7 +64,7 @@ prompt_public_ip() {
# grab a fresh IP if needed
local fresh_ip
if [[ ${refresh_ip} =~ true && -w $P9K_PUBLIC_IP_FILE ]]; then
if [[ ${refresh_ip} == true && -w $P9K_PUBLIC_IP_FILE ]]; then
for method in "${P9K_PUBLIC_IP_METHODS[@]}"; do
case ${method} in
'dig')
@ -95,15 +99,12 @@ prompt_public_ip() {
if [[ -n ${public_ip} ]]; then
local icon=''
# TODO: Where is this variable actually set?
# Check VPN is on if VPN interface is set
if [[ -n $P9K_PUBLIC_IP_VPN_INTERFACE ]]; then
for vpn_iface in $(/sbin/ifconfig | grep -e ^"$P9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1)
do
local vpnIp="$(p9k::parseIp "${P9K_PUBLIC_IP_VPN_INTERFACE}" "${ROOT_PREFIX}")"
if [[ -n "$vpnIp" ]]; then
icon="VPN_ICON"
break
done
fi
fi
p9k::prepare_segment "$0" "" $1 "$2" $3 "${public_ip}" "" "$icon"
fi

View File

@ -40,7 +40,7 @@ Pages inactive: 1313411.
local __P9K_OS="OSX" # Fake OSX
assertEquals "%K{003} %F{000}RAM%f %F{000}6.15G " "$(prompt_ram left 1 false ${FOLDER})"
assertEquals "%K{003} %F{000}RAM %F{000}6.15G " "$(prompt_ram left 1 false ${FOLDER})"
unalias vm_stat
}
@ -51,7 +51,7 @@ function testRamSegmentWorksOnBsd() {
local __P9K_OS="BSD" # Fake BSD
assertEquals "%K{003} %F{000}RAM%f %F{000}0.29M " "$(prompt_ram left 1 false ${FOLDER})"
assertEquals "%K{003} %F{000}RAM %F{000}0.29M " "$(prompt_ram left 1 false ${FOLDER})"
return 0
}
@ -61,7 +61,7 @@ function testRamSegmentWorksOnLinux() {
local __P9K_OS="Linux" # Fake Linux
assertEquals "%K{003} %F{000}RAM%f %F{000}0.29G " "$(prompt_ram left 1 false ${FOLDER})"
assertEquals "%K{003} %F{000}RAM %F{000}0.29G " "$(prompt_ram left 1 false ${FOLDER})"
}
source shunit2/shunit2

View File

@ -12,7 +12,7 @@
# Parameters:
# segment_name context background foreground Generic Flat/Awesome-Patched Awesome-FontConfig Awesome-Mapped-FontConfig NerdFont
#   
p9k::register_segment "RUST_VERSION" "" "darkorange" "$DEFAULT_COLOR" 'Rust' '' $'\uE6A8' $'\uE6A8' $'\uE7A8 '
p9k::register_segment "RUST_VERSION" "" "darkorange" "$DEFAULT_COLOR" 'Rust' '(rust)' $'\uE6A8' $'\uE6A8' $'\uE7A8 '
}
################################################################

View File

@ -36,7 +36,7 @@ function testRust() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(rust_version)
assertEquals "%K{208} %F{000}Rust%f %F{000}0.4.1a-alpha %k%F{208}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{208} %F{000}Rust %F{000}0.4.1a-alpha %k%F{208}%f " "$(__p9k_build_left_prompt)"
}
function testRustPrintsNothingIfRustIsNotAvailable() {

View File

@ -25,9 +25,11 @@
# $3 boolean Whether the segment should be joined
##
prompt_rvm() {
local version_and_gemset=${rvm_env_string/ruby-}
if [ $commands[rvm-prompt] ]; then
local version_and_gemset=${$(rvm-prompt v p)/ruby-}
if [[ -n "$version_and_gemset" ]]; then
p9k::prepare_segment "$0" "" $1 "$2" $3 "$version_and_gemset"
if [[ -n "$version_and_gemset" ]]; then
p9k::prepare_segment "$0" "" $1 "$2" $3 "$version_and_gemset"
fi
fi
}

View File

@ -37,7 +37,7 @@ function testSshSegmentWorksIfOnlySshClientIsSet() {
SSH_CLIENT='ssh-client'
unset SSH_TTY
assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{003}ssh-icon %k%F{000}%f " "$(__p9k_build_left_prompt)"
unset SSH_CLIENT
}
@ -52,7 +52,7 @@ function testSshSegmentWorksIfOnlySshTtyIsSet() {
SSH_TTY='ssh-tty'
unset SSH_CLIENT
assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{003}ssh-icon %k%F{000}%f " "$(__p9k_build_left_prompt)"
unset SSH_TTY
}
@ -67,7 +67,7 @@ function testSshSegmentWorksIfAllNecessaryVariablesAreSet() {
SSH_CLIENT='ssh-client'
SSH_TTY='ssh-tty'
assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{003}ssh-icon %k%F{000}%f " "$(__p9k_build_left_prompt)"
unset SSH_TTY
unset SSH_CLIENT

View File

@ -62,7 +62,7 @@ function testStackProjectSegment() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(stack_project)
assertEquals "%K{056} %F{015}λ=%f %F{015}Stack %k%F{056}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{056} %F{015}λ= %F{015}Stack %k%F{056}%f " "$(__p9k_build_left_prompt)"
unalias stack
}

View File

@ -34,7 +34,7 @@ function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() {
local P9K_STATUS_HIDE_SIGNAME=true
local P9K_LEFT_PROMPT_ELEMENTS=(status)
assertEquals "%K{000} %F{002}%f %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{002} %k%F{000}%f " "$(__p9k_build_left_prompt)"
}
function testStatusInGeneralErrorCase() {
@ -43,7 +43,7 @@ function testStatusInGeneralErrorCase() {
local P9K_STATUS_VERBOSE=true
local P9K_STATUS_SHOW_PIPESTATUS=false
assertEquals "%K{001} %F{226}%f %F{226}1 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226} %F{226}1 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testPipestatusInErrorCase() {
@ -53,7 +53,7 @@ function testPipestatusInErrorCase() {
local P9K_STATUS_VERBOSE=true
local P9K_STATUS_SHOW_PIPESTATUS=true
assertEquals "%K{001} %F{226}%f %F{226}0|0|1|0 %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226} %F{226}0|0|1|0 %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testStatusCrossWinsOverVerbose() {
@ -63,7 +63,7 @@ function testStatusCrossWinsOverVerbose() {
local P9K_STATUS_VERBOSE=true
local P9K_STATUS_CROSS=true
assertEquals "%K{000} %F{001}%f %k%F{000}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{000} %F{001} %k%F{000}%f " "$(__p9k_build_left_prompt)"
}
function testStatusShowsSignalNameInErrorCase() {
@ -73,7 +73,7 @@ function testStatusShowsSignalNameInErrorCase() {
local P9K_STATUS_VERBOSE=true
local P9K_STATUS_HIDE_SIGNAME=false
assertEquals "%K{001} %F{226}%f %F{226}SIGILL(4) %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{226} %F{226}SIGILL(4) %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testStatusSegmentIntegrated() {
@ -82,7 +82,7 @@ function testStatusSegmentIntegrated() {
false; __p9k_prepare_prompts
assertEquals "%f%b%k%K{000} %F{001}%f %k%F{000}%f " "${(e)PROMPT}"
assertEquals "%f%b%k%K{000} %F{001} %k%F{000}%f " "${(e)PROMPT}"
}
source shunit2/shunit2

View File

@ -40,7 +40,7 @@ function testSwapSegmentWorksOnOsx() {
local __P9K_OS="OSX" # Fake OSX
assertEquals "%K{003} %F{000}SWP%f %F{000}1.58G " "$(prompt_swap left 1 false ${FOLDER})"
assertEquals "%K{003} %F{000}SWP %F{000}1.58G " "$(prompt_swap left 1 false ${FOLDER})"
unfunction sysctl
}
@ -54,7 +54,7 @@ function testSwapSegmentWorksOnLinux() {
local __P9K_OS="Linux" # Fake Linux
assertEquals "%K{003} %F{000}SWP%f %F{000}0.95G " "$(prompt_swap left 1 false ${FOLDER})"
assertEquals "%K{003} %F{000}SWP %F{000}0.95G " "$(prompt_swap left 1 false ${FOLDER})"
}
source shunit2/shunit2

View File

@ -49,7 +49,7 @@ function testSwiftSegmentWorks() {
echo "Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)\nTarget: x86_64-apple-macosx10.9"
}
assertEquals "%K{005} %F{015}Swift%f %F{015}3.0.1 %k%F{005}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{005} %F{015}Swift %F{015}3.0.1 %k%F{005}%f " "$(__p9k_build_left_prompt)"
unfunction swift
}

View File

@ -55,7 +55,7 @@ function testTodoSegmentWorksAsExpected() {
echo 'echo "TODO: 34 of 100 tasks shown";' >> ${FOLDER}/bin/todo.sh
chmod +x ${FOLDER}/bin/todo.sh
assertEquals "%K{244} %F{000}%f %F{000}100 %k%F{244}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{244} %F{000} %F{000}100 %k%F{244}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -61,7 +61,7 @@ function testVagrantSegmentSaysVmIsDownIfVirtualboxIsNotAvailableButVagrantFolde
local PATH=/bin:/usr/bin
mockVagrantFolder "some-id"
assertEquals "%K{001} %F{000}V%f %F{000}DOWN %K{015}%F{001} %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{000}V %F{000}DOWN %K{015}%F{001} %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testVagrantSegmentWorksIfVmIsUp() {
@ -71,7 +71,7 @@ function testVagrantSegmentWorksIfVmIsUp() {
mockVBoxManage "${vagrantId}"
mockVagrantFolder "${vagrantId}"
assertEquals "%K{002} %F{000}V%f %F{000}UP %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}V %F{000}UP %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testVagrantSegmentWorksIfVmIsDown() {
@ -81,7 +81,7 @@ function testVagrantSegmentWorksIfVmIsDown() {
mockVBoxManage "${vagrantId}"
mockVagrantFolder "another-vm-id"
assertEquals "%K{001} %F{000}V%f %F{000}DOWN %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{000}V %F{000}DOWN %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testVagrantSegmentWorksIfVmIsUpFromWithinSubdir() {
@ -94,7 +94,7 @@ function testVagrantSegmentWorksIfVmIsUpFromWithinSubdir() {
mkdir -p "subfolder/1/2/3"
cd subfolder/1/2/3
assertEquals "%K{002} %F{000}V%f %F{000}UP %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}V %F{000}UP %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testVagrantSegmentWithChangedString() {
@ -104,11 +104,11 @@ function testVagrantSegmentWithChangedString() {
mockVagrantFolder "${vagrantId}"
local P9K_VAGRANT_DOWN_STRING="Nope"
assertEquals "%K{001} %F{000}V%f %F{000}Nope %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{000}V %F{000}Nope %k%F{001}%f " "$(__p9k_build_left_prompt)"
mockVBoxManage "${vagrantId}"
local P9K_VAGRANT_UP_STRING="Yep"
assertEquals "%K{002} %F{000}V%f %F{000}Yep %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}V %F{000}Yep %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -136,10 +136,10 @@ function +vi-git-untracked() {
# dump out if we're outside a git repository (which includes being in the .git folder)
[[ $? != 0 || -z $repoTopLevel ]] && return
local untrackedFiles=$(command git ls-files --others --exclude-standard "${repoTopLevel}")
local untrackedFiles=$(command git ls-files --others --exclude-standard "${repoTopLevel}" 2> /dev/null)
if [[ -z $untrackedFiles && "$P9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" ]]; then
untrackedFiles+=$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')
untrackedFiles+=$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard' 2> /dev/null)
fi
[[ -z $untrackedFiles ]] && return

View File

@ -118,7 +118,7 @@ function testColorOverridingForUntrackedStateWorks() {
touch testfile
assertEquals "%K{003} %F{006}?%f %F{006} master ? %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{006}? %F{006} master ? %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
function testGitIconWorks() {
@ -126,7 +126,7 @@ function testGitIconWorks() {
local P9K_VCS_GIT_ICON='Git-icon'
source "${P9K_HOME}/segments/vcs/vcs.p9k"
assertEquals "%K{002} %F{000}Git-icon%f %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}Git-icon %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testGitlabIconWorks() {
@ -139,7 +139,7 @@ function testGitlabIconWorks() {
# sufficient to show the GitLab-specific icon.
git remote add origin https://gitlab.com/dritter/gitlab-test-project.git
assertEquals "%K{002} %F{000}GL-icon%f %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}GL-icon %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testBitbucketIconWorks() {
@ -152,7 +152,7 @@ function testBitbucketIconWorks() {
# sufficient to show the BitBucket-specific icon.
git remote add origin https://dritter@bitbucket.org/dritter/dr-test.git
assertEquals "%K{002} %F{000}BB-icon%f %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}BB-icon %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testGitHubIconWorks() {
@ -165,7 +165,7 @@ function testGitHubIconWorks() {
# sufficient to show the GitHub-specific icon.
git remote add origin https://github.com/dritter/test.git
assertEquals "%K{002} %F{000}GH-icon%f %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}GH-icon %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testUntrackedFilesIconWorks() {
@ -176,7 +176,7 @@ function testUntrackedFilesIconWorks() {
# Create untracked file
touch "i-am-untracked.txt"
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testStagedFilesIconWorks() {
@ -365,10 +365,10 @@ function testBranchNameTruncatingShortenLength() {
touch testfile
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
local P9K_VCS_SHORTEN_LENGTH=3
assertEquals "%K{002} %F{000}?%f %F{000} mas ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} mas ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testBranchNameTruncatingMinLength() {
@ -381,11 +381,11 @@ function testBranchNameTruncatingMinLength() {
touch testfile
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
local P9K_VCS_SHORTEN_MIN_LENGTH=7
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testBranchNameTruncatingShortenStrategy() {
@ -398,11 +398,11 @@ function testBranchNameTruncatingShortenStrategy() {
touch testfile
assertEquals "%K{002} %F{000}?%f %F{000} mas ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} mas ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
local P9K_VCS_SHORTEN_STRATEGY="truncate_middle"
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testRemoteBranchNameIdenticalToTag() {
@ -511,7 +511,7 @@ function testDetectingUntrackedFilesInSubmodulesWork() {
touch "i-am-untracked.txt"
cd -
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testDetectinUntrackedFilesInMainRepoWithDirtySubmodulesWork() {
@ -536,7 +536,7 @@ function testDetectinUntrackedFilesInMainRepoWithDirtySubmodulesWork() {
# Create untracked file
touch "i-am-untracked.txt"
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testDetectingUntrackedFilesInNestedSubmodulesWork() {
@ -578,7 +578,7 @@ function testDetectingUntrackedFilesInNestedSubmodulesWork() {
touch "i-am-untracked.txt"
cd -
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testDetectingUntrackedFilesInCleanSubdirectoryWorks() {
@ -600,7 +600,7 @@ function testDetectingUntrackedFilesInCleanSubdirectoryWorks() {
touch dirty-folder/new-file.txt
cd clean-folder
assertEquals "%K{002} %F{000}?%f %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}? %F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testBranchNameScriptingVulnerability() {

View File

@ -194,7 +194,7 @@ function testMercurialIconWorks() {
# Load Powerlevel9k
source ${P9K_HOME}/segments/vcs/vcs.p9k
assertEquals "%K{002} %F{000}HG-icon%f %F{000} default %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{002} %F{000}HG-icon %F{000} default %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testBookmarkIconWorks() {

View File

@ -28,7 +28,8 @@
# [virtualenv (Python)](https://virtualenv.pypa.io/en/latest/)
# for more information.
prompt_virtualenv() {
if [[ -n "${VIRTUAL_ENV}" && "${VIRTUAL_ENV_DISABLE_PROMPT}" != true ]]; then
p9k::prepare_segment "$0" "" $1 "$2" $3 "${VIRTUAL_ENV:t}"
fi
# Early exit; $virtualenv_path must always be set.
[[ -z "$virtualenv_path" ]] && return
p9k::prepare_segment "$0" "" $1 "$2" $3 "${VIRTUAL_ENV:t}"
}

View File

@ -27,11 +27,13 @@
# $1 string Alignment - left | right
# $2 integer Segment index
# $3 boolean Whether the segment should be joined
# $4 Root Prefix: string - Root prefix for testing purposes
##
prompt_vpn_ip() {
for vpn_iface in $(/sbin/ifconfig | grep -e ^"$P9K_VPN_IP_INTERFACE" | cut -d":" -f1)
do
ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2)
local ROOT_PREFIX="${4}"
local ip=$(p9k::parseIp "${P9K_VPN_IP_INTERFACE}" "${ROOT_PREFIX}")
if [[ -n "${ip}" ]]; then
p9k::prepare_segment "$0" "" $1 "$2" $3 "$ip"
done
fi
}

200
segments/vpn_ip/vpn_ip.spec Executable file
View File

@ -0,0 +1,200 @@
#!/usr/bin/env zsh
#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
# Required for shunit2 to run correctly
setopt shwordsplit
SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
# Test specific
P9K_HOME=$(pwd)
FOLDER=/tmp/powerlevel9k-test
mkdir -p $FOLDER
mkdir $FOLDER/sbin
}
function tearDown() {
# Go back to powerlevel9k folder
cd "${P9K_HOME}"
# Remove eventually created test-specific folder
rm -fr "${FOLDER}"
unset FOLDER
unset P9K_HOME
}
function fakeIfconfig() {
# Fake ifconfig
cat > $FOLDER/sbin/ifconfig <<EOF
#!/usr/bin/env zsh
if [[ "\$#" -gt 0 ]]; then
cat <<INNER
tun1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 1.2.3.4 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
INNER
exit 0
fi
cat <<INNER
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:8f:5c:ed:51 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tun1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 1.2.3.4 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xe8200000-e8220000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 5136 bytes 328651 (320.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5136 bytes 328651 (320.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
INNER
EOF
chmod +x $FOLDER/sbin/ifconfig
}
function fakeIp() {
local INTERFACE1="${1}"
[[ -z "${INTERFACE1}" ]] && INTERFACE1="tun0"
local INTERFACE2="${2}"
[[ -z "${INTERFACE2}" ]] && INTERFACE2="disabled-if2"
cat > $FOLDER/sbin/ip <<EOF
#!/usr/bin/env zsh
if [[ "\$*" == 'link ls up' ]]; then
cat <<INNER
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ${INTERFACE1}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff
3: ${INTERFACE2}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff
INNER
fi
if [[ "\$*" =~ '-brief.*show' ]]; then
cat <<INNER
lo UNKNOWN 127.0.0.1/8
${INTERFACE1} UP 1.2.3.4/24
${INTERFACE2} UP 5.4.3.2/16
docker0 DOWN 172.17.0.1/16
INNER
fi
if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then
cat <<INNER
2: ${INTERFACE1}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever
INNER
fi
if [[ "\$*" =~ 'show ${INTERFACE2}' ]]; then
cat <<INNER
3: ${INTERFACE2}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 1.2.3.4 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever
INNER
fi
EOF
chmod +x $FOLDER/sbin/ip
}
function testVpnIpSegmentPrintsNothingOnOsxIfNotConnected() {
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/vpn_ip/vpn_ip.p9k
local OS="OSX" # Fake OSX
cat > $FOLDER/sbin/ifconfig <<EOF
#!/usr/bin/env zsh
echo "not connected"
EOF
chmod +x $FOLDER/sbin/ifconfig
assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")"
}
function testVpnIpSegmentPrintsNothingOnLinuxIfNotConnected() {
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/vpn_ip/vpn_ip.p9k
local OS="Linux" # Fake Linux
cat > $FOLDER/sbin/ip <<EOF
#!/usr/bin/env zsh
echo "not connected"
EOF
chmod +x $FOLDER/sbin/ip
assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")"
}
function testVpnIpSegmentWorksOnOsxWithInterfaceSpecified() {
local P9K_VPN_IP_INTERFACE='tun1'
fakeIfconfig
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/vpn_ip/vpn_ip.p9k
local OS='OSX' # Fake OSX
assertEquals "%K{006} %F{000}(vpn) %F{000}1.2.3.4 " "$(prompt_vpn_ip left 1 false "$FOLDER")"
}
function testVpnIpSegmentWorksOnLinuxWithInterfaceSpecified() {
local P9K_VPN_IP_INTERFACE='tun1'
fakeIp "tun1"
# Load Powerlevel9k
source powerlevel9k.zsh-theme
source segments/vpn_ip/vpn_ip.p9k
local OS='Linux' # Fake Linux
assertEquals "%K{006} %F{000}(vpn) %F{000}1.2.3.4 " "$(prompt_vpn_ip left 1 false "$FOLDER")"
}
# vpn_ip is not capable of handling multiple vpn interfaces ATM.
# function testVpnIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() {
# local P9K_VPN_IP_INTERFACE=(tun0 tun1)
# fakeIp "tun0" "tun1"
# # Load Powerlevel9k
# source powerlevel9k.zsh-theme
# source segments/vpn_ip/vpn_ip.p9k
# local OS='Linux' # Fake Linux
# setopt xtrace
# assertEquals "%K{006} %F{000}(vpn) %F{000}10.0.2.15 " "$(prompt_vpn_ip left 1 false "$FOLDER")"
# unsetopt xtrace
# }
source shunit2/shunit2

View File

@ -19,7 +19,7 @@ function testDynamicColoringOfSegmentsWork() {
local P9K_DATE_BACKGROUND='red'
source segments/date/date.p9k
assertEquals "%K{001} %F{000}date-icon%f %F{000}%D{%d.%m.%y} %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{000}date-icon %F{000}%D{%d.%m.%y} %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testDynamicColoringOfVisualIdentifiersWork() {
@ -28,7 +28,7 @@ function testDynamicColoringOfVisualIdentifiersWork() {
local P9K_DATE_ICON_COLOR='green'
source segments/date/date.p9k
assertEquals "%K{015} %F{002}date-icon%f %F{000}%D{%d.%m.%y} %k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{015} %F{002}date-icon %F{000}%D{%d.%m.%y} %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
@ -39,7 +39,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
local P9K_DATE_BACKGROUND='yellow'
source segments/date/date.p9k
assertEquals "%K{003} %F{002}date-icon%f %F{001}%D{%d.%m.%y} %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{002}date-icon %F{001}%D{%d.%m.%y} %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
function testColorOverridingOfStatefulSegment() {
@ -51,7 +51,7 @@ function testColorOverridingOfStatefulSegment() {
local SSH_CLIENT="x"
source segments/host/host.p9k
assertEquals "%K{001} %F{002}ssh-icon%f %F{002}%m %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{002}ssh-icon %F{002}%m %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
function testColorOverridingOfCustomSegment() {
@ -62,7 +62,7 @@ function testColorOverridingOfCustomSegment() {
local P9K_CUSTOM_WORLD_FOREGROUND='red'
local P9K_CUSTOM_WORLD_BACKGROUND='red'
assertEquals "%K{001} %F{002}CW%f %F{001}world %k%F{001}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{001} %F{002}CW %F{001}world %k%F{001}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -96,7 +96,7 @@ function testLeftJoiningBuiltinSegmentWorks() {
alias php="echo PHP 1.2.3 "
source segments/php_version/php_version.p9k
assertEquals "%K{013} %F{255}PHP%f %F{255}1.2.3 %F{255}PHP%f %F{255}1.2.3 %k%F{013}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{013} %F{255}PHP %F{255}1.2.3 %F{255}PHP %F{255}1.2.3 %k%F{013}%f " "$(__p9k_build_left_prompt)"
unalias php
}

View File

@ -163,7 +163,7 @@ function testCustomWhitespaceOfSegments() {
local P9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS="_[R]_"
local P9K_MIDDLE_WHITESPACE_OF_RIGHT_SEGMENTS="_[M]_"
assertEquals "%K{015}_[L]_%F{000}{1}%f_[M]_%F{000}world1_[L]__[L]_%F{000}world2_[L]__[L]_%F{000}{3}%f_[M]_%F{000}world3_[L]_%k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{015}_[L]_%F{000}{1}_[M]_%F{000}world1_[L]__[L]_%F{000}world2_[L]__[L]_%F{000}{3}_[M]_%F{000}world3_[L]_%k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%F{015}%K{015}%F{000}_[R]_world1_[M]_%F{000}{1}%f_[R]_%F{000}%K{015}%F{000}_[R]_world2_[R]_%F{000}%K{015}%F{000}_[R]_world3_[M]_%F{000}{3}%f_[R]" "$(stripEsc "$(__p9k_build_right_prompt)")"
}
@ -189,7 +189,7 @@ function testCustomWhitespaceOfLeftAndRightSegments() {
local P9K_MIDDLE_WHITESPACE_OF_RIGHT_SEGMENTS="_[RM]_"
local P9K_RIGHT_WHITESPACE_OF_RIGHT_SEGMENTS="_[RR]_"
assertEquals "%K{015}_[LL]_%F{000}{1}%f_[LM]_%F{000}world1_[LR]__[LL]_%F{000}world2_[LR]__[LL]_%F{000}{3}%f_[LM]_%F{000}world3_[LR]_%k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{015}_[LL]_%F{000}{1}_[LM]_%F{000}world1_[LR]__[LL]_%F{000}world2_[LR]__[LL]_%F{000}{3}_[LM]_%F{000}world3_[LR]_%k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%F{015}%K{015}%F{000}_[RL]_world1_[RM]_%F{000}{1}%f_[RR]_%F{000}%K{015}%F{000}_[RL]_world2_[RR]_%F{000}%K{015}%F{000}_[RL]_world3_[RM]_%F{000}{3}%f_[RR]" "$(stripEsc "$(__p9k_build_right_prompt)")"
}
@ -219,7 +219,7 @@ function testCustomWhitespaceOfCustomSegments() {
local P9K_CUSTOM_WORLD3_MIDDLE_WHITESPACE="_[M3]_"
local P9K_CUSTOM_WORLD3_RIGHT_WHITESPACE="_[R3]_"
assertEquals "%K{015}_[L1]_%F{000}{1}%f_[M1]_%F{000}world1_[R1]__[L2]_%F{000}world2_[R2]__[L3]_%F{000}{3}%f_[M3]_%F{000}world3_[R3]_%k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{015}_[L1]_%F{000}{1}_[M1]_%F{000}world1_[R1]__[L2]_%F{000}world2_[R2]__[L3]_%F{000}{3}_[M3]_%F{000}world3_[R3]_%k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%F{015}%K{015}%F{000}_[L1]_world1_[M1]_%F{000}{1}%f_[R1]_%F{000}%K{015}%F{000}_[L2]_world2_[R2]_%F{000}%K{015}%F{000}_[L3]_world3_[M3]_%F{000}{3}%f_[R3]" "$(stripEsc "$(__p9k_build_right_prompt)")"
}

View File

@ -21,7 +21,7 @@ function testOverwritingIconsWork() {
local P9K_CUSTOM_WORLD1='echo world1'
local P9K_CUSTOM_WORLD1_ICON='icon-here'
assertEquals "%K{015} %F{000}icon-here%f %F{000}world1 %k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{015} %F{000}icon-here %F{000}world1 %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() {
@ -31,7 +31,7 @@ function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() {
local P9K_CUSTOM_WORLD1='echo world1'
local P9K_CUSTOM_WORLD1_ICON='icon-here'
assertEquals "%K{015} %F{000}icon-here%f %F{000}world1 %k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{015} %F{000}icon-here %F{000}world1 %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() {
@ -60,7 +60,7 @@ function testVisualIdentifierWorksWithUnicodeIcon() {
local P9K_CUSTOM_WORLD1='echo world1'
local P9K_CUSTOM_WORLD1_ICON='\u2714'
assertEquals "%K{015} %F{000}%f %F{000}world1 %k%F{015}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{015} %F{000} %F{000}world1 %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2

View File

@ -81,7 +81,7 @@ function testDynamicColoringOfVisualIdentifiersWork() {
cd /tmp
assertEquals "%K{004} %F{002}icon-here%f %F{000}/tmp %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{002}icon-here %F{000}/tmp %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
}
@ -101,7 +101,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
cd /tmp
assertEquals "%K{003} %F{002}icon-here%f %F{001}/tmp %k%F{003}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{003} %F{002}icon-here %F{001}/tmp %k%F{003}%f " "$(__p9k_build_left_prompt)"
cd -
}
@ -118,7 +118,7 @@ function testOverwritingIconsWork() {
#cd ~/$testFolder
cd /tmp
assertEquals "%K{004} %F{000}icon-here%f %F{000}/tmp %k%F{004}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{004} %F{000}icon-here %F{000}/tmp %k%F{004}%f " "$(__p9k_build_left_prompt)"
cd -
# rm -fr ~/$testFolder

View File

@ -1,73 +0,0 @@
#!/usr/bin/env zsh
#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
# Required for shunit2 to run correctly
setopt shwordsplit
SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
local -a P9K_RIGHT_PROMPT_ELEMENTS
P9K_RIGHT_PROMPT_ELEMENTS=()
# Load Powerlevel9k
source powerlevel9k.zsh-theme
}
function testCustomDirectOutputSegment() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(custom_world)
local P9K_CUSTOM_WORLD="echo world"
assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testCustomClosureSegment() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(custom_world)
function p9k_hello_world() {
echo "world"
}
local P9K_CUSTOM_WORLD='p9k_hello_world'
assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testSettingBackgroundForCustomSegment() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(custom_world)
local P9K_CUSTOM_WORLD="echo world"
local P9K_CUSTOM_WORLD_BACKGROUND="yellow"
assertEquals "%K{003} %F{000}world %k%F{003}%f " "$(__p9k_build_left_prompt)"
}
function testSettingForegroundForCustomSegment() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(custom_world)
local P9K_CUSTOM_WORLD="echo world"
local P9K_CUSTOM_WORLD_FOREGROUND="red"
assertEquals "%K{015} %F{001}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testSettingVisualIdentifierForCustomSegment() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(custom_world)
local P9K_CUSTOM_WORLD="echo world"
local P9K_CUSTOM_WORLD_ICON="hw"
assertEquals "%K{015} %F{000}hw%f %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
function testSettingVisualIdentifierForegroundColorForCustomSegment() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(custom_world)
local P9K_CUSTOM_WORLD="echo world"
local P9K_CUSTOM_WORLD_ICON="hw"
local P9K_CUSTOM_WORLD_ICON_COLOR="red"
assertEquals "%K{015} %F{001}hw%f %F{000}world %k%F{015}%f " "$(__p9k_build_left_prompt)"
}
source shunit2/shunit2