aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml84
-rw-r--r--README.md2
-rw-r--r--TESTS.md44
-rwxr-xr-xdebug/font-issues.zsh337
-rw-r--r--docker/base-5.0.3/Dockerfile2
-rw-r--r--docker/base-5.1.1/Dockerfile2
-rw-r--r--docker/base-5.2/Dockerfile4
-rw-r--r--docker/base-5.3.1/Dockerfile40
-rw-r--r--docker/base-5.4.2/Dockerfile35
-rw-r--r--docker/base-5.5.1/Dockerfile35
-rw-r--r--docker/prezto/install.zsh2
-rw-r--r--docker/zshing/Dockerfile7
-rw-r--r--docker/zshing/install.zsh16
-rwxr-xr-xfunctions/colors.zsh4
-rwxr-xr-xpowerlevel9k.zsh-theme119
m---------shunit20
-rwxr-xr-xtest-in-docker75
-rwxr-xr-xtest/core/color_overriding.spec62
-rwxr-xr-xtest/core/joining_segments.spec187
-rwxr-xr-xtest/core/prompt.spec104
-rwxr-xr-xtest/core/visual_identifier.spec50
-rwxr-xr-xtest/functions/colors.spec2
-rwxr-xr-xtest/functions/icons.spec145
-rwxr-xr-xtest/functions/utilities.spec2
-rwxr-xr-xtest/powerlevel9k.spec57
-rwxr-xr-xtest/segments/anaconda.spec69
-rwxr-xr-xtest/segments/aws_eb_env.spec61
-rwxr-xr-xtest/segments/background_jobs.spec78
-rwxr-xr-xtest/segments/battery.spec177
-rwxr-xr-xtest/segments/command_execution_time.spec94
-rwxr-xr-xtest/segments/context.spec113
-rwxr-xr-xtest/segments/custom.spec86
-rwxr-xr-xtest/segments/detect_virt.spec83
-rwxr-xr-xtest/segments/dir.spec480
-rwxr-xr-xtest/segments/disk_usage.spec131
-rwxr-xr-xtest/segments/go_version.spec50
-rwxr-xr-xtest/segments/ip.spec231
-rwxr-xr-xtest/segments/kubecontext.spec28
-rwxr-xr-xtest/segments/laravel_version.spec49
-rwxr-xr-xtest/segments/load.spec149
-rwxr-xr-xtest/segments/node_version.spec41
-rwxr-xr-xtest/segments/nodeenv.spec99
-rwxr-xr-xtest/segments/nvm.spec72
-rwxr-xr-xtest/segments/php_version.spec42
-rwxr-xr-xtest/segments/public_ip.spec222
-rwxr-xr-xtest/segments/ram.spec66
-rwxr-xr-xtest/segments/rust_version.spec21
-rwxr-xr-xtest/segments/ssh.spec80
-rwxr-xr-xtest/segments/status.spec60
-rwxr-xr-xtest/segments/swap.spec58
-rwxr-xr-xtest/segments/swift_version.spec57
-rwxr-xr-xtest/segments/symfony_version.spec117
-rwxr-xr-xtest/segments/todo.spec58
-rwxr-xr-xtest/segments/vcs-git.spec378
-rwxr-xr-xtest/segments/vcs-hg.spec207
-rwxr-xr-xtest/segments/vcs.spec161
-rwxr-xr-xtest/segments/vi_mode.spec48
-rwxr-xr-xtest/suite.spec17
58 files changed, 4418 insertions, 682 deletions
diff --git a/.travis.yml b/.travis.yml
index 136b661e..30631ea8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,33 +1,77 @@
-sudo: true
-dist: trusty
language: sh
+
+os:
+ - linux
+ - osx
+
+osx_image: xcode9.4
+
addons:
apt:
packages:
- build-essential
+ - git
+ - mercurial
+ - subversion
+ - jq
+ - node
+ - golang
+ - ruby
+ - python
+ - python-virtualenv
+
+before_install:
+ - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
+
+env:
+ global:
+ - ZSH_DIST=$HOME/.zshdist
+ matrix:
+ # Use _ZSH_VERSION since if ZSH_VERSION is present, travis cacher thinks it
+ # is running in zsh and tries to use zsh specific functions.
+ - _ZSH_VERSION=5.5.1
+ - _ZSH_VERSION=5.5
+ - _ZSH_VERSION=5.4.2
+ - _ZSH_VERSION=5.4.1
+ - _ZSH_VERSION=5.3.1
+ - _ZSH_VERSION=5.3
+ - _ZSH_VERSION=5.2
+ - _ZSH_VERSION=5.1.1
+
+cache:
+ directories:
+ - $ZSH_DIST
before_script:
+ - >
+ setup_zsh() {
+ dest="$ZSH_DIST/$1"
+ if [[ ! -d $dest/bin ]]; then
+ coreutils_mktemp="mktemp"
+ if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
+ coreutils_mktemp="gmktemp"
+ fi
+ tmp="$(${coreutils_mktemp} --directory --tmpdir="${TMPDIR:/tmp}" zshbuild.XXXXXX)"
+ (
+ cd "$tmp" &&
+ curl -L http://downloads.sourceforge.net/zsh/zsh-${1}.tar.gz | tar zx &&
+ cd zsh-$1 &&
+ ./configure --prefix="$dest" &&
+ make &&
+ mkdir -p "$dest" &&
+ make install ||
+ echo "Failed to build zsh-${1}!"
+ )
+ fi
+ export PATH="$dest/bin:$PATH"
+ }
+ - setup_zsh $_ZSH_VERSION
# Show the git version being used to test.
- "git --version"
+ # Show the mercurial version being used to test.
+ - "hg --version"
# Show the zsh version being used to test.
- "zsh --version"
-install:
- - "sudo apt-get update -qq"
- - "sudo apt-get install -y zsh"
- - "sudo chsh -s $(which zsh)"
- - "sudo apt-get install -y git mercurial subversion jq node golang ruby python python-virtualenv"
-
script:
- - test/powerlevel9k.spec
- - test/functions/utilities.spec
- - test/functions/colors.spec
- - test/functions/icons.spec
- - test/segments/command_execution_time.spec
- - test/segments/dir.spec
- - test/segments/rust_version.spec
- - test/segments/go_version.spec
- - test/segments/vcs.spec
- - test/segments/kubecontext.spec
- - test/segments/laravel_version.spec
- - test/segments/status.spec
+ - test/suite.spec
diff --git a/README.md b/README.md
index 9989d9cc..51c68d70 100644
--- a/README.md
+++ b/README.md
@@ -386,12 +386,14 @@ Powerline" fonts, there are additional glyphs, as well:
| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183451/40ec4016-b58f-11e5-9b9e-74e2b2f0b8b3.png) | At the root of your home folder |
| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12369315/8a5d762c-bbf5-11e5-8a20-ca1179f48d6c.png) | Within a subfolder of your home directory |
| None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183452/40f79286-b58f-11e5-9b8c-ed1343a07b08.png) | Outside of your home folder |
+| None | None | ⚙ | Within the `/etc` directory |
To turn off these icons you could set these variables to an empty string.
```zsh
POWERLEVEL9K_HOME_ICON=''
POWERLEVEL9K_HOME_SUB_ICON=''
POWERLEVEL9K_FOLDER_ICON=''
+POWERLEVEL9K_ETC_ICON=''
```
You can limit the output to a certain length by truncating long paths.
Customizations available are:
diff --git a/TESTS.md b/TESTS.md
index eb5db704..b57c4d6d 100644
--- a/TESTS.md
+++ b/TESTS.md
@@ -1,25 +1,45 @@
-# Structure
+# Tests
-The Unit-Tests do not follow exactly the file structure of Powerlevel9k itself.
+## Automated Tests
-## Basic Tests
+The Unit-Tests do not follow exactly the file structure of Powerlevel9k itself,
+but we try to reflect the structure as much as possible. All tests are located
+under `test/`. Segment specific tests under `test/segments/` (one file per
+segment).
-Basic Tests belong in `test/powerlevel9k.spec` if they test basic functionality of
-Powerlevel9k itself. Basic functions from the `functions` directory have their
-Tests in separate files under `test/functions`.
+### Installation
-## Segment Tests
+In order to execute the tests you need to install `shunit2`, which is a
+submodule. To install the submodule, you can execute
+`git submodule init && git submodule update`.
-These Tests tend to be more complex in setup than the basic tests. To avoid ending
-up in a huge single file, there is one file per segment in `test/segments`.
+### Executing tests
-# Manual Testing
+The tests are shell scripts on their own. So you can execute them right away.
+To execute all tests you could just execute `./test/suite.spec`.
+
+### General Test Structure
+
+The tests usually have a `setUp()` function which is executed before every
+test function. Speaking of, test functions must be prefixed with `test`. In
+the tests, you can do [different Assertions](https://github.com/kward/shunit2#-asserts).
+It is always a good idea to mock the program you want to test (just have a
+look at other tests), so that the testrunner does not have to have all
+programs installed.
+
+### Travis
+
+We use [Travis](https://travis-ci.org/) for Continuous Integration. This
+service executes our tests after every push. For now, we need to tell travis
+where to find the tests, which is what happens in the `.travis.yml` file.
+
+## Manual Testing
If unit tests are not sufficient (e.g. you have an issue with your prompt that
occurs only in a specific ZSH framework) then you can use either Docker or
or our Vagrant.
-## Docker
+### Docker
This is the easiest to use _if_ you have Docker already installed and running.
@@ -42,7 +62,7 @@ You can get Docker at <https://www.docker.com/community-edition>.
**Note:** Not all frameworks work with all versions of ZSH (or the underlying OS).
-## Vagrant
+### Vagrant
Currently there are two test VMs. `test-vm` is an Ubuntu machine with several
pre-installed ZSH frameworks. And there is `test-bsd-vm` which is a FreeBSD!
diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh
index 166a6ac5..82f8e60b 100755
--- a/debug/font-issues.zsh
+++ b/debug/font-issues.zsh
@@ -1,111 +1,236 @@
#!/usr/bin/env zsh
#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+source functions/colors.zsh
+source functions/icons.zsh
+source functions/utilities.zsh
+# Map our $OS to neofetch $os
+os="$OS"
+
+
+trim() {
+ set -f
+ # shellcheck disable=2048,2086
+ set -- $*
+ printf '%s\n' "${*//[[:space:]]/}"
+ set +f
+}
+
+get_ppid() {
+ # Get parent process ID of PID.
+ case "$os" in
+ "Windows")
+ ppid="$(ps -p "${1:-$PPID}" | awk '{printf $2}')"
+ ppid="${ppid/PPID}"
+ ;;
+
+ "Linux")
+ ppid="$(grep -i -F "PPid:" "/proc/${1:-$PPID}/status")"
+ ppid="$(trim "${ppid/PPid:}")"
+ ;;
+
+ *)
+ ppid="$(ps -p "${1:-$PPID}" -o ppid=)"
+ ;;
+ esac
+
+ printf "%s" "$ppid"
+}
+
+get_process_name() {
+ # Get PID name.
+ case "$os" in
+ "Windows")
+ name="$(ps -p "${1:-$PPID}" | awk '{printf $8}')"
+ name="${name/COMMAND}"
+ name="${name/*\/}"
+ ;;
+
+ "Linux")
+ name="$(< "/proc/${1:-$PPID}/comm")"
+ ;;
+
+ *)
+ name="$(ps -p "${1:-$PPID}" -o comm=)"
+ ;;
+ esac
+
+ printf "%s" "$name"
+}
+
# Taken from NeoFetch (slightly modified)
get_term() {
local term
+
# If function was run, stop here.
- #((term_run == 1)) && return
+ # ((term_run == 1)) && return
# Workaround for macOS systems that
# don't support the block below.
case "$TERM_PROGRAM" in
- "iTerm.app") term="iTerm2" ;;
+ "iTerm.app") term="iTerm2" ;;
"Terminal.app") term="Apple Terminal" ;;
- "Hyper") term="HyperTerm" ;;
- *) term="${TERM_PROGRAM/\.app}" ;;
+ "Hyper") term="HyperTerm" ;;
+ *) term="${TERM_PROGRAM/\.app}" ;;
esac
+ # Most likely TosWin2 on FreeMiNT - quick check
+ [[ "$TERM" == "tw52" || "$TERM" == "tw100" ]] && \
+ term="TosWin2"
+
+ [[ "$SSH_CONNECTION" ]] && \
+ term="$SSH_TTY"
+
# Check $PPID for terminal emulator.
while [[ -z "$term" ]]; do
parent="$(get_ppid "$parent")"
+ [[ -z "$parent" ]] && break
name="$(get_process_name "$parent")"
case "${name// }" in
- "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su"*) ;;
- "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;;
- "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) break ;;
+ "${SHELL/*\/}"|*"sh"|"screen"|"su"*) ;;
+
+ "login"*|*"Login"*|"init"|"(init)")
+ term="$(tty)"
+ ;;
+
+ "ruby"|"1"|"tmux"*|"systemd"|"sshd"*|"python"*|"USER"*"PID"*|"kdeinit"*|"launchd"*)
+ break
+ ;;
+
"gnome-terminal-") term="gnome-terminal" ;;
- *) term="${name##*/}" ;;
+ "urxvtd") term="urxvt" ;;
+ *"nvim") term="Neovim Terminal" ;;
+ *"NeoVimServer"*) term="VimR Terminal" ;;
+ *) term="${name##*/}" ;;
esac
done
# Log that the function was run.
- #term_run=1
+ # term_run=1
echo "${term}"
}
get_term_font() {
local term="${1}"
- #((term_run != 1)) && get_term
+ # ((term_run != 1)) && get_term
case "$term" in
"alacritty"*)
- term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${XDG_CONFIG_HOME}/alacritty/alacritty.yml")"
+ shopt -s nullglob
+ confs=({$XDG_CONFIG_HOME,$HOME}/{alacritty,}/{.,}alacritty.ym?)
+ shopt -u nullglob
+
+ [[ -f "${confs[0]}" ]] || return
+
+ term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[0]}")"
term_font="${term_font/*family:}"
term_font="${term_font/$'\n'*}"
term_font="${term_font/\#*}"
;;
"Apple_Terminal")
- term_font="$(osascript -e 'tell application "Terminal" to font name of window frontmost')"
+ term_font="$(osascript <<END
+ tell application "Terminal" to font name of window frontmost
+END
+)"
;;
+
"iTerm2")
# Unfortunately the profile name is not unique, but it seems to be the only thing
- # that identifies an active profile. There is the "id of current session of current window"
- # thou, but that does not match to a guid in the plist.
- # So, be warned! Collisions may occur!
+ # that identifies an active profile. There is the "id of current session of current win-
+ # dow" though, but that does not match to a guid in the plist.
+ # So, be warned, collisions may occur!
# See: https://groups.google.com/forum/#!topic/iterm2-discuss/0tO3xZ4Zlwg
- # and: https://gitlab.com/gnachman/iterm2/issues/5586
- local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window')
+ local current_profile_name profiles_count profile_name diff_font
+
+ current_profile_name="$(osascript <<END
+ tell application "iTerm2" to profile name \
+ of current session of current window
+END
+)"
# Warning: Dynamic profiles are not taken into account here!
# https://www.iterm2.com/documentation-dynamic-profiles.html
+ font_file="${HOME}/Library/Preferences/com.googlecode.iterm2.plist"
- local nonAsciiFont
-
# Count Guids in "New Bookmarks"; they should be unique
- local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep -c "Guid")
- for idx in $(seq 0 "${profilesCount}"); do
- local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null)
- if [[ "${profileName}" == "${currentProfileName}" ]]; then
+ profiles_count="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:'" "$font_file" | \
+ 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")"
+
+ if [[ "$profile_name" == "$current_profile_name" ]]; then
# "Normal Font"
- term_font=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)
-
+ term_font="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Normal Font:'" \
+ "$font_file")"
+
# 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.
- local useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)
- if [[ "$useDifferentFont" == "true" ]]; then
- local nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist)
- if [[ "$term_font" != "$nonAsciiFont" ]]; then
- term_font="$term_font (normal) / $nonAsciiFont (non-ascii)"
- fi
+ diff_font="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Use Non-ASCII Font:'" \
+ "$font_file")"
+
+ if [[ "$diff_font" == "true" ]]; then
+ non_ascii="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Non Ascii Font:'" \
+ "$font_file")"
+
+ [[ "$term_font" != "$non_ascii" ]] && \
+ term_font="$term_font (normal) / $non_ascii (non-ascii)"
fi
fi
done
;;
"deepin-terminal"*)
- term_font="$(awk -F '=' '/font=/ {a=$2} /font_size/ {b=$2} END{print a " " b}' "${XDG_CONFIG_HOME}/deepin/deepin-terminal/config.conf")"
+ 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}' \
+ "${HOME}/GNUstep/Defaults/Terminal.plist")"
;;
"Hyper"*)
- term_font="$(awk -F "," '/fontFamily/ {a=$1} END{print a}' "${HOME}/.hyper.js" | awk -F "'" '{a=$2} END{print a}')"
+ term_font="$(awk -F':|,' '/fontFamily/ {print $2; exit}' "${HOME}/.hyper.js")"
+ term_font="$(trim_quotes "$term_font")"
+ ;;
+
+ "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]}")"
;;
"konsole"*)
# Get Process ID of current konsole window / tab
child="$(get_ppid "$$")"
- konsole_instances=($(qdbus | grep 'org.kde.konsole'))
+ IFS=$'\n' read -d "" -ra konsole_instances < <(qdbus | grep -F 'org.kde.konsole')
for i in "${konsole_instances[@]}"; do
- konsole_sessions=($(qdbus "${i}" | grep '/Sessions/'))
+ IFS=$'\n' read -d "" -ra konsole_sessions < <(qdbus "$i" | grep -F '/Sessions/')
+
for session in "${konsole_sessions[@]}"; do
- if ((child == "$(qdbus "${i}" "${session}" processId)")); then
- profile="$(qdbus "${i}" "${session}" environment | awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')"
+ if ((child == "$(qdbus "$i" "$session" processId)")); then
+ profile="$(qdbus "$i" "$session" environment |\
+ awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')"
break
fi
done
@@ -113,9 +238,53 @@ get_term_font() {
done
# We could have two profile files for the same profile name, take first match
- profile_filename="$(grep -l "Name=${profile}" "${HOME}"/.local/share/konsole/*.profile)"
+ profile_filename="$(grep -l "Name=${profile}" "$HOME"/.local/share/konsole/*.profile)"
profile_filename="${profile_filename/$'\n'*}"
- [[ "$profile_filename" ]] && term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "$profile_filename")"
+
+ [[ "$profile_filename" ]] && \
+ term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "$profile_filename")"
+ ;;
+
+ "lxterminal"*)
+ term_font="$(awk -F '=' '/fontname=/ {print $2; exit}' \
+ "${XDG_CONFIG_HOME}/lxterminal/lxterminal.conf")"
+ ;;
+
+ "mate-terminal")
+ # To get the actual config we have to create a temporarily file with the
+ # --save-config option.
+ mateterm_config="/tmp/mateterm.cfg"
+
+ # Ensure /tmp exists and we do not overwrite anything.
+ if [[ -d /tmp && ! -f "$mateterm_config" ]]; then
+ mate-terminal --save-config="$mateterm_config"
+
+ role="$(xprop -id "${WINDOWID}" WM_WINDOW_ROLE)"
+ role="${role##* }"
+ role="${role//\"}"
+
+ profile="$(awk -F '=' -v r="$role" \
+ '$0~r {
+ getline;
+ if(/Maximized/) getline;
+ if(/Fullscreen/) getline;
+ id=$2"]"
+ } $0~id {if(id) {getline; print $2; exit}}' \
+ "$mateterm_config")"
+
+ rm -f "$mateterm_config"
+
+ mate_get() {
+ gsettings get org.mate.terminal.profile:/org/mate/terminal/profiles/"$1"/ "$2"
+ }
+
+ if [[ "$(mate_get "$profile" "use-system-font")" == "true" ]]; then
+ term_font="$(gsettings get org.mate.interface monospace-font-name)"
+ else
+ term_font="$(mate_get "$profile" "font")"
+ fi
+ term_font="$(trim_quotes "$term_font")"
+ fi
;;
"mintty")
@@ -124,30 +293,91 @@ get_term_font() {
"pantheon"*)
term_font="$(gsettings get org.pantheon.terminal.settings font)"
- [[ -z "${term_font//\'}" ]] && term_font="$(gsettings get org.gnome.desktop.interface monospace-font-name)"
+
+ [[ -z "${term_font//\'}" ]] && \
+ term_font="$(gsettings get org.gnome.desktop.interface monospace-font-name)"
+
term_font="$(trim_quotes "$term_font")"
;;
+ "qterminal")
+ term_font="$(awk -F '=' '/fontFamily=/ {a=$2} /fontSize=/ {b=$2} END {print a " " b}' \
+ "${XDG_CONFIG_HOME}/qterminal.org/qterminal.ini")"
+ ;;
+
"sakura"*)
- term_font="$(awk -F '=' '/^font=/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/sakura/sakura.conf")"
+ term_font="$(awk -F '=' '/^font=/ {print $2; exit}' \
+ "${XDG_CONFIG_HOME}/sakura/sakura.conf")"
+ ;;
+
+ "st")
+ term_font="$(ps -o command= -p "$parent" | grep -F -- "-f")"
+
+ if [[ "$term_font" ]]; then
+ term_font="${term_font/*-f/}"
+ term_font="${term_font/ -*/}"
+
+ else
+ # 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)"
+
+ # 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.
+ # Technically "Font Name" is a valid font. As it doesn't specify any font options
+ # though it is hard to match it correctly amongst the rest of the noise.
+ [[ -n "$binary" ]] && \
+ term_font="$(strings "$binary" | grep -F -m 1 \
+ -e "pixelsize=" \
+ -e "size=" \
+ -e "antialias=" \
+ -e "autohint=")"
+ fi
+
+ term_font="${term_font/xft:}"
+ term_font="${term_font/:*}"
;;
"terminology")
- term_font="$(strings "${XDG_CONFIG_HOME}/terminology/config/standard/base.cfg" | awk '/^font\.name$/{print a}{a=$0}')"
+ term_font="$(strings "${XDG_CONFIG_HOME}/terminology/config/standard/base.cfg" |\
+ awk '/^font\.name$/{print a}{a=$0}')"
term_font="${term_font/.pcf}"
term_font="${term_font/:*}"
;;
"termite")
- [[ -f "${XDG_CONFIG_HOME}/termite/config" ]] && termite_config="${XDG_CONFIG_HOME}/termite/config"
- term_font="$(awk -F '= ' '/\[options\]/ {opt=1} /^font/ {if(opt==1) a=$2; opt=0} END{print a}' "/etc/xdg/termite/config" "$termite_config")"
+ [[ -f "${XDG_CONFIG_HOME}/termite/config" ]] && \
+ termite_config="${XDG_CONFIG_HOME}/termite/config"
+
+ term_font="$(awk -F '= ' '/\[options\]/ {
+ opt=1
+ }
+ /^\s*font/ {
+ if(opt==1) a=$2;
+ opt=0
+ } END {print a}' "/etc/xdg/termite/config" \
+ "$termite_config")"
;;
"urxvt" | "urxvtd" | "rxvt-unicode" | "xterm")
- term_font="$(grep -i -F "${term/d}*font" < <(xrdb -query))"
- term_font="${term_font/*font:}"
+ xrdb="$(xrdb -query)"
+ term_font="$(grep -im 1 -e "^${term/d}"'\**\.*font' -e '^\*font' <<< "$xrdb")"
+ term_font="${term_font/*"*font:"}"
+ term_font="${term_font/*".font:"}"
+ term_font="${term_font/*"*.font:"}"
term_font="$(trim "$term_font")"
+ [[ -z "$term_font" && "$term" == "xterm" ]] && \
+ term_font="$(grep '^XTerm.vt100.faceName' <<< "$xrdb")"
+
+ 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="xft:$term_font"
+
# Xresources has two different font formats, this checks which
# one is in use and formats it accordingly.
case "$term_font" in
@@ -156,12 +386,23 @@ get_term_font() {
term_font="${term_font/:*}"
;;
- "-"*) term_font="$(awk -F '\\-' '{printf $3}' <<< "$term_font")" ;;
+ "-"*)
+ IFS=- read -r _ _ term_font _ <<< "$term_font"
+ ;;
esac
;;
"xfce4-terminal")
- term_font="$(awk -F '=' '/^FontName/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/xfce4/terminal/terminalrc")"
+ term_font="$(awk -F '=' '/^FontName/{a=$2}/^FontUseSystem=TRUE/{a=$0} END {print a}' \
+ "${XDG_CONFIG_HOME}/xfce4/terminal/terminalrc")"
+
+ [[ "$term_font" == "FontUseSystem=TRUE" ]] && \
+ term_font="$(gsettings get org.gnome.desktop.interface monospace-font-name)"
+
+ term_font="$(trim_quotes "$term_font")"
+
+ # Default fallback font hardcoded in terminal-preferences.c
+ [[ -z "$term_font" ]] && term_font="Monospace 12"
;;
esac
diff --git a/docker/base-5.0.3/Dockerfile b/docker/base-5.0.3/Dockerfile
index e0b6c6c3..b1b85fcb 100644
--- a/docker/base-5.0.3/Dockerfile
+++ b/docker/base-5.0.3/Dockerfile
@@ -6,7 +6,7 @@ RUN \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
curl \
git \
- zsh \
+ zsh=5.0.2-3ubuntu6.2 \
mercurial \
subversion \
golang \
diff --git a/docker/base-5.1.1/Dockerfile b/docker/base-5.1.1/Dockerfile
index a7f644bf..c4fb6424 100644
--- a/docker/base-5.1.1/Dockerfile
+++ b/docker/base-5.1.1/Dockerfile
@@ -6,7 +6,7 @@ RUN \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
curl \
git \
- zsh \
+ zsh=5.1.1-1ubuntu2.2 \
mercurial \
subversion \
golang \
diff --git a/docker/base-5.2/Dockerfile b/docker/base-5.2/Dockerfile
index 62a10074..2ec096fc 100644
--- a/docker/base-5.2/Dockerfile
+++ b/docker/base-5.2/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:17.04
+FROM ubuntu:17.10
RUN \
apt-get update && \
@@ -6,7 +6,7 @@ RUN \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
curl \
git \
- zsh \
+ zsh=5.2-5ubuntu1.2 \
mercurial \
subversion \
golang \
diff --git a/docker/base-5.3.1/Dockerfile b/docker/base-5.3.1/Dockerfile
new file mode 100644
index 00000000..0294cf25
--- /dev/null
+++ b/docker/base-5.3.1/Dockerfile
@@ -0,0 +1,40 @@
+FROM debian:stretch
+
+# We switched here to debian, as there seems no ZSH 5.3 in ubuntu.
+
+RUN \
+ apt-get update && \
+ echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y \
+ curl \
+ git \
+ zsh=5.3.1-4+b2 \
+ mercurial \
+ subversion \
+ golang \
+ jq \
+ nodejs \
+ ruby \
+ python \
+ python-virtualenv \
+ sudo \
+ locales
+
+RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred
+# Locale generation is different in debian. We need to enable en_US
+# locale and then regenerate locales.
+RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
+RUN locale-gen "en_US.UTF-8"
+
+COPY docker/fred-sudoers /etc/sudoers.d/fred
+
+USER fred
+WORKDIR /home/fred
+ENV LANG=en_US.UTF-8
+ENV TERM=xterm-256color
+ENV DEFAULT_USER=fred
+ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true
+
+RUN touch .zshrc
+
+CMD ["/bin/zsh", "-l"]
diff --git a/docker/base-5.4.2/Dockerfile b/docker/base-5.4.2/Dockerfile
new file mode 100644
index 00000000..8984c105
--- /dev/null
+++ b/docker/base-5.4.2/Dockerfile
@@ -0,0 +1,35 @@
+FROM ubuntu:18.04
+
+RUN \
+ apt-get update && \
+ echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y \
+ curl \
+ git \
+ zsh=5.4.2-3ubuntu3 \
+ mercurial \
+ subversion \
+ golang \
+ jq \
+ nodejs \
+ ruby \
+ python \
+ python-virtualenv \
+ sudo \
+ locales
+
+RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred
+RUN locale-gen "en_US.UTF-8"
+
+COPY docker/fred-sudoers /etc/sudoers.d/fred
+
+USER fred
+WORKDIR /home/fred
+ENV LANG=en_US.UTF-8
+ENV TERM=xterm-256color
+ENV DEFAULT_USER=fred
+ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true
+
+RUN touch .zshrc
+
+CMD ["/bin/zsh", "-l"]
diff --git a/docker/base-5.5.1/Dockerfile b/docker/base-5.5.1/Dockerfile
new file mode 100644
index 00000000..85fc570c
--- /dev/null
+++ b/docker/base-5.5.1/Dockerfile
@@ -0,0 +1,35 @@
+FROM ubuntu:18.10
+
+RUN \
+ apt-get update && \
+ echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y \
+ curl \
+ git \
+ zsh=5.5.1-1ubuntu1 \
+ mercurial \
+ subversion \
+ golang \
+ jq \
+ nodejs \
+ ruby \
+ python \
+ python-virtualenv \
+ sudo \
+ locales
+
+RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred
+RUN locale-gen "en_US.UTF-8"
+
+COPY docker/fred-sudoers /etc/sudoers.d/fred
+
+USER fred
+WORKDIR /home/fred
+ENV LANG=en_US.UTF-8
+ENV TERM=xterm-256color
+ENV DEFAULT_USER=fred
+ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true
+
+RUN touch .zshrc
+
+CMD ["/bin/zsh", "-l"]
diff --git a/docker/prezto/install.zsh b/docker/prezto/install.zsh
index 9cca57ed..2b2e878c 100644
--- a/docker/prezto/install.zsh
+++ b/docker/prezto/install.zsh
@@ -9,7 +9,7 @@ for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -nsf "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
-ln -s "${HOME}/p9k/powerlevel9k.zsh-theme" \
+ln -snf "${HOME}/p9k/powerlevel9k.zsh-theme" \
"${HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup"
echo "zstyle ':prezto:module:prompt' theme 'powerlevel9k'" \
diff --git a/docker/zshing/Dockerfile b/docker/zshing/Dockerfile
new file mode 100644
index 00000000..a51a3067
--- /dev/null
+++ b/docker/zshing/Dockerfile
@@ -0,0 +1,7 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/zshing/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
diff --git a/docker/zshing/install.zsh b/docker/zshing/install.zsh
new file mode 100644
index 00000000..8f926992
--- /dev/null
+++ b/docker/zshing/install.zsh
@@ -0,0 +1,16 @@
+#!zsh
+
+# install zshing https://github.com/zakariaGatter/zshing
+git clone https://github.com/zakariaGatter/zshing.git ~/.zshing/zshing
+
+# Link P9K in zshing directory
+ln -nsf ~/p9k ~/.zshing/powerlevel9k
+
+{
+ echo
+ echo 'ZSHING_PLUGINS=(
+ "bhilburn/powerlevel9k"
+ )'
+ echo
+ echo "source ~/.zshing/zshing/zshing.zsh"
+} >> ~/.zshrc
diff --git a/functions/colors.zsh b/functions/colors.zsh
index 9309a225..6b612256 100755
--- a/functions/colors.zsh
+++ b/functions/colors.zsh
@@ -79,6 +79,10 @@ function getColorCode() {
else
echo -n "$1"
fi
+ # Check if value is none with any case.
+ elif [[ "${(L)1}" == "none" ]]
+ then
+ echo -n 'none'
else
typeset -A codes
# https://jonasjacek.github.io/colors/
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 3e425c48..f253bfb9 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -409,12 +409,13 @@ prompt_battery() {
'charged' 'green'
'disconnected' "$DEFAULT_COLOR_INVERTED"
)
+ local ROOT_PREFIX="${4}"
# Set default values if the user did not configure them
set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10
- if [[ $OS =~ OSX && -f /usr/bin/pmset && -x /usr/bin/pmset ]]; then
+ if [[ $OS =~ OSX && -f "${ROOT_PREFIX}"/usr/bin/pmset && -x "${ROOT_PREFIX}"/usr/bin/pmset ]]; then
# obtain battery information from system
- local raw_data="$(pmset -g batt | awk 'FNR==2{print}')"
+ local raw_data="$(${ROOT_PREFIX}/usr/bin/pmset -g batt | awk 'FNR==2{print}')"
# return if there is no battery on system
[[ -z $(echo $raw_data | grep "InternalBattery") ]] && return
@@ -446,7 +447,7 @@ prompt_battery() {
fi
if [[ "$OS" == 'Linux' ]] || [[ "$OS" == 'Android' ]]; then
- local sysp="/sys/class/power_supply"
+ local sysp="${ROOT_PREFIX}/sys/class/power_supply"
# Reported BAT0 or BAT1 depending on kernel version
[[ -a $sysp/BAT0 ]] && local bat=$sysp/BAT0
@@ -468,8 +469,8 @@ prompt_battery() {
[[ $bat_percent =~ 100 ]] && current_state="charged"
[[ $bat_percent -lt 100 ]] && current_state="charging"
fi
- if [[ -f /usr/bin/acpi ]]; then
- local time_remaining=$(acpi | awk '{ print $5 }')
+ if [[ -f ${ROOT_PREFIX}/usr/bin/acpi ]]; then
+ local time_remaining=$(${ROOT_PREFIX}/usr/bin/acpi | awk '{ print $5 }')
if [[ $time_remaining =~ rate ]]; then
local tstring="..."
elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then
@@ -623,12 +624,12 @@ prompt_context() {
if [[ $(print -P "%#") == '#' ]]; then
current_state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
- if sudo -n true 2>/dev/null; then
+ if [[ -n "$SUDO_COMMAND" ]]; then
current_state="REMOTE_SUDO"
else
current_state="REMOTE"
fi
- elif sudo -n true 2>/dev/null; then
+ elif [[ -n "$SUDO_COMMAND" ]]; then
current_state="SUDO"
fi
@@ -702,11 +703,13 @@ prompt_host() {
# The 'custom` prompt provides a way for users to invoke commands and display
# the output in a segment.
prompt_custom() {
- local command=POWERLEVEL9K_CUSTOM_$3:u
+ local segment_name="${3:u}"
+ # Get content of custom segment
+ local command="POWERLEVEL9K_CUSTOM_${segment_name}"
local segment_content="$(eval ${(P)command})"
if [[ -n $segment_content ]]; then
- "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$segment_content"
+ "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$segment_content" "CUSTOM_${segment_name}_ICON"
fi
}
@@ -745,6 +748,31 @@ prompt_command_execution_time() {
}
################################################################
+# Determine the unique path - this is needed for the
+# truncate_to_unique strategy.
+#
+function getUniqueFolder() {
+ local trunc_path directory test_dir test_dir_length
+ local -a matching
+ local -a paths
+ local cur_path='/'
+ paths=(${(s:/:)1})
+ for directory in ${paths[@]}; do
+ test_dir=''
+ for (( i=0; i < ${#directory}; i++ )); do
+ test_dir+="${directory:$i:1}"
+ matching=("$cur_path"/"$test_dir"*/)
+ if [[ ${#matching[@]} -eq 1 ]]; then
+ break
+ fi
+ done
+ trunc_path+="$test_dir/"
+ cur_path+="$directory/"
+ done
+ echo "${trunc_path: : -1}"
+}
+
+################################################################
# Dir: current working directory
# Parameters:
# * $1 Alignment: string - left|right
@@ -811,23 +839,10 @@ prompt_dir() {
# for each parent path component find the shortest unique beginning
# characters sequence. Source: https://stackoverflow.com/a/45336078
if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths
- local matching
- local cur_path='/'
- [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path=''
- for directory in ${paths[@]}; do
- test_dir=''
- for (( i=0; i<${#directory}; i++ )); do
- test_dir+="${directory:$i:1}"
- matching=("$cur_path"/"$test_dir"*/)
- if [[ ${#matching[@]} -eq 1 ]]; then
- break
- fi
- done
- trunc_path+="$test_dir/"
- cur_path+="$directory/"
- done
- [[ $current_path == "~"* ]] && trunc_path="~/$trunc_path"
- current_path="${trunc_path: : -1}"
+ # cheating here to retain ~ as home folder
+ local home_path="$(getUniqueFolder $HOME)"
+ trunc_path="$(getUniqueFolder $PWD)"
+ [[ $current_path == "~"* ]] && current_path="~${trunc_path//${home_path}/}" || current_path="/${trunc_path}"
fi
;;
truncate_with_folder_marker)
@@ -1043,18 +1058,14 @@ prompt_history() {
################################################################
# Detection for virtualization (systemd based systems only)
prompt_detect_virt() {
- if ! command -v systemd-detect-virt > /dev/null; then
- return
- fi
- local virt=$(systemd-detect-virt)
+ local virt=$(systemd-detect-virt 2> /dev/null)
if [[ "$virt" == "none" ]]; then
if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then
virt="chroot"
- "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
- else
- ;
fi
- else
+ fi
+
+ if [[ -n "${virt}" ]]; then
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
fi
}
@@ -1089,18 +1100,20 @@ prompt_ip() {
else
if defined POWERLEVEL9K_IP_INTERFACE; then
# Get the IP address of the specified interface.
- ip=$(ip -4 a show "$POWERLEVEL9K_IP_INTERFACE" | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*")
+ ip=$(ip -4 a show "$POWERLEVEL9K_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 "[a-z0-9]*")
- callback='ip -4 a show $item | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*"'
+ 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 "inet\s*[0-9.]*" | grep -o -E "[0-9.]+"'
ip=$(getRelevantItem "$interfaces" "$callback")
fi
fi
- "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON'
+ if [[ -n "$ip" ]]; then
+ "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON'
+ fi
}
################################################################
@@ -1118,11 +1131,10 @@ prompt_vpn_ip() {
################################################################
# Segment to display laravel version
prompt_laravel_version() {
- local laravel_version="$(php artisan --version 2>/dev/null)"
- if [[ -n "${laravel_version}" ]]; then
- # Remove unrelevant infos
- laravel_version="${laravel_version//Laravel Framework version /}"
-
+ local laravel_version="$(php artisan --version 2> /dev/null)"
+ if [[ -n "${laravel_version}" && "${laravel_version}" =~ "Laravel Framework" ]]; then
+ # Strip out everything but the version
+ laravel_version="${laravel_version//Laravel Framework /}"
"$1_prompt_segment" "$0" "$2" "maroon" "white" "${laravel_version}" 'LARAVEL_ICON'
fi
}
@@ -1131,6 +1143,7 @@ prompt_laravel_version() {
# Segment to display load
set_default POWERLEVEL9K_LOAD_WHICH 5
prompt_load() {
+ local ROOT_PREFIX="${4}"
# The load segment can have three different states
local current_state="unknown"
local load_select=2
@@ -1166,7 +1179,7 @@ prompt_load() {
fi
;;
*)
- load_avg=$(cut -d" " -f${load_select} /proc/loadavg)
+ load_avg=$(cut -d" " -f${load_select} ${ROOT_PREFIX}/proc/loadavg)
cores=$(nproc)
esac
@@ -1239,6 +1252,7 @@ prompt_php_version() {
################################################################
# Segment to display free RAM and used Swap
prompt_ram() {
+ local ROOT_PREFIX="${4}"
local base=''
local ramfree=0
if [[ "$OS" == "OSX" ]]; then
@@ -1250,9 +1264,9 @@ prompt_ram() {
ramfree=$(( ramfree * 4096 ))
else
if [[ "$OS" == "BSD" ]]; then
- ramfree=$(grep 'avail memory' /var/run/dmesg.boot | awk '{print $4}')
+ ramfree=$(grep 'avail memory' ${ROOT_PREFIX}/var/run/dmesg.boot | awk '{print $4}')
else
- ramfree=$(grep -o -E "MemAvailable:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
+ ramfree=$(grep -o -E "MemAvailable:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
base='K'
fi
fi
@@ -1417,6 +1431,7 @@ prompt_status() {
################################################################
# Segment to display Swap information
prompt_swap() {
+ local ROOT_PREFIX="${4}"
local swap_used=0
local base=''
@@ -1431,8 +1446,8 @@ prompt_swap() {
base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$")
else
- swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
- swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
+ swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
+ swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
swap_used=$(( swap_total - swap_free ))
base='K'
fi
@@ -1605,7 +1620,7 @@ set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL"
prompt_vi_mode() {
case ${KEYMAP} in
vicmd)
- "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING"
+ "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "white" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING"
;;
main|viins|*)
if [[ -z $POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then return; fi
@@ -1634,7 +1649,11 @@ prompt_pyenv() {
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$PYENV_VERSION" 'PYTHON_ICON'
elif [ $commands[pyenv] ]; then
local pyenv_version_name="$(pyenv version-name)"
- local pyenv_global="$(pyenv version-file-read $(pyenv root)/version)"
+ local pyenv_global="system"
+ local pyenv_root="$(pyenv root)"
+ if [[ -f "${pyenv_root}/version" ]]; then
+ pyenv_global="$(pyenv version-file-read ${pyenv_root}/version)"
+ fi
if [[ "${pyenv_version_name}" != "${pyenv_global}" || "${POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$pyenv_version_name" 'PYTHON_ICON'
fi
diff --git a/shunit2 b/shunit2
-Subproject 60dd60bcd1573befe38465010263ab242e55811
+Subproject 07bb3292048a4982aad7247bdd7890f2bf532ec
diff --git a/test-in-docker b/test-in-docker
index 3c7255ec..0ed1254f 100755
--- a/test-in-docker
+++ b/test-in-docker
@@ -2,10 +2,12 @@
set -eu
-# The default ZSH to use.
-default_version='4.3.11'
+# The default ZSH to use; it can just be the first few characters.
+# This should be the oldest version we support.
+default_version='4.'
setopt extended_glob glob_subst numeric_glob_sort
+setopt warn_create_global warn_nested_var 2> /dev/null
cd "${${(%):-%x}:A:h}"
# TODO: Crazy Logic to munge TERM to something supported in Ubuntu 14.04
@@ -15,13 +17,18 @@ term=screen-256color
# ...see Modifiers in zshexpn(1) for details.
# List of ZSH versions
-typeset -a versions
+typeset -aU versions
versions=( docker/base-*/Dockerfile(N.on:h:t:s/base-//) )
+typeset -r versions
# List of frameworks
-typeset -a frameworks
+typeset -aU frameworks
frameworks=( docker/*/Dockerfile(N.on:h:t) )
-frameworks=${(@)frameworks:#base-*}
+for i in {$#frameworks..1}; do
+ # Remove all base entries
+ [[ "${frameworks[$i]}" == base-* ]] && frameworks[$i]=()
+done
+typeset -r frameworks
# Known Issues
typeset -A known_issues
@@ -30,6 +37,7 @@ known_issues["4.3.11-zim"]="BROKEN: Zim wants ZSH 5.2 or newer."
known_issues["5.0.3-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer."
known_issues["5.1.1-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer."
known_issues["4.3.11-zulu"]="Zulu doesn't work; it needs a newer version of git."
+typeset -r known_issues
err()
{
@@ -65,6 +73,14 @@ check_for_known_issues() {
fi
}
+cmd() {
+ if (( dry_run )); then
+ echo "${(@q)*}" 1>&2
+ else
+ "${(@)*}"
+ fi
+}
+
build_and_run() {
local version="$1"
local framework="$2"
@@ -75,14 +91,14 @@ build_and_run() {
print -P "%F{green}Preparing containers...%f"
echo -n "p9k:base-${version}: "
- docker build \
+ cmd docker build \
--quiet \
--tag "p9k:base-${version}" \
--file "docker/base-${version}/Dockerfile" \
.
echo -n "p9k:${version}-${framework}: "
- docker build \
+ cmd docker build \
--quiet \
--build-arg="base=base-${version}" \
--tag "p9k:${version}-${framework}" \
@@ -90,7 +106,7 @@ build_and_run() {
.
print -P "%F{green}Starting ${name} container...%f"
- exec docker run \
+ cmd docker run \
--rm \
--interactive \
--tty \
@@ -105,9 +121,10 @@ show_help() {
echo
echo "Loads up a docker image with powershell9k configured in <framework>"
echo
- echo " --frameworks Lists all available frameworks, newline separated."
- echo " --versions Lists all available ZSH versions, newline separated."
- echo " --zsh VER Uses ZSH with version VER."
+ echo " -f --frameworks Lists all available frameworks, newline separated."
+ echo " -v --versions Lists all available ZSH versions, newline separated."
+ echo " -z --zsh VER Uses ZSH with version VER."
+ echo " -n --dry-run Just prints the docker commands that would be run."
echo " --help You're soaking in it."
echo
echo "ZSH versions:"
@@ -128,8 +145,9 @@ if (( $# == 0 )); then
fi
# Parse flags and such.
-use_version=$default_version
-use_framework=
+asked_for_version=$default_version
+asked_for_framework=
+dry_run=0
while (( $# > 0 )); do
case "$1" in
-f | --frameworks )
@@ -142,13 +160,9 @@ while (( $# > 0 )); do
;;
-z | --zsh )
shift
- local v="$(resolve_version "$1")"
- if [[ -n "$v" ]]; then
- use_version=$v
- else
- err "No such ZSH version '${1}'"
- fi
+ asked_for_version=$1
;;
+ -n | --dry-run ) dry_run=1 ;;
-h | --help )
show_help
exit
@@ -159,21 +173,28 @@ while (( $# > 0 )); do
exit 1
;;
* )
- if [[ -z "$use_framework" ]]; then
- local f="$(resolve_framework "$1")"
- if [[ -n "$f" ]]; then
- use_framework=$f
- else
- err "No such framework '${1}'"
- fi
+ if [[ -z "$asked_for_framework" ]]; then
+ asked_for_framework=$1
else
- err "You can only specify one framework at a time; you already specified '${use_framework}'"
+ err "You can only specify one framework at a time; you already specified '${asked_for_framework}'"
fi
;;
esac
shift
done
+typeset -r asked_for_version asked_for_framework
+
+typeset -r use_version="$(resolve_version "${asked_for_version}")"
+if [[ -z "$use_version" ]]; then
+ err "No such ZSH version '${asked_for_version}'"
+fi
+
+typeset -r use_framework="$(resolve_framework "${asked_for_framework}")"
+if [[ -z "$use_framework" ]]; then
+ err "No such framework '${asked_for_framework}'"
+fi
+
build_and_run "$use_version" "$use_framework"
# EOF
diff --git a/test/core/color_overriding.spec b/test/core/color_overriding.spec
new file mode 100755
index 00000000..48b30f00
--- /dev/null
+++ b/test/core/color_overriding.spec
@@ -0,0 +1,62 @@
+#!/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"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testDynamicColoringOfSegmentsWork() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date)
+ local POWERLEVEL9K_DATE_ICON="date-icon"
+ local POWERLEVEL9K_DATE_BACKGROUND='red'
+
+ assertEquals "%K{red} %F{black%}date-icon %f%F{black}%D{%d.%m.%y} %k%F{red}%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{white} %F{green%}date-icon %f%F{black}%D{%d.%m.%y} %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date)
+ local POWERLEVEL9K_DATE_ICON="date-icon"
+ local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green'
+ local POWERLEVEL9K_DATE_FOREGROUND='red'
+ local POWERLEVEL9K_DATE_BACKGROUND='yellow'
+
+ assertEquals "%K{yellow} %F{green%}date-icon %f%F{red}%D{%d.%m.%y} %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingOfStatefulSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(host)
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ local POWERLEVEL9K_HOST_REMOTE_BACKGROUND='red'
+ local POWERLEVEL9K_HOST_REMOTE_FOREGROUND='green'
+ # Provoke state
+ local SSH_CLIENT="x"
+
+ assertEquals "%K{red} %F{green%}ssh-icon %f%F{green}%m %k%F{red}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingOfCustomSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_CUSTOM_WORLD_ICON='CW'
+ local POWERLEVEL9K_CUSTOM_WORLD_VISUAL_IDENTIFIER_COLOR='green'
+ local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND='red'
+ local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND='red'
+
+ assertEquals "%K{red} %F{green%}CW %f%F{red}world %k%F{red}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/core/joining_segments.spec b/test/core/joining_segments.spec
new file mode 100755
index 00000000..f224007e
--- /dev/null
+++ b/test/core/joining_segments.spec
@@ -0,0 +1,187 @@
+#!/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"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testLeftNormalSegmentsShouldNotBeJoined() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4_joined custom_world5 custom_world6)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+ local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"
+
+ assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world2 %K{white}%F{black} %F{black}world4 %K{white}%F{black} %F{black}world6 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testLeftJoinedSegments() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+
+ assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testLeftTransitiveJoinedSegments() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"
+
+ assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %K{white}%F{black}%F{black}world3 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testLeftTransitiveJoiningWithConditionalJoinedSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+
+ assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %K{white}%F{black}%F{black}world4 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testLeftPromotingSegmentWithConditionalPredecessor() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"
+
+ assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world3 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testLeftPromotingSegmentWithJoinedConditionalPredecessor() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+
+ assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world4 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testLeftPromotingSegmentWithDeepJoinedConditionalPredecessor() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+ local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"
+
+ assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world4 %K{white}%F{black}%F{black}world6 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testLeftJoiningBuiltinSegmentWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version php_version_joined)
+ alias php="echo PHP 1.2.3"
+
+ assertEquals "%K{013} %F{255}PHP 1.2.3 %K{013}%F{255}%F{255}PHP 1.2.3 %k%F{fuchsia}%f " "$(build_left_prompt)"
+
+ unalias php
+}
+
+function testRightNormalSegmentsShouldNotBeJoined() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4 custom_world5_joined custom_world6)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+ local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world2 %f%F{black}%f%K{white}%F{black} world4 %f%F{black}%f%K{white}%F{black} world6%E" "$(build_right_prompt)"
+}
+
+function testRightJoinedSegments() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2%E" "$(build_right_prompt)"
+}
+
+function testRightTransitiveJoinedSegments() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2 %f%K{white}%F{black}world3%E" "$(build_right_prompt)"
+}
+
+function testRightTransitiveJoiningWithConditionalJoinedSegment() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2 %f%K{white}%F{black}world4%E" "$(build_right_prompt)"
+}
+
+function testRightPromotingSegmentWithConditionalPredecessor() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world3%E" "$(build_right_prompt)"
+}
+
+function testRightPromotingSegmentWithJoinedConditionalPredecessor() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world4%E" "$(build_right_prompt)"
+}
+
+function testRightPromotingSegmentWithDeepJoinedConditionalPredecessor() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined)
+ local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
+ local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
+ local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
+ local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world4 %f%K{white}%F{black}world6%E" "$(build_right_prompt)"
+}
+
+function testRightJoiningBuiltinSegmentWorks() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(php_version php_version_joined)
+ alias php="echo PHP 1.2.3"
+
+ assertEquals "%F{013}%f%K{013}%F{255} PHP 1.2.3 %f%K{013}%F{255}PHP 1.2.3%E" "$(build_right_prompt)"
+
+ unalias php
+}
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/core/prompt.spec b/test/core/prompt.spec
new file mode 100755
index 00000000..dd5bba58
--- /dev/null
+++ b/test/core/prompt.spec
@@ -0,0 +1,104 @@
+#!/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"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testSegmentOnRightSide() {
+ # Reset RPROMPT, so a running P9K does not interfere with the test
+ local RPROMPT=
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+ local POWERLEVEL9K_CUSTOM_WORLD2='echo world2'
+
+ powerlevel9k_prepare_prompts
+
+ local reset_attributes=$'\e[00m'
+ assertEquals "%f%b%k%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world2%E%{${reset_attributes}%}" "${(e)RPROMPT}"
+}
+
+function testDisablingRightPrompt() {
+ # Reset RPROMPT, so a running P9K does not interfere with the test
+ local RPROMPT=
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+ local POWERLEVEL9K_CUSTOM_WORLD2='echo world2'
+ local POWERLEVEL9K_DISABLE_RPROMPT=true
+
+ powerlevel9k_prepare_prompts
+
+ assertEquals "" "${(e)RPROMPT}"
+}
+
+function testLeftMultilinePrompt() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+ local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
+
+ powerlevel9k_prepare_prompts
+
+ local nl=$'\n'
+ assertEquals "╭─%f%b%k%K{white} %F{black}world1 %k%F{white}%f ${nl}╰─ " "${(e)PROMPT}"
+}
+
+function testRightPromptOnSameLine() {
+ # Reset RPROMPT, so a running P9K does not interfere with the test
+ local RPROMPT=
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+
+ local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
+ local POWERLEVEL9K_RPROMPT_ON_NEWLINE=false # We want the RPROMPT on the same line as our left prompt
+
+ # Skip test, as this cannot be tested properly.
+ # The "go one line up" instruction does not get
+ # printed as real characters in RPROMPT.
+ # On command line the assert statement produces
+ # a visually identical output as we expect, but
+ # it fails anyway. :(
+ startSkipping
+
+ powerlevel9k_prepare_prompts
+ assertEquals "%{\e[1A%}%F{white}%f%K{white}%F{black} world1 %f%{\e[1B%}" "${(e)RPROMPT}"
+}
+
+function testPrefixingFirstLineOnLeftPrompt() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+
+ local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
+ local POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX='XXX'
+
+ powerlevel9k_prepare_prompts
+
+ local nl=$'\n'
+ assertEquals "XXX%f%b%k%K{white} %F{black}world1 %k%F{white}%f ${nl}╰─ " "${(e)PROMPT}"
+}
+
+function testPrefixingSecondLineOnLeftPrompt() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+
+ local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
+ local POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX='XXX'
+
+ powerlevel9k_prepare_prompts
+
+ local nl=$'\n'
+ assertEquals "╭─%f%b%k%K{white} %F{black}world1 %k%F{white}%f ${nl}XXX" "${(e)PROMPT}"
+}
+
+source shunit2/shunit2
diff --git a/test/core/visual_identifier.spec b/test/core/visual_identifier.spec
new file mode 100755
index 00000000..c6b1125b
--- /dev/null
+++ b/test/core/visual_identifier.spec
@@ -0,0 +1,50 @@
+#!/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"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ source functions/*
+}
+
+function testOverwritingIconsWork() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+ local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here'
+
+ assertEquals "%K{white} %F{black%}icon-here %f%F{black}world1 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+ local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here'
+
+ assertEquals "%K{white} %F{black%}icon-here %f%F{black}world1 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() {
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+ local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here'
+
+ assertEquals "%F{white}%f%K{white}%F{black} world1%F{black%} icon-here%f%E" "$(build_right_prompt)"
+}
+
+function testVisualIdentifierPrintsNothingIfNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
+ local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
+
+ assertEquals "%K{white} %F{black}world1 %k%F{white}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/functions/colors.spec b/test/functions/colors.spec
index 61a40087..bb06b719 100755
--- a/test/functions/colors.spec
+++ b/test/functions/colors.spec
@@ -39,4 +39,4 @@ function testIsSameColorDoesNotYieldNotEqualColorsTruthy() {
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/functions/icons.spec b/test/functions/icons.spec
index c8d88644..ec0cb1fa 100755
--- a/test/functions/icons.spec
+++ b/test/functions/icons.spec
@@ -10,21 +10,15 @@ function setUp() {
_OLD_LC_CTYPE="${LC_CTYPE}"
# Reset actual LC_CTYPE
unset LC_CTYPE
-
- # Store old P9K mode
- _OLD_P9K_MODE="${POWERLEVEL9K_MODE}"
}
function tearDown() {
# Restore LC_CTYPE
LC_CTYPE="${_OLD_LC_CTYPE}"
-
- # Restore old P9K mode
- POWERLEVEL9K_MODE="${_OLD_P9K_MODE}"
}
function testLcCtypeIsSetCorrectlyInDefaultMode() {
- POWERLEVEL9K_MODE="default"
+ local POWERLEVEL9K_MODE="default"
# Load Powerlevel9k
source functions/icons.zsh
@@ -32,7 +26,7 @@ function testLcCtypeIsSetCorrectlyInDefaultMode() {
}
function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() {
- POWERLEVEL9K_MODE="awesome-patched"
+ local POWERLEVEL9K_MODE="awesome-patched"
# Load Powerlevel9k
source functions/icons.zsh
@@ -40,7 +34,7 @@ function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() {
}
function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() {
- POWERLEVEL9K_MODE="awesome-fontconfig"
+ local POWERLEVEL9K_MODE="awesome-fontconfig"
# Load Powerlevel9k
source functions/icons.zsh
@@ -48,7 +42,7 @@ function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() {
}
function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() {
- POWERLEVEL9K_MODE="nerdfont-fontconfig"
+ local POWERLEVEL9K_MODE="nerdfont-fontconfig"
# Load Powerlevel9k
source functions/icons.zsh
@@ -56,7 +50,7 @@ function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() {
}
function testLcCtypeIsSetCorrectlyInFlatMode() {
- POWERLEVEL9K_MODE="flat"
+ local POWERLEVEL9K_MODE="flat"
# Load Powerlevel9k
source functions/icons.zsh
@@ -64,7 +58,7 @@ function testLcCtypeIsSetCorrectlyInFlatMode() {
}
function testLcCtypeIsSetCorrectlyInCompatibleMode() {
- POWERLEVEL9K_MODE="compatible"
+ local POWERLEVEL9K_MODE="compatible"
# Load Powerlevel9k
source functions/icons.zsh
@@ -76,7 +70,7 @@ function testLcCtypeIsSetCorrectlyInCompatibleMode() {
function testAllIconsAreDefinedLikeInDefaultMode() {
# Always compare against this mode
local _P9K_TEST_MODE="default"
- POWERLEVEL9K_MODE="${_P9K_TEST_MODE}"
+ local POWERLEVEL9K_MODE="${_P9K_TEST_MODE}"
source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key
@@ -121,6 +115,15 @@ function testAllIconsAreDefinedLikeInDefaultMode() {
assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
done
+ # Switch to "nerdfont-complete" mode
+ POWERLEVEL9K_MODE="nerdfont-complete"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
# Switch to "flat" mode
POWERLEVEL9K_MODE="flat"
source functions/icons.zsh
@@ -148,7 +151,7 @@ function testAllIconsAreDefinedLikeInDefaultMode() {
function testAllIconsAreDefinedLikeInAwesomePatchedMode() {
# Always compare against this mode
local _P9K_TEST_MODE="awesome-patched"
- POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
+ local POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key
@@ -193,6 +196,15 @@ function testAllIconsAreDefinedLikeInAwesomePatchedMode() {
assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
done
+ # Switch to "nerdfont-complete" mode
+ POWERLEVEL9K_MODE="nerdfont-complete"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
# Switch to "flat" mode
POWERLEVEL9K_MODE="flat"
source functions/icons.zsh
@@ -220,7 +232,7 @@ function testAllIconsAreDefinedLikeInAwesomePatchedMode() {
function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() {
# Always compare against this mode
local _P9K_TEST_MODE="awesome-fontconfig"
- POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
+ local POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key
@@ -265,6 +277,15 @@ function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() {
assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
done
+ # Switch to "nerdfont-complete" mode
+ POWERLEVEL9K_MODE="nerdfont-complete"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
# Switch to "flat" mode
POWERLEVEL9K_MODE="flat"
source functions/icons.zsh
@@ -292,7 +313,7 @@ function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() {
function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() {
# Always compare against this mode
local _P9K_TEST_MODE="nerdfont-fontconfig"
- POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
+ local POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key
@@ -337,6 +358,96 @@ function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() {
assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
done
+ # Switch to "nerdfont-complete" mode
+ POWERLEVEL9K_MODE="nerdfont-complete"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
+ # Switch to "flat" mode
+ POWERLEVEL9K_MODE="flat"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
+ # Switch to "compatible" mode
+ POWERLEVEL9K_MODE="compatible"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
+ unset current_icons
+ unset _ICONS_UNDER_TEST
+}
+
+# Go through all icons defined in nerdfont-complete mode, and
+# check if all of them are defined in the other modes.
+function testAllIconsAreDefinedLikeInNerdfontCompleteMode() {
+ # Always compare against this mode
+ local _P9K_TEST_MODE="nerdfont-complete"
+ local POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
+ source functions/icons.zsh
+ # _ICONS_UNDER_TEST is an array of just the keys of $icons.
+ # We later check via (r) "subscript" flag that our key
+ # is in the values of our flat array.
+ typeset -ah _ICONS_UNDER_TEST
+ _ICONS_UNDER_TEST=(${(k)icons[@]})
+
+ # Switch to "default" mode
+ POWERLEVEL9K_MODE="default"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ # Iterate over all keys found in the _ICONS_UNDER_TEST
+ # array and compare it with the icons array of the
+ # current POWERLEVEL9K_MODE.
+ # Use parameter expansion, to directly check if the
+ # key exists in the flat current array of keys. That
+ # is quite complicated, but there seems no easy way
+ # to check the mere existance of a key in an array.
+ # The usual way would always return the value, so that
+ # would do the wrong thing as we have some (on purpose)
+ # empty values.
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
+ # Switch to "awesome-patched" mode
+ POWERLEVEL9K_MODE="awesome-patched"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
+ # Switch to "awesome-fontconfig" mode
+ POWERLEVEL9K_MODE="awesome-fontconfig"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
+ # Switch to "nerdfont-fontconfig" mode
+ POWERLEVEL9K_MODE="nerdfont-fontconfig"
+ source functions/icons.zsh
+ typeset -ah current_icons
+ current_icons=(${(k)icons[@]})
+ for key in ${_ICONS_UNDER_TEST}; do
+ assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))"
+ done
+
# Switch to "flat" mode
POWERLEVEL9K_MODE="flat"
source functions/icons.zsh
@@ -359,4 +470,4 @@ function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() {
unset _ICONS_UNDER_TEST
}
-source shunit2/source/2.1/src/shunit2 \ No newline at end of file
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/functions/utilities.spec b/test/functions/utilities.spec
index a9bd67e3..b727c1f6 100755
--- a/test/functions/utilities.spec
+++ b/test/functions/utilities.spec
@@ -106,4 +106,4 @@ function testSegmentShouldNotBeJoinedIfPredecessingSegmentIsNotJoinedButConditio
unset segments
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec
index 0ddf36c1..8de0f1e2 100755
--- a/test/powerlevel9k.spec
+++ b/test/powerlevel9k.spec
@@ -17,68 +17,66 @@ function setUp() {
}
function testJoinedSegments() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_joined)
cd /tmp
assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
cd -
}
function testTransitiveJoinedSegments() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir root_indicator_joined dir_joined)
cd /tmp
assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
cd -
}
function testJoiningWithConditionalSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir background_jobs dir_joined)
cd /tmp
assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
cd -
}
function testDynamicColoringOfSegmentsWork() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red'
+ local POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red'
cd /tmp
assertEquals "%K{red} %F{black}/tmp %k%F{red}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_DIR_DEFAULT_BACKGROUND
cd -
}
function testDynamicColoringOfVisualIdentifiersWork() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green'
- POWERLEVEL9K_FOLDER_ICON="icon-here"
+ local POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green'
+ local POWERLEVEL9K_FOLDER_ICON="icon-here"
cd /tmp
assertEquals "%K{blue} %F{green%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR
- unset POWERLEVEL9K_FOLDER_ICON
cd -
}
function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green'
- POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='red'
- POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='yellow'
- POWERLEVEL9K_FOLDER_ICON="icon-here"
+ local POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green'
+ local POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='red'
+ local POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='yellow'
+ local POWERLEVEL9K_FOLDER_ICON="icon-here"
# Re-Source the icons, as the POWERLEVEL9K_MODE is directly
# evaluated there.
@@ -88,17 +86,13 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() {
assertEquals "%K{yellow} %F{green%}icon-here %f%F{red}/tmp %k%F{yellow}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR
- unset POWERLEVEL9K_DIR_DEFAULT_FOREGROUND
- unset POWERLEVEL9K_DIR_DEFAULT_BACKGROUND
- unset POWERLEVEL9K_FOLDER_ICON
cd -
}
function testOverwritingIconsWork() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_FOLDER_ICON='icon-here'
+ local POWERLEVEL9K_FOLDER_ICON='icon-here'
#local testFolder=$(mktemp -d -p p9k)
# Move testFolder under home folder
#mv testFolder ~
@@ -108,29 +102,22 @@ function testOverwritingIconsWork() {
cd /tmp
assertEquals "%K{blue} %F{black%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_DIR_FOLDER_ICON
cd -
# rm -fr ~/$testFolder
}
function testNewlineOnRpromptCanBeDisabled() {
- POWERLEVEL9K_PROMPT_ON_NEWLINE=true
- POWERLEVEL9K_RPROMPT_ON_NEWLINE=false
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
- POWERLEVEL9K_CUSTOM_RWORLD='echo rworld'
+ local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
+ local POWERLEVEL9K_RPROMPT_ON_NEWLINE=false
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_CUSTOM_RWORLD='echo rworld'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_rworld)
powerlevel9k_prepare_prompts
assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})"
-
- unset POWERLEVEL9K_PROMPT_ON_NEWLINE
- unset POWERLEVEL9K_RPROMPT_ON_NEWLINE
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_CUSTOM_WORLD
- unset POWERLEVEL9K_CUSTOM_RWORLD
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/segments/anaconda.spec b/test/segments/anaconda.spec
new file mode 100755
index 00000000..c35f0494
--- /dev/null
+++ b/test/segments/anaconda.spec
@@ -0,0 +1,69 @@
+#!/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"
+}
+
+function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() {
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda custom_world)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Unset anacona variables
+ unset CONDA_ENV_PATH
+ unset CONDA_PREFIX
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda)
+ local POWERLEVEL9K_PYTHON_ICON="icon-here"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ CONDA_ENV_PATH=/tmp
+ unset CONDA_PREFIX
+
+ assertEquals "%K{blue} %F{black%}icon-here %f%F{black}(tmp) %k%F{blue}%f " "$(build_left_prompt)"
+}
+
+function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda)
+ local POWERLEVEL9K_PYTHON_ICON="icon-here"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ unset CONDA_ENV_PATH
+ local CONDA_PREFIX="test"
+
+ assertEquals "%K{blue} %F{black%}icon-here %f%F{black}(test) %k%F{blue}%f " "$(build_left_prompt)"
+}
+
+function testAnacondaSegmentWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda)
+ local POWERLEVEL9K_PYTHON_ICON="icon-here"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ local CONDA_ENV_PATH=/tmp
+ local CONDA_PREFIX="test"
+
+ assertEquals "%K{blue} %F{black%}icon-here %f%F{black}(tmptest) %k%F{blue}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/aws_eb_env.spec b/test/segments/aws_eb_env.spec
new file mode 100755
index 00000000..92240e42
--- /dev/null
+++ b/test/segments/aws_eb_env.spec
@@ -0,0 +1,61 @@
+#!/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"
+}
+
+function testAwsEbEnvSegmentPrintsNothingIfNoElasticBeanstalkEnvironmentIsSet() {
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env custom_world)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ mkdir -p /tmp/powerlevel9k-test/.elasticbeanstalk
+ echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml
+ cd /tmp/powerlevel9k-test
+
+ assertEquals "%K{black} %F{green%}🌱 %f%F{green}test %k%F{black}%f " "$(build_left_prompt)"
+
+ rm -fr /tmp/powerlevel9k-test
+ cd -
+}
+
+function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirectory() {
+ # Skip test, because currently we cannot detect
+ # if the configuration is in a parent directory
+ startSkipping # Skip test
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ mkdir -p /tmp/powerlevel9k-test/.elasticbeanstalk
+ mkdir -p /tmp/powerlevel9k-test/1/12/123/1234/12345
+ echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml
+ cd /tmp/powerlevel9k-test/1/12/123/1234/12345
+
+ assertEquals "%K{black} %F{green%}🌱 %f%F{green}test %k%F{black}%f " "$(build_left_prompt)"
+
+ rm -fr /tmp/powerlevel9k-test
+ cd -
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec
new file mode 100755
index 00000000..fa8d5ce6
--- /dev/null
+++ b/test/segments/background_jobs.spec
@@ -0,0 +1,78 @@
+#!/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"
+}
+
+function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() {
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs custom_world)
+ alias jobs="nojobs 2>/dev/null"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias jobs
+}
+
+function testBackgroundJobsSegmentWorksWithOneBackgroundJob() {
+ unset POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs)
+ jobs() {
+ echo '[1] + 30444 suspended nvim xx'
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{cyan%}⚙%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction jobs
+}
+
+function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() {
+ local POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=false
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs)
+ jobs() {
+ echo "[1] 31190 suspended nvim xx"
+ echo "[2] - 31194 suspended nvim xx2"
+ echo "[3] + 31206 suspended nvim xx3"
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{cyan%}⚙%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction jobs
+}
+
+function testBackgroundJobsSegmentWithVerboseMode() {
+ local POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=true
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs)
+ jobs() {
+ echo "[1] 31190 suspended nvim xx"
+ echo "[2] - 31194 suspended nvim xx2"
+ echo "[3] + 31206 suspended nvim xx3"
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{cyan%}⚙ %f%F{cyan}3 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction jobs
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/battery.spec b/test/segments/battery.spec
new file mode 100755
index 00000000..754de3cf
--- /dev/null
+++ b/test/segments/battery.spec
@@ -0,0 +1,177 @@
+#!/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"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+
+ # Prepare folder for pmset (OSX)
+ PMSET_PATH=$FOLDER/usr/bin
+ mkdir -p $PMSET_PATH
+ # Prepare folder for $BATTERY (Linux)
+ BATTERY_PATH=$FOLDER/sys/class/power_supply
+ mkdir -p $BATTERY_PATH
+ mkdir -p $BATTERY_PATH/BAT0
+ mkdir -p $BATTERY_PATH/BAT1
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}" &>/dev/null
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test &>/dev/null
+ unset PMSET_PATH
+ unset BATTERY_PATH
+ unset FOLDER
+ unset P9K_HOME
+}
+
+# Mock Battery
+# For mocking pmset on OSX this function takes one argument (the
+# content that pmset should echo).
+# For mocking the battery on Linux this function takes two
+# arguments: $1 is the capacity; $2 the battery status.
+function makeBatterySay() {
+ if [[ -z "${FOLDER}" ]]; then
+ echo "Fake root path is not correctly set!"
+ exit 1
+ fi
+ # OSX
+ echo "#!/bin/sh" > $PMSET_PATH/pmset
+ echo "echo \"$1\"" >> $PMSET_PATH/pmset
+ chmod +x $PMSET_PATH/pmset
+
+ # Linux
+ local capacity="$1"
+ echo "$capacity" > $BATTERY_PATH/BAT0/capacity
+ echo "$capacity" > $BATTERY_PATH/BAT1/capacity
+ local battery_status="$2"
+ echo "$battery_status" > $BATTERY_PATH/BAT0/status
+ echo "$battery_status" > $BATTERY_PATH/BAT1/status
+}
+
+function testBatterySegmentIfBatteryIsLowWhileDischargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 4%; discharging; 0:05 remaining present: true"
+
+ assertEquals "%K{black} %F{red%}🔋 %f%F{red}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 4%; charging; 0:05 remaining present: true"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 98%; discharging; 3:57 remaining present: true"
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsAlmostFullWhileChargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 98%; charging; 3:57 remaining present: true"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsFullOnOSX() {
+ local OS='OSX' # Fake OSX
+ makeBatterySay "Now drawing from 'AC Power'
+ -InternalBattery-0 (id=1234567) 99%; charged; 0:00 remaining present: true"
+
+ assertEquals "%K{black} %F{green%}🔋 %f%F{green}99%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsCalculatingOnOSX() {
+ local OS='OSX' # Fake OSX
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 99%; discharging; (no estimate) present: true"
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsLowWhileDischargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ makeBatterySay "4" "Discharging"
+
+ assertEquals "%K{black} %F{red%}🔋 %f%F{red}4%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsLowWhileChargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ makeBatterySay "4" "Charging"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}4%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsNormalWhileDischargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ makeBatterySay "10" "Discharging"
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}10%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsNormalWhileChargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ makeBatterySay "10" "Charging"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}10%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsFullOnLinux() {
+ local OS='Linux' # Fake Linux
+ makeBatterySay "100" "Full"
+
+ assertEquals "%K{black} %F{green%}🔋 %f%F{green}100%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() {
+ local OS='Linux' # Fake Linux
+ makeBatterySay "50" "Discharging"
+ echo "echo 'Batter 0: Discharging, 50%, 01:38:54 remaining'" > ${FOLDER}/usr/bin/acpi
+ chmod +x ${FOLDER}/usr/bin/acpi
+ # For running on Mac, we need to mock date :(
+ [[ -f /usr/local/bin/gdate ]] && alias date=gdate
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})"
+
+ unalias date &>/dev/null
+ # unaliasing date fails where it was never aliased (e.g. on Linux).
+ # This causes the whole test to fail, because the return code is
+ # non-zero.
+ return 0
+}
+
+function testBatterySegmentIfBatteryIsCalculatingWithAcpiEnabledOnLinux() {
+ local OS='Linux' # Fake Linux
+ makeBatterySay "50" "Discharging"
+ # Todo: Include real acpi output!
+ echo "echo 'Batter 0: Discharging, 50%, rate remaining'" > ${FOLDER}/usr/bin/acpi
+ chmod +x ${FOLDER}/usr/bin/acpi
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}50%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec
index d3588d83..b47d3fc9 100755
--- a/test/segments/command_execution_time.spec
+++ b/test/segments/command_execution_time.spec
@@ -7,90 +7,98 @@ SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
}
function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time)
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
- _P9K_COMMAND_DURATION=2
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
- assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_CUSTOM_WORLD
- unset _P9K_COMMAND_DURATION
+ # Override payload
+ local _P9K_COMMAND_DURATION=2
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
}
function testCommandExecutionTimeThresholdCouldBeChanged() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
- _P9K_COMMAND_DURATION=2.03
+ local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
- assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Override payload
+ local _P9K_COMMAND_DURATION=2.03
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset _P9K_COMMAND_DURATION
- unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD
+ assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)"
}
function testCommandExecutionTimeThresholdCouldBeSetToZero() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
- _P9K_COMMAND_DURATION=0.03
+ local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
+ local _P9K_COMMAND_DURATION=0.03
assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.03 %k%F{red}%f " "$(build_left_prompt)"
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset _P9K_COMMAND_DURATION
- unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD
}
function testCommandExecutionTimePrecisionCouldBeChanged() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4
- _P9K_COMMAND_DURATION=0.0001
+ local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
+ local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4
- assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Override payload
+ local _P9K_COMMAND_DURATION=0.0001
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset _P9K_COMMAND_DURATION
- unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION
- unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD
+ assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)"
}
function testCommandExecutionTimePrecisionCouldBeSetToZero() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
- POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
- _P9K_COMMAND_DURATION=23.5001
+ local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
- assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset _P9K_COMMAND_DURATION
- unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION
+ # Override payload
+ local _P9K_COMMAND_DURATION=23.5001
+
+ assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)"
}
function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
- _P9K_COMMAND_DURATION=180
- assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Override payload
+ local _P9K_COMMAND_DURATION=180
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset _P9K_COMMAND_DURATION
+ assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)"
}
function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
- _P9K_COMMAND_DURATION=7200
- assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset _P9K_COMMAND_DURATION
+ # Override payload
+ local _P9K_COMMAND_DURATION=7200
+
+ assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)"
}
-source shunit2/source/2.1/src/shunit2 \ No newline at end of file
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/context.spec b/test/segments/context.spec
new file mode 100755
index 00000000..49795668
--- /dev/null
+++ b/test/segments/context.spec
@@ -0,0 +1,113 @@
+#!/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 settings
+ OLD_DEFAULT_USER=$DEFAULT_USER
+ unset DEFAULT_USER
+}
+
+function tearDown() {
+ # Restore old variables
+ [[ -n "$OLD_DEFAULT_USER" ]] && DEFAULT_USER=$OLD_DEFAULT_USER
+
+ return 0
+}
+
+function testContextSegmentDoesNotGetRenderedWithDefaultUser() {
+ local DEFAULT_USER=$(whoami)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context custom_world)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() {
+ function sudo() {
+ return 0
+ }
+ local SSH_CLIENT="putty"
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction sudo
+}
+
+function testContextSegmentWithForeignUser() {
+ function sudo() {
+ return 0
+ }
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction sudo
+}
+
+# TODO: How to test root?
+function testContextSegmentWithRootUser() {
+ startSkipping # Skip test
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+}
+
+function testOverridingContextTemplate() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+ local POWERLEVEL9K_CONTEXT_TEMPLATE=xx
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow}xx %k%F{black}%f " "$(build_left_prompt)"
+}
+
+function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+ local POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true
+ local DEFAULT_USER=$(whoami)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+}
+
+function testContextSegmentIsShownIfForced() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+ local POWERLEVEL9K_ALWAYS_SHOW_USER=true
+ local DEFAULT_USER=$(whoami)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow}$(whoami) %k%F{black}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/custom.spec b/test/segments/custom.spec
new file mode 100755
index 00000000..3062d2e5
--- /dev/null
+++ b/test/segments/custom.spec
@@ -0,0 +1,86 @@
+#!/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"
+}
+
+function testCustomDirectOutputSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testCustomClosureSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ function p9k_hello_world() {
+ echo "world"
+ }
+ local POWERLEVEL9K_CUSTOM_WORLD='p9k_hello_world'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSettingBackgroundForCustomSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND="yellow"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black}world %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testSettingForegroundForCustomSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND="red"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{red}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSettingVisualIdentifierForCustomSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black%}hw %f%F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSettingVisualIdentifierForegroundColorForCustomSegment() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw"
+ local POWERLEVEL9K_CUSTOM_WORLD_VISUAL_IDENTIFIER_COLOR="red"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{red%}hw %f%F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/detect_virt.spec b/test/segments/detect_virt.spec
new file mode 100755
index 00000000..f5c54198
--- /dev/null
+++ b/test/segments/detect_virt.spec
@@ -0,0 +1,83 @@
+#!/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"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias systemd-detect-virt="novirt"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias systemd-detect-virt
+}
+
+function testDetectVirtSegmentIfSystemdReturnsPlainName() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt)
+ alias systemd-detect-virt="echo 'xxx'"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow}xxx %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias systemd-detect-virt
+}
+
+function testDetectVirtSegmentIfRootFsIsOnExpectedInode() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt)
+ # Well. This is a weak test, as it fixates the implementation,
+ # but it is necessary, as the implementation relys on the root
+ # directory having the inode number "2"..
+ alias systemd-detect-virt="echo 'none'"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # The original command in the implementation is "ls -di / | grep -o 2",
+ # which translates to: Show the inode number of "/" and test if it is "2".
+ alias ls="echo '2'"
+
+ assertEquals "%K{black} %F{yellow}none %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias ls
+ unalias systemd-detect-virt
+}
+
+function testDetectVirtSegmentIfRootFsIsNotOnExpectedInode() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt)
+ # Well. This is a weak test, as it fixates the implementation,
+ # but it is necessary, as the implementation relys on the root
+ # directory having the inode number "2"..
+ alias systemd-detect-virt="echo 'none'"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # The original command in the implementation is "ls -di / | grep -o 2",
+ # which translates to: Show the inode number of "/" and test if it is "2".
+ alias ls="echo '3'"
+
+ assertEquals "%K{black} %F{yellow}chroot %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias ls
+ unalias systemd-detect-virt
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/dir.spec b/test/segments/dir.spec
index b5fce59f..09fa8505 100755
--- a/test/segments/dir.spec
+++ b/test/segments/dir.spec
@@ -7,32 +7,46 @@ SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
- # Every test should at least use the dir segment
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ P9K_HOME="${PWD}"
}
function tearDown() {
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset P9K_HOME
}
function testDirPathAbsoluteWorks() {
- POWERLEVEL9K_DIR_PATH_ABSOLUTE=true
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_ABSOLUTE=true
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
cd ~
- assertEquals "%K{blue} %F{black}/home/travis %k%F{blue}%f " "$(build_left_prompt)"
+
+ # Unfortunately, we cannot fake Linux or OSX here, because
+ # of /home or /Users path.. That is why we change the test
+ # according to the OS of the host.
+ if [[ "${OS}" == 'Linux' ]]; then
+ assertEquals "%K{blue} %F{black}/home/${USER} %k%F{blue}%f " "$(build_left_prompt)"
+ elif [[ "${OS}" == 'OSX' ]]; then
+ assertEquals "%K{blue} %F{black}/Users/${USER} %k%F{blue}%f " "$(build_left_prompt)"
+ fi
cd -
- unset POWERLEVEL9K_DIR_PATH_ABSOLUTE
}
function testTruncateFoldersWorks() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders'
- FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@@ -40,18 +54,19 @@ function testTruncateFoldersWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
-
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncateFolderWithHomeDirWorks() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
- CURRENT_DIR=$(pwd)
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
+ local CURRENT_DIR=$(pwd)
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
cd ~
- FOLDER="powerlevel9k-test-${RANDOM}"
+ local FOLDER="powerlevel9k-test-${RANDOM}"
mkdir -p $FOLDER
cd $FOLDER
# Switch back to home folder as this causes the problem.
@@ -61,17 +76,18 @@ function testTruncateFolderWithHomeDirWorks() {
rmdir $FOLDER
cd ${CURRENT_DIR}
-
- unset CURRENT_DIR
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
}
function testTruncateMiddleWorks() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle'
- FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@@ -79,17 +95,18 @@ function testTruncateMiddleWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
-
- unset FOLDER
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncationFromRightWorks() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
- FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@@ -97,17 +114,18 @@ function testTruncationFromRightWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
-
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncateToLastWorks() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last"
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last"
- FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@@ -115,17 +133,18 @@ function testTruncateToLastWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
-
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncateToFirstAndLastWorks() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last"
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
- FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@@ -133,17 +152,18 @@ function testTruncateToFirstAndLastWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
-
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncateAbsoluteWorks() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute"
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
- FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@@ -151,18 +171,19 @@ function testTruncateAbsoluteWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
-
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncationFromRightWithEmptyDelimiter() {
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_DELIMITER=""
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_DELIMITER=""
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
- FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@@ -170,16 +191,15 @@ function testTruncationFromRightWithEmptyDelimiter() {
cd -
rm -fr /tmp/powerlevel9k-test
-
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_DELIMITER
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncateWithFolderMarkerWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
+ local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
local BASEFOLDER=/tmp/powerlevel9k-test
local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567
@@ -191,16 +211,16 @@ function testTruncateWithFolderMarkerWorks() {
cd -
rm -fr $BASEFOLDER
- unset BASEFOLDER
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_STRATEGY
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
}
function testTruncateWithFolderMarkerWithChangedFolderMarker() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
- POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx'
+ local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
+ local POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
local BASEFOLDER=/tmp/powerlevel9k-test
local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567
@@ -212,11 +232,6 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() {
cd -
rm -fr $BASEFOLDER
- unset BASEFOLDER
- unset FOLDER
- unset POWERLEVEL9K_SHORTEN_FOLDER_MARKER
- unset POWERLEVEL9K_SHORTEN_STRATEGY
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
}
function testTruncateWithPackageNameWorks() {
@@ -237,18 +252,19 @@ function testTruncateWithPackageNameWorks() {
# Go back to deeper folder
cd "${FOLDER}"
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)"
# Go back
cd $p9kFolder
rm -fr $BASEFOLDER
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_SHORTEN_STRATEGY
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
}
function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() {
@@ -276,18 +292,19 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() {
# Go to deep folder inside linked repo
cd linked-repo/asdfasdf/qwerqwer
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)"
# Go back
cd $p9kFolder
rm -fr $BASEFOLDER
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_SHORTEN_STRATEGY
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
}
function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() {
@@ -311,60 +328,77 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() {
cd linked-repo/.git/refs/heads
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)"
# Go back
cd $p9kFolder
rm -fr $BASEFOLDER
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_SHORTEN_STRATEGY
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
}
function testHomeFolderDetectionWorks() {
- POWERLEVEL9K_HOME_ICON='home-icon'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_HOME_ICON='home-icon'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
cd ~
assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_HOME_ICON
}
function testHomeSubfolderDetectionWorks() {
- POWERLEVEL9K_HOME_SUB_ICON='sub-icon'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_HOME_SUB_ICON='sub-icon'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
- FOLDER=~/powerlevel9k-test
+ local FOLDER=~/powerlevel9k-test
mkdir $FOLDER
cd $FOLDER
assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
cd -
rm -fr $FOLDER
- unset FOLDER
- unset POWERLEVEL9K_HOME_SUB_ICON
}
function testOtherFolderDetectionWorks() {
- POWERLEVEL9K_FOLDER_ICON='folder-icon'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_FOLDER_ICON='folder-icon'
- FOLDER=/tmp/powerlevel9k-test
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ local FOLDER=/tmp/powerlevel9k-test
mkdir $FOLDER
cd $FOLDER
assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
cd -
rm -fr $FOLDER
- unset FOLDER
- unset POWERLEVEL9K_FOLDER_ICON
}
function testChangingDirPathSeparator() {
- POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
local FOLDER="/tmp/powerlevel9k-test/1/2"
mkdir -p $FOLDER
cd $FOLDER
@@ -372,52 +406,77 @@ function testChangingDirPathSeparator() {
assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset FOLDER
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR
}
function testHomeFolderAbbreviation() {
- local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local dir=$PWD
cd ~/
# default
- POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~'
+ local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)"
# substituted
- POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq'
+ local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
assertEquals "%K{blue} %F{black}qQq %k%F{blue}%f " "$(build_left_prompt)"
cd /tmp
# default
- POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~'
+ local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
# substituted
- POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq'
+ local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
cd "$dir"
}
function testOmittingFirstCharacterWorks() {
- POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
- POWERLEVEL9K_FOLDER_ICON='folder-icon'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
+ local POWERLEVEL9K_FOLDER_ICON='folder-icon'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
cd /tmp
assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_FOLDER_ICON
- unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
}
function testOmittingFirstCharacterWorksWithChangingPathSeparator() {
- POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
- POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
- POWERLEVEL9K_FOLDER_ICON='folder-icon'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
+ local POWERLEVEL9K_FOLDER_ICON='folder-icon'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@@ -425,9 +484,6 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() {
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_FOLDER_ICON
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR
- unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
}
# This test makes it obvious that combining a truncation strategy
@@ -438,10 +494,16 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() {
# But it does more sense in combination with other truncation
# strategies.
function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTruncation() {
- POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
- POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@@ -449,17 +511,19 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR
- unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTruncation() {
- POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
- POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@@ -467,17 +531,19 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR
- unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncation() {
- POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
- POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@@ -485,17 +551,19 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR
- unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncateToUniqueWorks() {
- POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
- POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
- POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
- POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
+ local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p /tmp/powerlevel9k-test/adam/devl
mkdir -p /tmp/powerlevel9k-test/alice/devl
mkdir -p /tmp/powerlevel9k-test/alice/docs
@@ -506,24 +574,31 @@ function testTruncateToUniqueWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR
- unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
- unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
- unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testBoldHomeDirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
cd ~
assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
}
function testBoldHomeSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test
@@ -531,31 +606,46 @@ function testBoldHomeSubdirWorks() {
cd -
rm -fr ~/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
}
function testBoldRootDirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
cd /
assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
}
function testBoldRootSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
cd /tmp
assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
}
function testBoldRootSubSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test
@@ -563,21 +653,31 @@ function testBoldRootSubSubdirWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
}
function testHighlightHomeWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
cd ~
assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
}
function testHighlightHomeSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test
@@ -585,31 +685,46 @@ function testHighlightHomeSubdirWorks() {
cd -
rm -fr ~/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
}
function testHighlightRootWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
cd /
assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
}
function testHighlightRootSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
cd /tmp
assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)"
cd -
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
}
function testHighlightRootSubSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test
@@ -617,11 +732,16 @@ function testHighlightRootSubSubdirWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
}
function testDirSeparatorColorHomeSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test
@@ -629,11 +749,16 @@ function testDirSeparatorColorHomeSubdirWorks() {
cd -
rm -fr ~/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
}
function testDirSeparatorColorRootSubSubdirWorks() {
- POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
mkdir -p /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test
@@ -641,7 +766,6 @@ function testDirSeparatorColorRootSubSubdirWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
- unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/segments/disk_usage.spec b/test/segments/disk_usage.spec
new file mode 100755
index 00000000..80fc996f
--- /dev/null
+++ b/test/segments/disk_usage.spec
@@ -0,0 +1,131 @@
+#!/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
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+ unset FOLDER
+ unset P9K_HOME
+
+ # Remove IP cache file
+ rm -f ${POWERLEVEL9K_PUBLIC_IP_FILE}
+}
+
+function testDiskUsageSegmentWhenDiskIsAlmostFull() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 97% /"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{red} %F{white%}hdd %f%F{white}97%% %k%F{red}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentWhenDiskIsVeryFull() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 94% /"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black%}hdd %f%F{black}94%% %k%F{yellow}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentWhenDiskIsQuiteEmpty() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 4% /"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow%}hdd %f%F{yellow}4%% %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentPrintsNothingIfDiskIsQuiteEmptyAndOnlyWarningsShouldBeDisplayed() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage custom_world)
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 4% /"
+ }
+
+ local POWERLEVEL9K_DISK_USAGE_ONLY_WARNING=true
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentWarningLevelCouldBeAdjusted() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+ local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=10
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 11% /"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black%}hdd %f%F{black}11%% %k%F{yellow}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+ local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=5
+ local POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL=10
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 11% /"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{red} %F{white%}hdd %f%F{white}11%% %k%F{red}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec
index 9104ac8b..6260aaf5 100755
--- a/test/segments/go_version.spec
+++ b/test/segments/go_version.spec
@@ -7,8 +7,6 @@ SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
}
function mockGo() {
@@ -35,52 +33,56 @@ function mockGoEmptyGopath() {
function testGo() {
alias go=mockGo
- POWERLEVEL9K_GO_ICON=""
+ local POWERLEVEL9K_GO_ICON=""
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(go_version)
- PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ local PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"
- assertEquals "%K{green} %F{grey93%} %f%F{grey93}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
+ assertEquals "%K{green} %F{grey93%} %f%F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_GO_ICON
- unset PWD
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias go
}
function testGoSegmentPrintsNothingIfEmptyGopath() {
- alias go=mockGoEmptyGopath
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias go=mockGoEmptyGopath
- assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_CUSTOM_WORLD
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
}
function testGoSegmentPrintsNothingIfNotInGopath() {
- alias go=mockGo
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias go=mockGo
- assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_CUSTOM_WORLD
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
}
function testGoSegmentPrintsNothingIfGoIsNotAvailable() {
- alias go=noGo
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias go=noGo
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_CUSTOM_WORLD
unalias go
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/segments/ip.spec b/test/segments/ip.spec
new file mode 100755
index 00000000..8ffb41eb
--- /dev/null
+++ b/test/segments/ip.spec
@@ -0,0 +1,231 @@
+#!/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"
+}
+
+function testIpSegmentPrintsNothingOnOsxIfNotConnected() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world)
+ alias networksetup='echo "not connected"'
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS="OSX" # Fake OSX
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias networksetup
+}
+
+function testIpSegmentPrintsNothingOnLinuxIfNotConnected() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world)
+ alias ip='echo "not connected"'
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS="Linux" # Fake Linux
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias ip
+}
+
+function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_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)
+'"
+
+ alias ipconfig="_(){ echo '1.2.3.4'; };_"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS='OSX' # Fake OSX
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(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 POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_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
+ ;;
+ }
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS='OSX' # Fake OSX
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ipconfig
+ unalias networksetup
+}
+
+function testIpSegmentWorksOnOsxWithInterfaceSpecified() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local POWERLEVEL9K_IP_INTERFACE='xxx'
+ alias ipconfig="_(){ echo '1.2.3.4'; };_"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS='OSX' # Fake OSX
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unalias ipconfig
+}
+
+function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() {
+ setopt aliases
+ local POWERLEVEL9K_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
+
+ 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
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS='Linux' # Fake Linux
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}10.0.2.15 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ip
+}
+
+function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() {
+ setopt aliases
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_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
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS='Linux' # Fake Linux
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}10.0.2.15 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ip
+}
+
+function testIpSegmentWorksOnLinuxWithInterfaceSpecified() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local POWERLEVEL9K_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';
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local OS='Linux' # Fake Linux
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}10.0.2.15 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ip
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec
index 63810378..b954de4a 100755
--- a/test/segments/kubecontext.spec
+++ b/test/segments/kubecontext.spec
@@ -7,8 +7,6 @@ SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
}
function mockKubectl() {
@@ -66,33 +64,41 @@ function mockKubectlOtherNamespace() {
}
function testKubeContext() {
- alias kubectl=mockKubectl
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
+ alias kubectl=mockKubectl
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias kubectl
}
function testKubeContextOtherNamespace() {
- alias kubectl=mockKubectlOtherNamespace
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
+ alias kubectl=mockKubectlOtherNamespace
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias kubectl
}
function testKubeContextPrintsNothingIfKubectlNotAvailable() {
- alias kubectl=noKubectl
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias kubectl=noKubectl
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_CUSTOM_WORLD
unalias kubectl
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec
index 40b130d2..c83edfaf 100755
--- a/test/segments/laravel_version.spec
+++ b/test/segments/laravel_version.spec
@@ -7,63 +7,66 @@ SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
}
function mockLaravelVersion() {
case "$1" in
"artisan")
- echo "Laravel Framework version 5.4.23"
+ # artisan --version follows the format Laravel Framework <version>
+ echo "Laravel Framework 5.4.23"
;;
default)
esac
}
function mockNoLaravelVersion() {
- # This should output some error
- >&2 echo "Artisan not available"
- return 1
+ # When php can't find a file it will output a message
+ echo "Could not open input file: artisan"
+ return 0
}
function testLaravelVersionSegment() {
- alias php=mockLaravelVersion
- POWERLEVEL9K_LARAVEL_ICON='x'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version)
+ local POWERLEVEL9K_LARAVEL_ICON='x'
+ alias php=mockLaravelVersion
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_LARAVEL_ICON
unalias php
}
function testLaravelVersionSegmentIfArtisanIsNotAvailable() {
- alias php=mockNoLaravelVersion
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
- POWERLEVEL9K_LARAVEL_ICON='x'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_LARAVEL_ICON='x'
+ alias php=mockNoLaravelVersion
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_LARAVEL_ICON
- unset POWERLEVEL9K_CUSTOM_WORLD
unalias php
}
function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() {
- alias php=noPhp
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
- POWERLEVEL9K_LARAVEL_ICON='x'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_LARAVEL_ICON='x'
+ alias php=noPhp
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_LARAVEL_ICON
- unset POWERLEVEL9K_CUSTOM_WORLD
unalias php
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/segments/load.spec b/test/segments/load.spec
new file mode 100755
index 00000000..9caa82c3
--- /dev/null
+++ b/test/segments/load.spec
@@ -0,0 +1,149 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/load-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testLoadSegmentWorksOnOsx() {
+ sysctl() {
+ if [[ "$*" == 'vm.loadavg' ]]; then
+ echo "vm.loadavg: { 1,38 1,45 2,16 }";
+ fi
+
+ if [[ "$*" == '-n hw.logicalcpu' ]]; then
+ echo "4";
+ fi
+ }
+
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="OSX" # Fake OSX
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unfunction sysctl
+}
+
+function testLoadSegmentWorksOnBsd() {
+ sysctl() {
+ if [[ "$*" == 'vm.loadavg' ]]; then
+ echo "vm.loadavg: { 1,38 1,45 2,16 }";
+ fi
+
+ if [[ "$*" == '-n hw.ncpu' ]]; then
+ echo "4";
+ fi
+ }
+
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="BSD" # Fake BSD
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unfunction sysctl
+}
+
+function testLoadSegmentWorksOnLinux() {
+ # Prepare loadavg
+ mkdir proc
+ echo "1.38 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="Linux" # Fake Linux
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+# Test normal state. This test is not OS specific.
+# We test it as the Linux version, but that
+# does not matter here.
+function testLoadSegmentNormalState() {
+ # Prepare loadavg
+ mkdir proc
+ echo "1.00 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="Linux" # Fake Linux
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.00 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+# Test warning state. This test is not OS specific.
+# We test it as the Linux version, but that
+# does not matter here.
+function testLoadSegmentWarningState() {
+ # Prepare loadavg
+ mkdir proc
+ echo "2.01 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="Linux" # Fake Linux
+
+ assertEquals "%K{yellow} %F{black%}L %f%F{black}2.01 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+# Test critical state. This test is not OS specific.
+# We test it as the Linux version, but that
+# does not matter here.
+function testLoadSegmentCriticalState() {
+ # Prepare loadavg
+ mkdir proc
+ echo "2.81 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="Linux" # Fake Linux
+
+ assertEquals "%K{red} %F{black%}L %f%F{black}2.81 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/node_version.spec b/test/segments/node_version.spec
new file mode 100755
index 00000000..1627f436
--- /dev/null
+++ b/test/segments/node_version.spec
@@ -0,0 +1,41 @@
+#!/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"
+}
+
+function testNodeVersionSegmentPrintsNothingWithoutNode() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias node="nonode 2>/dev/null"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias node
+}
+
+function testNodeVersionSegmentWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version)
+ node() {
+ echo "v1.2.3"
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{white%}⬢ %f%F{white}1.2.3 %k%F{green}%f " "$(build_left_prompt)"
+
+ unfunction node
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec
new file mode 100755
index 00000000..b72b426a
--- /dev/null
+++ b/test/segments/nodeenv.spec
@@ -0,0 +1,99 @@
+#!/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 specfic
+ # unset all possible user specified variables
+ unset NODE_VIRTUAL_ENV_DISABLE_PROMPT
+ unset NODE_VIRTUAL_ENV
+}
+
+function testNodeenvSegmentPrintsNothingWithoutNode() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias node="nonode 2>/dev/null"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias node
+}
+
+function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ node() {
+ echo "v1.2.3"
+ }
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unfunction node
+}
+
+function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ node() {
+ echo "v1.2.3"
+ }
+ NODE_VIRTUAL_ENV="node-env"
+ NODE_VIRTUAL_ENV_DISABLE_PROMPT=true
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unset NODE_VIRTUAL_ENV_DISABLE_PROMPT
+ unset NODE_VIRTUAL_ENV
+ unfunction node
+}
+
+function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv)
+ alias node="nonode 2>/dev/null"
+ NODE_VIRTUAL_ENV="node-env"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{green%}⬢ %f%F{green}[node-env] %k%F{black}%f " "$(build_left_prompt)"
+
+ unset NODE_VIRTUAL_ENV
+ unalias node
+}
+
+function testNodeenvSegmentWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv)
+ node() {
+ echo "v1.2.3"
+ }
+ NODE_VIRTUAL_ENV="node-env"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{green%}⬢ %f%F{green}v1.2.3[node-env] %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction node
+ unset NODE_VIRTUAL_ENV
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec
new file mode 100755
index 00000000..83d4c8f6
--- /dev/null
+++ b/test/segments/nvm.spec
@@ -0,0 +1,72 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/nvm-test
+ mkdir -p "${FOLDER}/bin"
+ OLD_PATH=$PATH
+ PATH=${FOLDER}/bin:$PATH
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Restore old path
+ PATH="${OLD_PATH}"
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testNvmSegmentPrintsNothingIfNvmIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testNvmSegmentWorksWithoutHavingADefaultAlias() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm)
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ function nvm_version() {
+ [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0'
+ }
+
+ assertEquals "%K{magenta} %F{black%}⬢ %f%F{black}4.6.0 %k%F{magenta}%f " "$(build_left_prompt)"
+}
+
+function testNvmSegmentPrintsNothingWhenOnDefaultVersion() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ function nvm_version() {
+ [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v4.6.0'
+ }
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/php_version.spec b/test/segments/php_version.spec
new file mode 100755
index 00000000..1a3ec91b
--- /dev/null
+++ b/test/segments/php_version.spec
@@ -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"
+}
+
+function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias php="nophp"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias php
+}
+
+function testPhpVersionSegmentWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version)
+ alias php="echo 'PHP 5.6.27 (cli) (built: Oct 23 2016 11:47:58)
+Copyright (c) 1997-2016 The PHP Group
+Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
+'"
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{013} %F{255}PHP 5.6.27 %k%F{fuchsia}%f " "$(build_left_prompt)"
+
+ unalias php
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec
new file mode 100755
index 00000000..9a2dcdab
--- /dev/null
+++ b/test/segments/public_ip.spec
@@ -0,0 +1,222 @@
+#!/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
+ cd $FOLDER
+
+ # Change cache file, so that the users environment don't
+ # interfere with the tests.
+ POWERLEVEL9K_PUBLIC_IP_FILE=$FOLDER/public_ip_file
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+ unset FOLDER
+ unset P9K_HOME
+
+ # Unset cache file
+ unset POWERLEVEL9K_PUBLIC_IP_FILE
+}
+
+function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip custom_world)
+ local POWERLEVEL9K_PUBLIC_IP_HOST='http://unknown.xyz'
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ # We need to overwrite dig, as this is a fallback method that
+ # uses an alternative host.
+ alias dig='nodig'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias dig
+}
+
+function testPublicIpSegmentPrintsNoticeIfNotConnected() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ local POWERLEVEL9K_PUBLIC_IP_HOST='http://unknown.xyz'
+ local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected"
+ # We need to overwrite dig, as this is a fallback method that
+ # uses an alternative host.
+ alias dig='nodig'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}disconnected %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias dig
+}
+
+function testPublicIpSegmentWorksWithWget() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ alias dig='nodig'
+ alias curl='nocurl'
+ wget() {
+ echo "wget 1.2.3.4"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}wget 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction wget
+ unalias dig
+ unalias curl
+}
+
+function testPublicIpSegmentUsesCurlAsFallbackMethodIfWgetIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ alias dig='nodig'
+ alias wget='nowget'
+ curl() {
+ echo "curl 1.2.3.4"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}curl 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction curl
+ unalias dig
+ unalias wget
+}
+
+function testPublicIpSegmentUsesDigAsFallbackMethodIfWgetAndCurlAreNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ alias curl='nocurl'
+ alias wget='nowget'
+ dig() {
+ echo "dig 1.2.3.4"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}dig 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+ unalias curl
+ unalias wget
+}
+
+function testPublicIpSegmentCachesFile() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ dig() {
+ echo "first"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+function testPublicIpSegmentRefreshesCachesFileAfterTimeout() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ local POWERLEVEL9K_PUBLIC_IP_TIMEOUT=2
+ dig() {
+ echo "first"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ sleep 3
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}second %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+function testPublicIpSegmentRefreshesCachesFileIfEmpty() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ dig() {
+ echo "first"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ # Truncate cache file
+ echo "" >! $POWERLEVEL9K_PUBLIC_IP_FILE
+
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}second %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+function testPublicIpSegmentWhenGoingOnline() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ local POWERLEVEL9K_PUBLIC_IP_METHODS="dig"
+ local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected"
+ alias dig="nodig"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}disconnected %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias dig
+
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}second %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/ram.spec b/test/segments/ram.spec
new file mode 100755
index 00000000..f1331427
--- /dev/null
+++ b/test/segments/ram.spec
@@ -0,0 +1,66 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/ram-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testRamSegmentWorksOnOsx() {
+ alias vm_stat="echo 'Mach Virtual Memory Statistics: (page size of 4096 bytes)
+Pages free: 299687.
+Pages active: 1623792.
+Pages inactive: 1313411.
+'"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="OSX" # Fake OSX
+
+ assertEquals "%K{yellow} %F{black%}RAM %f%F{black}6.15G " "$(prompt_ram left 1 false ${FOLDER})"
+
+ unalias vm_stat
+}
+
+function testRamSegmentWorksOnBsd() {
+ mkdir -p var/run
+ echo "avail memory 5678B 299687 4444G 299" > var/run/dmesg.boot
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="BSD" # Fake BSD
+
+ assertEquals "%K{yellow} %F{black%}RAM %f%F{black}0.29M " "$(prompt_ram left 1 false ${FOLDER})"
+}
+
+function testRamSegmentWorksOnLinux() {
+ mkdir proc
+ echo "MemAvailable: 299687" > proc/meminfo
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="Linux" # Fake Linux
+
+ assertEquals "%K{yellow} %F{black%}RAM %f%F{black}0.29G " "$(prompt_ram left 1 false ${FOLDER})"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec
index 34883a10..9643125f 100755
--- a/test/segments/rust_version.spec
+++ b/test/segments/rust_version.spec
@@ -14,8 +14,6 @@ function setUp() {
PATH="${RUST_TEST_FOLDER}:${PATH}"
export TERM="xterm-256color"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
}
function tearDown() {
@@ -29,22 +27,25 @@ function mockRust() {
}
function testRust() {
- mockRust
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version)
+ mockRust
- assertEquals "%K{208} %F{black%}Rust %f%F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ assertEquals "%K{208} %F{black%}Rust %f%F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)"
}
function testRustPrintsNothingIfRustIsNotAvailable() {
- POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
- assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_CUSTOM_WORLD
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
}
-source shunit2/source/2.1/src/shunit2
+source shunit2/shunit2
diff --git a/test/segments/ssh.spec b/test/segments/ssh.spec
new file mode 100755
index 00000000..36971e13
--- /dev/null
+++ b/test/segments/ssh.spec
@@ -0,0 +1,80 @@
+#!/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"
+}
+
+function testSshSegmentPrintsNothingIfNoSshConnection() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo "world"'
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ unset SSH_CLIENT
+ unset SSH_TTY
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSshSegmentWorksIfOnlySshClientIsSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh)
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ SSH_CLIENT='ssh-client'
+ unset SSH_TTY
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unset SSH_CLIENT
+}
+
+function testSshSegmentWorksIfOnlySshTtyIsSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh)
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ SSH_TTY='ssh-tty'
+ unset SSH_CLIENT
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unset SSH_TTY
+}
+
+function testSshSegmentWorksIfAllNecessaryVariablesAreSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh)
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ SSH_CLIENT='ssh-client'
+ SSH_TTY='ssh-tty'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unset SSH_TTY
+ unset SSH_CLIENT
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/status.spec b/test/segments/status.spec
index 21bd65bb..97dc6b31 100755
--- a/test/segments/status.spec
+++ b/test/segments/status.spec
@@ -7,8 +7,6 @@ SHUNIT_PARENT=$0
function setUp() {
export TERM="xterm-256color"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
### Test specific
# Resets if someone has set these in his/hers env
@@ -17,69 +15,99 @@ function setUp() {
}
function testStatusPrintsNothingIfReturnCodeIsZeroAndVerboseIsUnset() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status custom_world)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
- local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status custom_world)
local POWERLEVEL9K_STATUS_VERBOSE=false
local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
}
function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
local POWERLEVEL9K_STATUS_VERBOSE=true
local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false
local POWERLEVEL9K_STATUS_HIDE_SIGNAME=true
- local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
assertEquals "%K{black} %F{green%}✔%f %k%F{black}%f " "$(build_left_prompt)"
}
function testStatusInGeneralErrorCase() {
- local RETVAL=1
- local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
local POWERLEVEL9K_STATUS_VERBOSE=true
local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local RETVAL=1
+
assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}1 %k%F{red}%f " "$(build_left_prompt)"
}
function testPipestatusInErrorCase() {
- local -a RETVALS
- RETVALS=(0 0 1 0)
- local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
local POWERLEVEL9K_STATUS_VERBOSE=true
local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=true
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local -a RETVALS
+ RETVALS=(0 0 1 0)
+
assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}0|0|1|0 %k%F{red}%f " "$(build_left_prompt)"
}
function testStatusCrossWinsOverVerbose() {
- local RETVAL=1
- local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false
local POWERLEVEL9K_STATUS_VERBOSE=true
local POWERLEVEL9K_STATUS_CROSS=true
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local RETVAL=1
+
assertEquals "%K{black} %F{red%}✘%f %k%F{black}%f " "$(build_left_prompt)"
}
function testStatusShowsSignalNameInErrorCase() {
- local RETVAL=132
- local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false
local POWERLEVEL9K_STATUS_VERBOSE=true
local POWERLEVEL9K_STATUS_HIDE_SIGNAME=false
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+ local RETVAL=132
+
assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}SIGILL(4) %k%F{red}%f " "$(build_left_prompt)"
}
function testStatusSegmentIntegrated() {
- local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
- local POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status)
+ local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
+ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
+ local POWERLEVEL9K_STATUS_CROSS=true
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
false; powerlevel9k_prepare_prompts
assertEquals "%f%b%k%K{black} %F{red%}✘%f %k%F{black}%f " "${(e)PROMPT}"
}
-source shunit2/source/2.1/src/shunit2 \ No newline at end of file
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/swap.spec b/test/segments/swap.spec
new file mode 100755
index 00000000..2f4fbbf1
--- /dev/null
+++ b/test/segments/swap.spec
@@ -0,0 +1,58 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/swap-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testSwapSegmentWorksOnOsx() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap)
+ sysctl() {
+ echo "vm.swapusage: total = 3072,00M used = 1620,50M free = 1451,50M (encrypted)"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="OSX" # Fake OSX
+
+ assertEquals "%K{yellow} %F{black%}SWP %f%F{black}1.58G " "$(prompt_swap left 1 false ${FOLDER})"
+
+ unfunction sysctl
+}
+
+function testSwapSegmentWorksOnLinux() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap)
+ mkdir proc
+ echo "SwapTotal: 1000000" > proc/meminfo
+ echo "SwapFree: 1000" >> proc/meminfo
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+ local OS="Linux" # Fake Linux
+
+ assertEquals "%K{yellow} %F{black%}SWP %f%F{black}0.95G " "$(prompt_swap left 1 false ${FOLDER})"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/swift_version.spec b/test/segments/swift_version.spec
new file mode 100755
index 00000000..4b7c6351
--- /dev/null
+++ b/test/segments/swift_version.spec
@@ -0,0 +1,57 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testSwiftSegmentPrintsNothingIfSwiftIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias swift="noswift"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias swift
+}
+
+function testSwiftSegmentWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version)
+ function swift() {
+ echo "Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)\nTarget: x86_64-apple-macosx10.9"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{magenta} %F{white%}Swift %f%F{white}3.0.1 %k%F{magenta}%f " "$(build_left_prompt)"
+
+ unfunction swift
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/symfony_version.spec b/test/segments/symfony_version.spec
new file mode 100755
index 00000000..89a2e0be
--- /dev/null
+++ b/test/segments/symfony_version.spec
@@ -0,0 +1,117 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testSymfonyVersionSegmentPrintsNothingIfPhpIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias php="nophp"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias php
+}
+
+function testSymfonyVersionSegmentPrintsNothingIfSymfonyIsNotAvailable() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world)
+ # "Symfony" is not a command, but rather a framework.
+ # To sucessfully execute this test, we just need to
+ # navigate into a folder that does not contain symfony.
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ mkdir app
+ touch app/AppKernel.php
+ function php() {
+ echo "Warning: Unsupported declare strict_types in /Users/dr/Privat/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 19
+
+ Parse error: parse error, expecting `;´ or `{´ in /Users/dr/Privat/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 97"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unfunction php
+}
+
+function testSymfonyVersionSegmentWorks() {
+ startSkipping # Skip test
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version)
+ mkdir app
+ touch app/AppKernel.php
+
+ function php() {
+ echo "Symfony version 3.1.4 - app/dev/debug"
+ }
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{240} %F{black%}SF %f%F{black}3.1.4 %k%F{240}%f " "$(build_left_prompt)"
+
+ unfunction php
+}
+
+function testSymfonyVersionSegmentWorksInNestedFolder() {
+ startSkipping # Skip test
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version)
+ mkdir app
+ touch app/AppKernel.php
+
+ function php() {
+ echo "Symfony version 3.1.4 - app/dev/debug"
+ }
+
+ mkdir -p src/P9K/AppBundle
+ cd src/P9K/AppBundle
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{240} %F{black%}SF %f%F{black}3.1.4 %k%F{240}%f " "$(build_left_prompt)"
+
+ unfunction php
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/todo.spec b/test/segments/todo.spec
new file mode 100755
index 00000000..488dc993
--- /dev/null
+++ b/test/segments/todo.spec
@@ -0,0 +1,58 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ mkdir ${FOLDER}/bin
+ OLD_PATH=$PATH
+ PATH=${FOLDER}/bin:$PATH
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Reset PATH
+ PATH=$OLD_PATH
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testTodoSegmentPrintsNothingIfTodoShIsNotInstalled() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testTodoSegmentWorksAsExpected() {
+ # TODO: Skript in den PATH legen!
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo)
+ echo '#!/bin/sh' > ${FOLDER}/bin/todo.sh
+ echo 'echo "TODO: 34 of 100 tasks shown";' >> ${FOLDER}/bin/todo.sh
+ chmod +x ${FOLDER}/bin/todo.sh
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{244} %F{black%}☑ %f%F{black}100 %k%F{grey50}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec
new file mode 100755
index 00000000..b84e08d9
--- /dev/null
+++ b/test/segments/vcs-git.spec
@@ -0,0 +1,378 @@
+#!/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
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/vcs-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+
+ # Set username and email
+ OLD_GIT_AUTHOR_NAME=$GIT_AUTHOR_NAME
+ GIT_AUTHOR_NAME="Testing Tester"
+ OLD_GIT_AUTHOR_EMAIL=$GIT_AUTHOR_EMAIL
+ GIT_AUTHOR_EMAIL="test@powerlevel9k.theme"
+
+ # Set default username if not already set!
+ if [[ -z $(git config user.name) ]]; then
+ GIT_AUTHOR_NAME_SET_BY_TEST=true
+ git config --global user.name "${GIT_AUTHOR_NAME}"
+ fi
+ # Set default email if not already set!
+ if [[ -z $(git config user.email) ]]; then
+ GIT_AUTHOR_EMAIL_SET_BY_TEST=true
+ git config --global user.email "${GIT_AUTHOR_EMAIL}"
+ fi
+
+ # Initialize FOLDER as git repository
+ git init 1>/dev/null
+}
+
+function tearDown() {
+ if [[ -n "${OLD_GIT_AUTHOR_NAME}" ]]; then
+ GIT_AUTHOR_NAME=$OLD_GIT_AUTHOR
+ unset OLD_GIT_AUTHOR_NAME
+ else
+ unset GIT_AUTHOR_NAME
+ fi
+
+ if [[ -n "${OLD_GIT_AUTHOR_EMAIL}" ]]; then
+ GIT_AUTHOR_EMAIL=$OLD_GIT_AUTHOR_EMAIL
+ unset OLD_GIT_AUTHOR_EMAIL
+ else
+ unset GIT_AUTHOR_EMAIL
+ fi
+
+ if [[ "${GIT_AUTHOR_NAME_SET_BY_TEST}" == "true" ]]; then
+ git config --global --unset user.name
+ fi
+ if [[ "${GIT_AUTHOR_EMAIL_SET_BY_TEST}" == "true" ]]; then
+ git config --global --unset user.email
+ fi
+
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+ unset FOLDER
+}
+
+function testColorOverridingForCleanStateWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan'
+ local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingForModifiedStateWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red'
+ local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow'
+
+ touch testfile
+ git add testfile
+ git commit -m "test" 1>/dev/null
+ echo "test" > testfile
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingForUntrackedStateWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan'
+ local POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow'
+
+ touch testfile
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testGitIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_ICON='Git-Icon'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black%}Git-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testGitlabIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_GITLAB_ICON='GL-Icon'
+
+ # Add a GitLab project as remote origin. This is
+ # sufficient to show the GitLab-specific icon.
+ git remote add origin https://gitlab.com/dritter/gitlab-test-project.git
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black%}GL-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testBitbucketIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_BITBUCKET_ICON='BB-Icon'
+
+ # Add a BitBucket project as remote origin. This is
+ # sufficient to show the BitBucket-specific icon.
+ git remote add origin https://dritter@bitbucket.org/dritter/dr-test.git
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black%}BB-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testGitHubIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_GITHUB_ICON='GH-Icon'
+
+ # Add a GitHub project as remote origin. This is
+ # sufficient to show the GitHub-specific icon.
+ git remote add origin https://github.com/dritter/test.git
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black%}GH-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testUntrackedFilesIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
+
+ # Create untracked file
+ touch "i-am-untracked.txt"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testStagedFilesIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_STAGED_ICON='+'
+
+ # Create staged file
+ touch "i-am-added.txt"
+ git add i-am-added.txt &>/dev/null
+ git commit -m "initial commit" &>/dev/null
+ echo "xx" >> i-am-added.txt
+ git add i-am-added.txt &>/dev/null
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black} master + %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testUnstagedFilesIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_UNSTAGED_ICON='M'
+
+ # Create unstaged (modified, but not added to index) file
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" 1>/dev/null
+ echo "xx" > i-am-modified.txt
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black} master M %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testStashIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_STASH_ICON='S'
+
+ # Create modified file
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" 1>/dev/null
+ echo "xx" > i-am-modified.txt
+ git stash 1>/dev/null
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} master S1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testTagIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" 1>/dev/null
+ git tag "v0.0.1"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} master Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testTagIconInDetachedHeadState() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" &>/dev/null
+ git tag "v0.0.1"
+ touch "file2.txt"
+ git add file2.txt
+ git commit -m "Add File2" &>/dev/null
+ git checkout v0.0.1 &>/dev/null
+ local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=8 HEAD)
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} ${hash} Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testActionHintWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" &>/dev/null
+
+ git clone . ../vcs-test2 &>/dev/null
+ echo "xx" >> i-am-modified.txt
+ git commit -a -m "Modified file" &>/dev/null
+
+ cd ../vcs-test2
+ echo "yy" >> i-am-modified.txt
+ git commit -a -m "Provoke conflict" &>/dev/null
+ git pull &>/dev/null
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black} master %F{red}| merge%f %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testIncomingHintWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON='I'
+
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" &>/dev/null
+
+ git clone . ../vcs-test2 &>/dev/null
+ echo "xx" >> i-am-modified.txt
+ git commit -a -m "Modified file" &>/dev/null
+
+ cd ../vcs-test2
+ git fetch &>/dev/null
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} master I1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testOutgoingHintWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON='o'
+
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" &>/dev/null
+
+ git clone . ../vcs-test2 &>/dev/null
+
+ cd ../vcs-test2
+
+ echo "xx" >> i-am-modified.txt
+ git commit -a -m "Modified file" &>/dev/null
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} master o1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=true
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" 1>/dev/null
+ local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=3 HEAD)
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+ assertEquals "%K{green} %F{black}${hash}  master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=false
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" 1>/dev/null
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+ assertEquals "%K{green} %F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec
new file mode 100755
index 00000000..ff84a3d6
--- /dev/null
+++ b/test/segments/vcs-hg.spec
@@ -0,0 +1,207 @@
+#!/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
+ # Create default folder and hg init it.
+ FOLDER=/tmp/powerlevel9k-test/vcs-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+
+ export HGUSER="Test bot <bot@example.com>"
+
+ hg init 1>/dev/null
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}" &>/dev/null
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test &>/dev/null
+ unset FOLDER
+ unset HGUSER
+}
+
+function testColorOverridingForCleanStateWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan'
+ local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{white} %F{cyan} default %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingForModifiedStateWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red'
+ local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow'
+
+ touch testfile
+ hg add testfile
+ hg commit -m "test" 1>/dev/null
+ echo "test" > testfile
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{red} default ● %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+# There is no staging area in mercurial, therefore there are no "untracked"
+# files.. In case there are added files, we show the VCS segment with a
+# yellow background.
+# This may be improved in future versions, to be a bit more consistent with
+# the git part.
+function testAddedFilesIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ touch "myfile.txt"
+ hg add myfile.txt
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black} default ● %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+# We don't support tagging in mercurial right now..
+function testTagIconWorks() {
+ startSkipping # Skip test
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" 1>/dev/null
+ hg tag "v0.0.1"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} default Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testTagIconInDetachedHeadState() {
+ startSkipping # Skip test
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" &>/dev/null
+ hg tag "v0.0.1"
+ touch "file2.txt"
+ hg add file2.txt
+ hg commit -m "Add File2" &>/dev/null
+ hg checkout v0.0.1 &>/dev/null
+ local hash=$(hg id)
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} ${hash} Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testActionHintWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ touch "i-am-modified.txt"
+ hg add i-am-modified.txt
+ hg commit -m "Add File" &>/dev/null
+
+ hg clone . ../vcs-test2 &>/dev/null
+ echo "xx" >> i-am-modified.txt
+ hg commit -m "Modified file" &>/dev/null
+
+ cd ../vcs-test2
+ echo "yy" >> i-am-modified.txt
+ hg commit -m "Provoke conflict" 2>/dev/null
+ hg pull 1>/dev/null
+ hg merge --tool internal:merge >/dev/null 2>&1
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{yellow} %F{black} default %F{red}| merging%f %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=true
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" 1>/dev/null
+ local hash=$(hg id | head -c ${POWERLEVEL9K_CHANGESET_HASH_LENGTH})
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+
+ assertEquals "%K{green} %F{black}${hash}  default %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=false
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" 1>/dev/null
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+
+ assertEquals "%K{green} %F{black} default %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testMercurialIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_HG_ICON='HG-Icon'
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black%}HG-Icon %f%F{black} default %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testBookmarkIconWorks() {
+ local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_BOOKMARK_ICON='B'
+ hg bookmark "initial"
+
+ # Load Powerlevel9k
+ source ${P9K_HOME}/powerlevel9k.zsh-theme
+
+ assertEquals "%K{green} %F{black} default Binitial %k%F{green}%f " "$(build_left_prompt)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec
deleted file mode 100755
index f6474f61..00000000
--- a/test/segments/vcs.spec
+++ /dev/null
@@ -1,161 +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"
- # Load Powerlevel9k
- source powerlevel9k.zsh-theme
-}
-
-function testColorOverridingForCleanStateWorks() {
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
- POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan'
- POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white'
-
- FOLDER=/tmp/powerlevel9k-test/vcs-test
- mkdir -p $FOLDER
- cd $FOLDER
- git init 1>/dev/null
-
- assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)"
-
- cd -
- rm -fr /tmp/powerlevel9k-test
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_VCS_CLEAN_FOREGROUND
- unset POWERLEVEL9K_VCS_CLEAN_BACKGROUND
-}
-
-function testColorOverridingForModifiedStateWorks() {
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
- POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red'
- POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow'
-
- FOLDER=/tmp/powerlevel9k-test/vcs-test
- mkdir -p $FOLDER
- cd $FOLDER
- git init 1>/dev/null
- git config user.email "test@powerlevel9k.theme"
- git config user.name "Testing Tester"
- touch testfile
- git add testfile
- git commit -m "test" 1>/dev/null
- echo "test" > testfile
-
- assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)"
-
- cd -
- rm -fr /tmp/powerlevel9k-test
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_VCS_MODIFIED_FOREGROUND
- unset POWERLEVEL9K_VCS_MODIFIED_BACKGROUND
-}
-
-function testColorOverridingForUntrackedStateWorks() {
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
- POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan'
- POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow'
-
- FOLDER=/tmp/powerlevel9k-test/vcs-test
- mkdir -p $FOLDER
- cd $FOLDER
- git init 1>/dev/null
- touch testfile
-
- assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)"
-
- cd -
- rm -fr /tmp/powerlevel9k-test
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND
- unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
-}
-
-function testBranchNameTruncatingShortenLength() {
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
- POWERLEVEL9K_VCS_SHORTEN_LENGTH=6
- POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3
- POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"
-
- FOLDER=/tmp/powerlevel9k-test/vcs-test
- mkdir -p $FOLDER
- cd $FOLDER
- git init 1>/dev/null
- touch testfile
-
- assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
-
- POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
- assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)"
-
- cd -
- rm -fr /tmp/powerlevel9k-test
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
- unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
- unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
-}
-
-function testBranchNameTruncatingMinLength() {
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
- POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
- POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=6
- POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"
-
- FOLDER=/tmp/powerlevel9k-test/vcs-test
- mkdir -p $FOLDER
- cd $FOLDER
- git init 1>/dev/null
- touch testfile
-
- assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
-
- POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=7
-
- assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
-
- cd -
- rm -fr /tmp/powerlevel9k-test
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
- unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
- unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
-}
-
-function testBranchNameTruncatingShortenStrategy() {
- POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
- POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
- POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3
- POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"
-
- FOLDER=/tmp/powerlevel9k-test/vcs-test
- mkdir -p $FOLDER
- cd $FOLDER
- git init 1>/dev/null
- touch testfile
-
- assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)"
-
- POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_middle"
-
- assertEquals "%K{green} %F{black} mas…ter ? %k%F{green}%f " "$(build_left_prompt)"
-
- cd -
- rm -fr /tmp/powerlevel9k-test
-
- unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
- unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
- unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
- unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
-}
-
-source shunit2/source/2.1/src/shunit2
diff --git a/test/segments/vi_mode.spec b/test/segments/vi_mode.spec
new file mode 100755
index 00000000..8913dfea
--- /dev/null
+++ b/test/segments/vi_mode.spec
@@ -0,0 +1,48 @@
+#!/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"
+}
+
+function testViInsertModeWorks() {
+ local KEYMAP='viins'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)"
+}
+
+function testViInsertModeWorksWhenLabeledAsMain() {
+ local KEYMAP='main'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)"
+}
+
+function testViCommandModeWorks() {
+ local KEYMAP='vicmd'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{white}NORMAL " "$(prompt_vi_mode left 1 false)"
+}
+
+function testViInsertModeStringIsCustomizable() {
+ local KEYMAP='viins'
+
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)"
+}
+
+source shunit2/shunit2 \ No newline at end of file
diff --git a/test/suite.spec b/test/suite.spec
new file mode 100755
index 00000000..0e51d322
--- /dev/null
+++ b/test/suite.spec
@@ -0,0 +1,17 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+local failed=false
+
+for test in **/*.spec; do
+ echo
+ echo "Now executing ${test}"
+ if [[ "${test}" == "test/suite.spec" ]]; then
+ continue;
+ fi
+ ./${test} || failed=true
+done
+
+if [[ "${failed}" == "true" ]]; then
+ exit 1
+fi \ No newline at end of file