summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml1
-rw-r--r--CHANGELOG.md36
-rw-r--r--README.md143
-rw-r--r--TESTS.md33
-rw-r--r--docker/antibody/Dockerfile8
-rw-r--r--docker/antibody/install.zsh1
-rw-r--r--docker/antibody/zshrc2
-rw-r--r--docker/antigen/Dockerfile8
-rw-r--r--docker/antigen/install.zsh12
-rw-r--r--docker/antigen/zshrc4
-rw-r--r--docker/base-4.3.11/Dockerfile31
-rw-r--r--docker/base-5.0.3/Dockerfile33
-rw-r--r--docker/base-5.1.1/Dockerfile35
-rw-r--r--docker/base-5.2/Dockerfile35
-rw-r--r--docker/dotfile/Dockerfile5
-rw-r--r--docker/dotfile/zshrc1
-rw-r--r--docker/fred-sudoers2
-rw-r--r--docker/omz/Dockerfile8
-rw-r--r--docker/omz/install.zsh4
-rw-r--r--docker/omz/zshrc5
-rw-r--r--docker/prezto/Dockerfile7
-rw-r--r--docker/prezto/install.zsh18
-rw-r--r--docker/zgen/Dockerfile8
-rw-r--r--docker/zgen/install.zsh5
-rw-r--r--docker/zgen/zshrc10
-rw-r--r--docker/zim/Dockerfile7
-rw-r--r--docker/zim/install.zsh21
-rw-r--r--docker/zplug/Dockerfile8
-rw-r--r--docker/zplug/install.zsh5
-rw-r--r--docker/zplug/zshrc5
-rw-r--r--docker/zplugin/Dockerfile8
-rw-r--r--docker/zplugin/install.zsh12
-rw-r--r--docker/zplugin/zshrc.plugins5
-rw-r--r--docker/zpm/Dockerfile8
-rw-r--r--docker/zpm/install.zsh6
-rw-r--r--docker/zpm/zshrc3
-rw-r--r--docker/zulu/Dockerfile7
-rw-r--r--docker/zulu/install.zsh10
-rw-r--r--functions/icons.zsh38
-rw-r--r--functions/utilities.zsh4
-rwxr-xr-xpowerlevel9k.zsh-theme296
-rwxr-xr-xtest-in-docker179
-rwxr-xr-xtest/segments/dir.spec25
-rwxr-xr-xtest/segments/kubecontext.spec80
44 files changed, 1089 insertions, 93 deletions
diff --git a/.travis.yml b/.travis.yml
index 134f31f1..e0ad5a93 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -28,3 +28,4 @@ script:
- test/segments/rust_version.spec
- test/segments/go_version.spec
- test/segments/vcs.spec
+ - test/segments/kubecontext.spec
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6257416b..42120aea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,34 @@
+## Next
+
+- Added `teardown` command to turn off P9k prompt.
+- Fixes for P9k in Cygwin and 32-bit systems.
+- Better colors in virtualization segments.
+- Added 'Gopher' icon to the `go_version` segment.
+- Improved detection in `nvm`
+- Added option to support command status reading from piped command sequences.
+
+### New Segments: `host` and `user`
+
+Provides two separate segments for `host` and `user` in case you don't wont both
+in one (per the `context` segment).
+
+### New Segment: `newline`
+
+Allows you to split segments across multiple lines.
+
+### New Segment: `kubecontext`
+
+Shows the current context of your `kubectl` configuration.
+
+### New Segment: `vpn`
+
+Shows current `vpn` interface.
+
+## v0.6.4
+
+- Significant enhancements to the `battery` segment. Check out the README to
+ read more!
+
## v0.6.3
- Fixed susceptibility to [pw3nage exploit](https://github.com/njhartwell/pw3nage).
@@ -26,6 +57,11 @@ A new script `debug/font-issues.zsh` was added, so that problems with your font
The `ram` segment now shows the available ram instead of free.
+### Add new segments `host` and `user`
+
+The user and host segments allow you to have different icons and colors for both the user and host segments
+depending on their state.
+
## v0.6.0
- Fixed a bug where the tag display was broken on detached HEADs.
diff --git a/README.md b/README.md
index bb07b7fd..9c17c2c5 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,9 @@ The segments that are currently available are:
* `dir_writable` - Displays a lock icon, if you do not have write permissions on the current folder.
* [`disk_usage`](#disk_usage) - Disk usage of your current partition.
* `history` - The command number for the current line.
+* [`host`](#host) - Your current host name
* [`ip`](#ip) - Shows the current IP address.
+* [`vpn`](#vpn) - Shows the current VPN IP address.
* [`public_ip`](#public_ip) - Shows your public IP address.
* `load` - Your machine's load averages.
* `os_icon` - Display a nice little icon, depending on your operating system.
@@ -101,6 +103,7 @@ The segments that are currently available are:
* [`status`](#status) - The return code of the previous command.
* `swap` - Prints the current swap size.
* [`time`](#time) - System time.
+* [`user`](#user) - Your current username
* [`vi_mode`](#vi_mode)- Your prompt's Vi editing mode (NORMAL|INSERT).
* `ssh` - Indicates whether or not you are in an SSH session.
@@ -136,6 +139,7 @@ The segments that are currently available are:
* [`aws`](#aws) - The current AWS profile, if active.
* `aws_eb_env` - The current Elastic Beanstalk Environment.
* `docker_machine` - The current Docker Machine.
+* `kubecontext` - The current context of your `kubectl` configuration.
**Other:**
* [`custom_command`](#custom_command) - Create a custom segment to display the
@@ -143,6 +147,7 @@ The segments that are currently available are:
* [`command_execution_time`](#command_execution_time) - Display the time the current command took to execute.
* [`todo`](http://todotxt.com/) - Shows the number of tasks in your todo.txt tasks file.
* `detect_virt` - Virtualization detection with systemd
+* `newline` - Continues the prompt on a new line.
---------------------------------------------------------------------------------
@@ -184,9 +189,8 @@ your `~/.zshrc`:
##### battery
-This segment will display your current battery status (fails gracefully on
-systems without a battery). It is supported on both OSX and Linux (note that it
-requires `acpi` on Linux).
+The default settings for this segment will display your current battery status (fails gracefully on
+systems without a battery). It is supported on both OSX and Linux (note that it requires `acpi` on Linux).
| Variable | Default Value | Description |
|----------|---------------|-------------|
@@ -201,6 +205,56 @@ Note that you can [modify the `_FOREGROUND`
color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)
without affecting the icon color.
+You can also change the battery icon automatically depending on the battery
+level. This will override the default battery icon. In order to do this, you
+need to define the `POWERLEVEL9k_BATTERY_STAGES` variable.
+
+| Variable | Default Value | Description |
+| `POWERLEVEL9K_BATTERY_STAGES`|Unset|A string or array, which each index indicates a charge level.|
+
+Powerlevel9k will use each index of the string or array as a stage to indicate battery
+charge level, progressing from left to right. You can provide any number of
+stages. The setting below, for example, provides 8 stages for Powerlevel9k to use.
+```zsh
+POWERLEVEL9K_BATTERY_STAGES="▁▂▃▄▅▆▇█"
+```
+
+If you require extra spacing after the icon, you will have to set it as an array,
+since spaces in the string will be used as one of the stages and you will get a
+missing icon. To do this, declare the variable as follows:
+```zsh
+POWERLEVEL9K_BATTERY_STAGES=($'\u2581 ' $'\u2582 ' $'\u2583 ' $'\u2584 ' $'\u2585 ' $'\u2586 ' $'\u2587 ' $'\u2588 ')
+```
+
+Using the array syntax, you can create stages comprised of multiple characters.
+The below setting provides 40 battery stages.
+```zsh
+POWERLEVEL9K_BATTERY_STAGES=(
+ $'▏ ▏' $'▎ ▏' $'▍ ▏' $'▌ ▏' $'▋ ▏' $'▊ ▏' $'▉ ▏' $'█ ▏'
+ $'█▏ ▏' $'█▎ ▏' $'█▍ ▏' $'█▌ ▏' $'█▋ ▏' $'█▊ ▏' $'█▉ ▏' $'██ ▏'
+ $'██ ▏' $'██▎ ▏' $'██▍ ▏' $'██▌ ▏' $'██▋ ▏' $'██▊ ▏' $'██▉ ▏' $'███ ▏'
+ $'███ ▏' $'███▎ ▏' $'███▍ ▏' $'███▌ ▏' $'███▋ ▏' $'███▊ ▏' $'███▉ ▏' $'████ ▏'
+ $'████ ▏' $'████▎▏' $'████▍▏' $'████▌▏' $'████▋▏' $'████▊▏' $'████▉▏' $'█████▏' )
+```
+
+You can also change the background of the segment automatically depending on the
+battery level. This will override the following variables:
+`POWERLEVEL9K_BATTERY_CHARGING`, `POWERLEVEL9K_BATTERY_CHARGED`,
+`POWERLEVEL9K_BATTERY_DISCONNECTED`, and `POWERLEVEL9K_BATTERY_LOW_COLOR`. In
+order to do this, define a color array, from low to high, as shown below:
+```zsh
+POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND=(196 202 208 214 220 226 190 154 118 82 46)
+```
+
+As with the battery stages, you can use any number of colors and Powerlevel9k
+will automatically use all of them appropriately.
+
+Some example settings:
+|Brightness|Possible Array|
+|Bright Colors|(196 202 208 214 220 226 190 154 118 82 46)|
+|Normal Colors|(124 130 136 142 148 112 76 40 34 28 22)|
+|Subdued Colors|( 88 94 100 106 70 34 28 22)|
+
##### command_execution_time
Display the time the previous command took to execute if the time is above
@@ -261,11 +315,11 @@ elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`.
You can customize the `context` segment. For example, you can make it to print the
full hostname by setting
+
```
POWERLEVEL9K_CONTEXT_TEMPLATE="%n@`hostname -f`"
```
-
You can set the `POWERLEVEL9K_CONTEXT_HOST_DEPTH` variable to change how the
hostname is displayed. See (ZSH Manual)[http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Login-information]
for details. The default is set to %m which will show the hostname up to the first ‘.’
@@ -349,7 +403,11 @@ You can also customize the leading tilde character when you are in `$HOME` using
# Double quotes are important here!
POWERLEVEL9K_HOME_FOLDER_ABBREVIATION="%F{red} $(print_icon 'HOME_ICON') %F{black}"
```
+You can also configure the `dir` segment to show when you are in a directory without write permissions, using the variable below.
+| Variable | Default Value | Description |
+|----------|---------------|-------------|
+|`POWERLEVEL9K_DIR_SHOW_WRITABLE`|`false`|If set to `true` and you are in a directory that you do not have write permissions for, this segment will display a lock icon and enter the `NOT_WRITABLE` state (which can be customized per [our usual process](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization). Note that this functionality is also available in a separate segment, `dir_writable`.|
##### disk_usage
@@ -361,6 +419,28 @@ The `disk_usage` segment will show the usage level of the partition that your cu
|POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL|90|The usage level that triggers a warning state.|
|POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL|95|The usage level that triggers a critical state.|
+##### host
+
+The `host` segment will print the hostname.
+
+You can set the `POWERLEVEL9K_HOST_TEMPLATE` variable to change how the hostname
+is displayed. See (ZSH Manual)[http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Login-information]
+for details. The default is set to `%m` which will show the hostname up to the
+first `.`. You can set it to `%{N}m` where N is an integer to show that many
+segments of system hostname. Setting `N` to a negative integer will show that many
+segments from the end of the hostname.
+
+```
+POWERLEVEL9K_HOST_TEMPLATE="%2m"
+```
+
+By default, LOCAL hosts will show the host icon and remote hosts will show the SSH icon. You can override them by setting
+```
+POWERLEVEL9K_HOST_ICON="\uF109 " # 
+POWERLEVEL9K_SSH_ICON="\uF489 " # 
+```
+
+
##### ip
This segment tries to examine all currently used network interfaces and prints
@@ -371,6 +451,14 @@ specify the correct network interface by setting:
|----------|---------------|-------------|
|`POWERLEVEL9K_IP_INTERFACE`|None|The NIC for which you wish to display the IP address. Example: `eth0`.|
+##### vpn
+
+This segment tries to extract the VPN related IP addresses from nmcli, based on the NIC type:
+
+| Variable | Default Value | Description |
+|----------|---------------|-------------|
+|`POWERLEVEL9K_VPN_IP_INTERFACE`|`tun`|The VPN interface.|
+
##### public_ip
This segment will display your public IP address. There are several methods of obtaining this
@@ -394,6 +482,15 @@ segment will not be displayed.
|`POWERLEVEL9K_PUBLIC_IP_METHODS`|(dig curl wget)| These methods in that order are used to refresh your IP.|
|`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained|
+##### newline
+
+Puts a newline in your prompt so you can continue using segments on the next
+line. This allows you to use segments on both lines, unlike
+`POWERLEVEL9K_PROMPT_ON_NEWLINE`, which simply separates segments from the
+prompt itself.
+
+This only works on the left side. On the right side it does nothing.
+
##### rbenv
This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack.
@@ -413,8 +510,10 @@ This segment shows the return code of the last command.
| Variable | Default Value | Description |
|----------|---------------|-------------|
-|`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to not show the error code when the last command returned an error and optionally hide this segment when the last command completed successfully by setting `POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE` to false.|
-|`POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE`|`false`|Set to true if you wish to show this segment when the last command completed successfully in non-verbose mode.|
+|`POWERLEVEL9K_STATUS_CROSS`|`false`|Set to true if you wish not to show the error code when the last command returned an error and optionally hide this segment when the last command completed successfully by setting `POWERLEVEL9K_STATUS_OK` to false.|
+|`POWERLEVEL9K_STATUS_OK`|`true`|Set to true if you wish to show this segment when the last command completed successfully, false to hide it.|
+|`POWERLEVEL9K_STATUS_SHOW_PIPESTATUS`|`true`|Set to true if you wish to show the exit status for all piped commands.|
+|`POWERLEVEL9K_STATUS_HIDE_SIGNAME`|`false`|Set to true return the raw exit code (`1-255`). When set to false, values over 128 are shown as `SIGNAME(-n)` (e.g. `KILL(-9)`)|
##### ram
@@ -443,6 +542,23 @@ segment, as well:
# Output time, date, and a symbol from the "Awesome Powerline Font" set
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}"
```
+##### user
+
+The `user` segment will print the username.
+
+You can also override the icons by setting:
+
+```
+POWERLEVEL9K_USER_ICON="\uF415" # 
+POWERLEVEL9K_ROOT_ICON="#"
+```
+
+| Variable | Default Value | Description |
+|----------|---------------|-------------|
+|`DEFAULT_USER`|None|Username to consider a "default context".|
+|`POWERLEVEL9K_ALWAYS_SHOW_USER`|`false`|Always print this segment.|
+|`POWERLEVEL9K_USER_TEMPLATE`|`%n`|Default username prompt. Refer to the [ZSH Documentation](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html) for all possible expansions|
+
##### vcs
By default, the `vcs` segment will provide quite a bit of information. Further
@@ -499,6 +615,21 @@ is count your source files and test files, and calculate the ratio between them.
Just enough to give you a quick overview about the test situation of the project
you are dealing with.
+### Disabling / Enabling Powerlevel9k
+
+You can disable P9k and return to a very basic prompt at any time simply by
+calling:
+
+```zsh
+$ prompt_powerlevel9k_teardown
+```
+
+You can then re-enable it by calling:
+
+```zsh
+$ prompt_powerlevel9k_setup
+```
+
### tl; dr
Want to just get a quick start? Check out the [Show Off Your
diff --git a/TESTS.md b/TESTS.md
index d51051c5..eb5db704 100644
--- a/TESTS.md
+++ b/TESTS.md
@@ -13,10 +13,37 @@ Tests in separate files under `test/functions`.
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`.
-# Test-VMs
+# 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 could use our Test-VMs!
+occurs only in a specific ZSH framework) then you can use either Docker or
+or our Vagrant.
+
+## Docker
+
+This is the easiest to use _if_ you have Docker already installed and running.
+
+The command `./test-in-docker` should make it fairly easy to get into a running
+container with the framework of your choice.
+
+Examples:
+
+``` zsh
+# Test Antigen with the oldest version of ZSH
+$ ./test-in-docker antigen
+```
+
+``` zsh
+# Test Prezto with ZSH version 5.2
+$ ./test-in-docker --zsh 5.2 prezto
+```
+
+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
+
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!
-For how to run the machines see [here](test-vm/README.md). \ No newline at end of file
+For how to run the machines see [here](test-vm/README.md).
diff --git a/docker/antibody/Dockerfile b/docker/antibody/Dockerfile
new file mode 100644
index 00000000..84a60a89
--- /dev/null
+++ b/docker/antibody/Dockerfile
@@ -0,0 +1,8 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/antibody/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
+COPY docker/antibody/zshrc .zshrc
diff --git a/docker/antibody/install.zsh b/docker/antibody/install.zsh
new file mode 100644
index 00000000..4c54fa68
--- /dev/null
+++ b/docker/antibody/install.zsh
@@ -0,0 +1 @@
+curl -sL https://git.io/antibody | bash -s
diff --git a/docker/antibody/zshrc b/docker/antibody/zshrc
new file mode 100644
index 00000000..d516b679
--- /dev/null
+++ b/docker/antibody/zshrc
@@ -0,0 +1,2 @@
+source <(antibody init)
+antibody bundle ~/p9k/
diff --git a/docker/antigen/Dockerfile b/docker/antigen/Dockerfile
new file mode 100644
index 00000000..d8d0a4bc
--- /dev/null
+++ b/docker/antigen/Dockerfile
@@ -0,0 +1,8 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/antigen/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
+COPY docker/antigen/zshrc .zshrc
diff --git a/docker/antigen/install.zsh b/docker/antigen/install.zsh
new file mode 100644
index 00000000..6bab8ab3
--- /dev/null
+++ b/docker/antigen/install.zsh
@@ -0,0 +1,12 @@
+#!/bin/zsh
+
+mkdir ~/antigen
+
+curl \
+ -qLsSf \
+ -o ~/antigen/antigen.zsh \
+ https://git.io/antigen
+
+source ~/antigen/antigen.zsh
+
+# EOF
diff --git a/docker/antigen/zshrc b/docker/antigen/zshrc
new file mode 100644
index 00000000..0f8d4da4
--- /dev/null
+++ b/docker/antigen/zshrc
@@ -0,0 +1,4 @@
+source ~/antigen/antigen.zsh
+
+antigen theme "${HOME}/p9k" powerlevel9k --no-local-clone
+antigen apply
diff --git a/docker/base-4.3.11/Dockerfile b/docker/base-4.3.11/Dockerfile
new file mode 100644
index 00000000..805a7ae1
--- /dev/null
+++ b/docker/base-4.3.11/Dockerfile
@@ -0,0 +1,31 @@
+FROM centos:6
+
+RUN \
+ yum install -y \
+ curl \
+ git \
+ zsh \
+ mercurial \
+ subversion \
+ golang \
+ jq \
+ node \
+ ruby \
+ python \
+ python-virtualenv \
+ sudo
+
+RUN adduser --shell /bin/zsh --comment 'fred' --user-group fred
+
+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.0.3/Dockerfile b/docker/base-5.0.3/Dockerfile
new file mode 100644
index 00000000..e0b6c6c3
--- /dev/null
+++ b/docker/base-5.0.3/Dockerfile
@@ -0,0 +1,33 @@
+FROM ubuntu:14.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 \
+ mercurial \
+ subversion \
+ golang \
+ jq \
+ node \
+ ruby \
+ python \
+ python-virtualenv
+
+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.1.1/Dockerfile b/docker/base-5.1.1/Dockerfile
new file mode 100644
index 00000000..a7f644bf
--- /dev/null
+++ b/docker/base-5.1.1/Dockerfile
@@ -0,0 +1,35 @@
+FROM ubuntu:16.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 \
+ 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.2/Dockerfile b/docker/base-5.2/Dockerfile
new file mode 100644
index 00000000..62a10074
--- /dev/null
+++ b/docker/base-5.2/Dockerfile
@@ -0,0 +1,35 @@
+FROM ubuntu:17.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 \
+ 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/dotfile/Dockerfile b/docker/dotfile/Dockerfile
new file mode 100644
index 00000000..f29c4d56
--- /dev/null
+++ b/docker/dotfile/Dockerfile
@@ -0,0 +1,5 @@
+ARG base
+FROM p9k:${base}
+
+COPY ./ p9k/
+COPY docker/dotfile/zshrc .zshrc
diff --git a/docker/dotfile/zshrc b/docker/dotfile/zshrc
new file mode 100644
index 00000000..382b84a8
--- /dev/null
+++ b/docker/dotfile/zshrc
@@ -0,0 +1 @@
+source "${HOME}/p9k/prompt_powerlevel9k_setup"
diff --git a/docker/fred-sudoers b/docker/fred-sudoers
new file mode 100644
index 00000000..5fcd646f
--- /dev/null
+++ b/docker/fred-sudoers
@@ -0,0 +1,2 @@
+Defaults:fred !requiretty
+fred ALL=(ALL) NOPASSWD: ALL
diff --git a/docker/omz/Dockerfile b/docker/omz/Dockerfile
new file mode 100644
index 00000000..1a417b9f
--- /dev/null
+++ b/docker/omz/Dockerfile
@@ -0,0 +1,8 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/omz/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY docker/omz/zshrc .zshrc
+COPY ./ p9k/
diff --git a/docker/omz/install.zsh b/docker/omz/install.zsh
new file mode 100644
index 00000000..e2cdfa96
--- /dev/null
+++ b/docker/omz/install.zsh
@@ -0,0 +1,4 @@
+sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
+
+mkdir -p ~/.oh-my-zsh/custom/themes
+ln -nsf ~/p9k/ ~/.oh-my-zsh/custom/themes/powerlevel9k
diff --git a/docker/omz/zshrc b/docker/omz/zshrc
new file mode 100644
index 00000000..9e798e2d
--- /dev/null
+++ b/docker/omz/zshrc
@@ -0,0 +1,5 @@
+export ZSH=$HOME/.oh-my-zsh
+ZSH_THEME="powerlevel9k/powerlevel9k"
+plugins=(git rake ruby)
+
+source $ZSH/oh-my-zsh.sh
diff --git a/docker/prezto/Dockerfile b/docker/prezto/Dockerfile
new file mode 100644
index 00000000..70f3b65d
--- /dev/null
+++ b/docker/prezto/Dockerfile
@@ -0,0 +1,7 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/prezto/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
diff --git a/docker/prezto/install.zsh b/docker/prezto/install.zsh
new file mode 100644
index 00000000..9cca57ed
--- /dev/null
+++ b/docker/prezto/install.zsh
@@ -0,0 +1,18 @@
+#!/bin/zsh
+
+set -eu
+
+git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
+
+setopt EXTENDED_GLOB
+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" \
+ "${HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup"
+
+echo "zstyle ':prezto:module:prompt' theme 'powerlevel9k'" \
+ >> "${HOME}/.zpreztorc"
+
+# EOF
diff --git a/docker/zgen/Dockerfile b/docker/zgen/Dockerfile
new file mode 100644
index 00000000..48e44c77
--- /dev/null
+++ b/docker/zgen/Dockerfile
@@ -0,0 +1,8 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/zgen/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
+COPY docker/zgen/zshrc .zshrc
diff --git a/docker/zgen/install.zsh b/docker/zgen/install.zsh
new file mode 100644
index 00000000..5cdc6181
--- /dev/null
+++ b/docker/zgen/install.zsh
@@ -0,0 +1,5 @@
+#!/bin/zsh
+
+git clone https://github.com/tarjoilija/zgen.git "${HOME}/.zgen"
+
+# EOF
diff --git a/docker/zgen/zshrc b/docker/zgen/zshrc
new file mode 100644
index 00000000..1fcb75b9
--- /dev/null
+++ b/docker/zgen/zshrc
@@ -0,0 +1,10 @@
+# load zgen
+source ~/.zgen/zgen.zsh
+
+# if the init scipt doesn't exist
+if ! zgen saved; then
+ zgen load ~/p9k/powerlevel9k.zsh-theme
+
+ # generate the init script from plugins above
+ zgen save
+fi
diff --git a/docker/zim/Dockerfile b/docker/zim/Dockerfile
new file mode 100644
index 00000000..cfe0fc93
--- /dev/null
+++ b/docker/zim/Dockerfile
@@ -0,0 +1,7 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/zim/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
diff --git a/docker/zim/install.zsh b/docker/zim/install.zsh
new file mode 100644
index 00000000..d6c6006a
--- /dev/null
+++ b/docker/zim/install.zsh
@@ -0,0 +1,21 @@
+#!zsh
+
+git clone --recursive https://github.com/Eriner/zim.git "${ZDOTDIR:-${HOME}}/.zim"
+
+setopt EXTENDED_GLOB
+for template_file ( ${ZDOTDIR:-${HOME}}/.zim/templates/* ); do
+ user_file="${ZDOTDIR:-${HOME}}/.${template_file:t}"
+ touch ${user_file}
+ ( print -rn "$(<${template_file})$(<${user_file})" >! ${user_file} ) 2>/dev/null
+done
+
+source "${ZDOTDIR:-${HOME}}/.zlogin"
+
+ln -nsf \
+ ~/p9k/ \
+ ~/.zim/modules/prompt/external-themes/powerlevel9k
+ln -nsf \
+ ~/.zim/modules/prompt/external-themes/powerlevel9k/powerlevel9k.zsh-theme \
+ ~/.zim/modules/prompt/functions/prompt_powerlevel9k_setup
+
+sed -i "s/zprompt_theme='steeef'/zprompt_theme='powerlevel9k'/g" ~/.zimrc
diff --git a/docker/zplug/Dockerfile b/docker/zplug/Dockerfile
new file mode 100644
index 00000000..89c23d54
--- /dev/null
+++ b/docker/zplug/Dockerfile
@@ -0,0 +1,8 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/zplug/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
+COPY docker/zplug/zshrc .zshrc
diff --git a/docker/zplug/install.zsh b/docker/zplug/install.zsh
new file mode 100644
index 00000000..b01ff6ee
--- /dev/null
+++ b/docker/zplug/install.zsh
@@ -0,0 +1,5 @@
+#!zsh
+
+curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh| zsh
+
+# git clone https://github.com/zplug/zplug "${HOME}/.zplug"
diff --git a/docker/zplug/zshrc b/docker/zplug/zshrc
new file mode 100644
index 00000000..0a4ceb83
--- /dev/null
+++ b/docker/zplug/zshrc
@@ -0,0 +1,5 @@
+#!zsh
+
+source ~/.zplug/init.zsh
+zplug "${HOME}/p9k", use:"powerlevel9k.zsh-theme", from:local, as:theme
+zplug load --verbose
diff --git a/docker/zplugin/Dockerfile b/docker/zplugin/Dockerfile
new file mode 100644
index 00000000..90c35c0e
--- /dev/null
+++ b/docker/zplugin/Dockerfile
@@ -0,0 +1,8 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/zplugin/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
+COPY docker/zplugin/zshrc.plugins .zshrc.plugins
diff --git a/docker/zplugin/install.zsh b/docker/zplugin/install.zsh
new file mode 100644
index 00000000..fec4249d
--- /dev/null
+++ b/docker/zplugin/install.zsh
@@ -0,0 +1,12 @@
+sh -c "$(curl -fsSL https://raw.githubusercontent.com/psprint/zplugin/master/doc/install.sh)"
+
+# The 'zplugin snippet' only copies the .zsh-theme file, not everything else.
+mkdir -p ~/.zplugin/snippets
+ln -nsf \
+ ~/p9k/ \
+~/.zplugin/snippets/--SLASH--home--SLASH--fred--SLASH--p9k--SLASH--powerlevel9k--DOT--zsh-theme
+
+{
+ echo
+ echo "source ~/.zshrc.plugins"
+} >> ~/.zshrc
diff --git a/docker/zplugin/zshrc.plugins b/docker/zplugin/zshrc.plugins
new file mode 100644
index 00000000..2e9ba7a3
--- /dev/null
+++ b/docker/zplugin/zshrc.plugins
@@ -0,0 +1,5 @@
+#!zsh
+
+zplugin load psprint zsh-navigation-tools
+zplugin load psprint---zprompts
+zplugin snippet ~/p9k/powerlevel9k.zsh-theme
diff --git a/docker/zpm/Dockerfile b/docker/zpm/Dockerfile
new file mode 100644
index 00000000..c1c44e38
--- /dev/null
+++ b/docker/zpm/Dockerfile
@@ -0,0 +1,8 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/zpm/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
+COPY docker/zpm/zshrc .zshrc
diff --git a/docker/zpm/install.zsh b/docker/zpm/install.zsh
new file mode 100644
index 00000000..6f74e8e0
--- /dev/null
+++ b/docker/zpm/install.zsh
@@ -0,0 +1,6 @@
+# install zpm
+git clone --recursive https://github.com/zpm-zsh/zpm.git ~/.zpm
+
+# Install powerlevel9k
+mkdir ~/.zpm/plugins/powerlevel9k
+ln -s ~/p9k/powerlevel9k.zsh-theme ~/.zpm/plugins/powerlevel9k/powerlevel9k.plugin.zsh
diff --git a/docker/zpm/zshrc b/docker/zpm/zshrc
new file mode 100644
index 00000000..b107976e
--- /dev/null
+++ b/docker/zpm/zshrc
@@ -0,0 +1,3 @@
+source ~/.zpm/zpm.zsh
+
+zpm load powerlevel9k
diff --git a/docker/zulu/Dockerfile b/docker/zulu/Dockerfile
new file mode 100644
index 00000000..880a07d0
--- /dev/null
+++ b/docker/zulu/Dockerfile
@@ -0,0 +1,7 @@
+ARG base
+FROM p9k:${base}
+
+COPY docker/zulu/install.zsh /tmp/
+RUN zsh /tmp/install.zsh
+
+COPY ./ p9k/
diff --git a/docker/zulu/install.zsh b/docker/zulu/install.zsh
new file mode 100644
index 00000000..0ad6aae3
--- /dev/null
+++ b/docker/zulu/install.zsh
@@ -0,0 +1,10 @@
+#!zsh
+
+# install zulu https://github.com/zulu-zsh/zulu
+curl -L https://git.io/zulu-install | zsh && zsh
+
+{
+echo 'zulu fpath add ~/p9k'
+echo 'zulu fpath add ~/p9k/functions'
+echo 'zulu theme powerlevel9k'
+} >> ~/.zshrc
diff --git a/functions/icons.zsh b/functions/icons.zsh
index ab4d2bac..3a4909f7 100644
--- a/functions/icons.zsh
+++ b/functions/icons.zsh
@@ -39,9 +39,11 @@ case $POWERLEVEL9K_MODE in
FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF'
NODE_ICON $'\u2B22' # ⬢
- MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500'
- MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 '
+ MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
+ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
+ MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
APPLE_ICON $'\uE26E' # 
+ WINDOWS_ICON $'\uE26F' # 
FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE270' # 
LINUX_ICON $'\uE271' # 
@@ -83,6 +85,8 @@ case $POWERLEVEL9K_MODE in
LOCK_ICON $'\UE138' # 
EXECUTION_TIME_ICON $'\UE89C' # 
SSH_ICON '(ssh)'
+ VPN_ICON '(vpn)'
+ KUBERNETES_ICON $'\U2388' # ⎈
)
;;
'awesome-fontconfig')
@@ -111,8 +115,10 @@ case $POWERLEVEL9K_MODE in
SYMFONY_ICON 'SF'
NODE_ICON $'\u2B22' # ⬢
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
- MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
+ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
+ MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
APPLE_ICON $'\uF179' # 
+ WINDOWS_ICON $'\uF17A' # 
FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE17B' # 
LINUX_ICON $'\uF17C' # 
@@ -150,6 +156,8 @@ case $POWERLEVEL9K_MODE in
LOCK_ICON $'\UE138' # 
EXECUTION_TIME_ICON $'\uF253'
SSH_ICON '(ssh)'
+ VPN_ICON $'\uF023'
+ KUBERNETES_ICON $'\U2388' # ⎈
)
;;
'nerdfont-complete'|'nerdfont-fontconfig')
@@ -172,14 +180,16 @@ case $POWERLEVEL9K_MODE in
TEST_ICON $'\uF188' # 
TODO_ICON $'\uF133' # 
BATTERY_ICON $'\UF240 ' # 
- DISK_ICON $'\uF0A0' # 
+ DISK_ICON $'\uF0A0' # 
OK_ICON $'\uF00C' # 
FAIL_ICON $'\uF00D' # 
SYMFONY_ICON $'\uE757' # 
NODE_ICON $'\uE617 ' # 
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
- MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
+ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
+ MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
APPLE_ICON $'\uF179' # 
+ WINDOWS_ICON $'\uF17A' # 
FREEBSD_ICON $'\UF30E ' # 
ANDROID_ICON $'\uF17B' # 
LINUX_ICON $'\uF17C' # 
@@ -206,7 +216,7 @@ case $POWERLEVEL9K_MODE in
VCS_GIT_ICON $'\uF113 ' # 
VCS_GIT_GITHUB_ICON $'\uE709 ' # 
VCS_GIT_BITBUCKET_ICON $'\uE703 ' # 
- VCS_GIT_GITLAB_ICON $'\uF296 ' # 
+ VCS_GIT_GITLAB_ICON $'\uF296 ' # 
VCS_HG_ICON $'\uF0C3 ' # 
VCS_SVN_ICON $'\uE72D ' # 
RUST_ICON $'\uE7A8 ' # 
@@ -214,9 +224,11 @@ case $POWERLEVEL9K_MODE in
SWIFT_ICON $'\uE755' # 
GO_ICON $'\uE626' # 
PUBLIC_IP_ICON $'\UF0AC' # 
- LOCK_ICON $'\UF023' # 
- EXECUTION_TIME_ICON $'\uF252' # 
- SSH_ICON $'\uF489' # 
+ LOCK_ICON $'\UF023' # 
+ EXECUTION_TIME_ICON $'\uF252' # 
+ SSH_ICON $'\uF489' # 
+ VPN_ICON '(vpn)'
+ KUBERNETES_ICON $'\U2388' # ⎈
)
;;
*)
@@ -244,9 +256,11 @@ case $POWERLEVEL9K_MODE in
FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF'
NODE_ICON $'\u2B22' # ⬢
- MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\u2500'
- MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\u2500 '
+ MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
+ MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
+ MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
APPLE_ICON 'OSX'
+ WINDOWS_ICON 'WIN'
FREEBSD_ICON 'BSD'
ANDROID_ICON 'And'
LINUX_ICON 'Lx'
@@ -284,6 +298,8 @@ case $POWERLEVEL9K_MODE in
LOCK_ICON $'\UE0A2'
EXECUTION_TIME_ICON 'Dur'
SSH_ICON '(ssh)'
+ VPN_ICON '(vpn)'
+ KUBERNETES_ICON $'\U2388' # ⎈
)
;;
esac
diff --git a/functions/utilities.zsh b/functions/utilities.zsh
index 39c5ecae..b4bfb838 100644
--- a/functions/utilities.zsh
+++ b/functions/utilities.zsh
@@ -85,6 +85,10 @@ case $(uname) in
OS='OSX'
OS_ICON=$(print_icon 'APPLE_ICON')
;;
+ CYGWIN_NT-*)
+ OS='Windows'
+ OS_ICON=$(print_icon 'WINDOWS_ICON')
+ ;;
FreeBSD)
OS='BSD'
OS_ICON=$(print_icon 'FREEBSD_ICON')
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 3baa50ce..3c34f0bb 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -17,74 +17,57 @@
################################################################
## Turn on for Debugging
+#PS4='%s%f%b%k%F{blue}%{λ%}%L %F{240}%N:%i%(?.. %F{red}%?) %1(_.%F{yellow}%-1_ .)%s%f%b%k '
#zstyle ':vcs_info:*+*:*' debug true
#set -o xtrace
# Try to set the installation path
-if [[ -n "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
- # If an installation path was set manually,
- # it should trump any other location found.
- # Do nothing. This is all right, as we use the
- # POWERLEVEL9K_INSTALLATION_PATH for further processing.
-elif [[ $(whence -w prompt_powerlevel9k_setup) =~ "function" ]]; then
- # Check if the theme was called as a function (e.g., from prezto)
- autoload -U is-at-least
- if is-at-least 5.0.8; then
- # Try to find the correct path of the script.
- POWERLEVEL9K_INSTALLATION_PATH=$(whence -v $0 | sed "s/$0 is a shell function from //")
- elif [[ -f "${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/init.zsh" ]]; then
- # If there is an prezto installation, we assume that powerlevel9k is linked there.
- POWERLEVEL9K_INSTALLATION_PATH="${ZDOTDIR:-$HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup"
- fi
-else
- # Last resort: Set installation path is script path
- POWERLEVEL9K_INSTALLATION_PATH="$0"
-fi
-
-# Resolve the installation path
-if [[ -L "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
- # If this theme is sourced as a symlink, we need to locate the real URL
- filename="${POWERLEVEL9K_INSTALLATION_PATH:A}"
-elif [[ -d "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
- # Directory
- filename="${POWERLEVEL9K_INSTALLATION_PATH}/powerlevel9k.zsh-theme"
-elif [[ -f "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
- # Script is a file
- filename="$POWERLEVEL9K_INSTALLATION_PATH"
-elif [[ -z "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
- # Fallback: specify an installation path!
- print -P "%F{red}We could not locate the installation path of powerlevel9k.%f"
- print -P "Please specify by setting %F{blue}POWERLEVEL9K_INSTALLATION_PATH%f (full path incl. file name) at the very beginning of your ~/.zshrc"
- return 1
+if [[ -n "$POWERLEVEL9K_INSTALLATION_DIR" ]]; then
+ p9k_directory=${POWERLEVEL9K_INSTALLATION_DIR:A}
else
- print -P "%F{red}Script location could not be found! Maybe your %F{blue}POWERLEVEL9K_INSTALLATION_PATH%F{red} is not correct?%f"
- return 1
+ if [[ "${(%):-%N}" == '(eval)' ]]; then
+ if [[ "$0" == '-antigen-load' ]] && [[ -r "${PWD}/powerlevel9k.zsh-theme" ]]; then
+ # Antigen uses eval to load things so it can change the plugin (!!)
+ # https://github.com/zsh-users/antigen/issues/581
+ p9k_directory=$PWD
+ else
+ print -P "%F{red}You must set POWERLEVEL9K_INSTALLATION_DIR work from within an (eval).%f"
+ return 1
+ fi
+ else
+ # Get the path to file this code is executing in; then
+ # get the absolute path and strip the filename.
+ # See https://stackoverflow.com/a/28336473/108857
+ p9k_directory=${${(%):-%x}:A:h}
+ fi
fi
-script_location="$(dirname $filename)"
################################################################
# Source icon functions
################################################################
-source $script_location/functions/icons.zsh
+source "${p9k_directory}/functions/icons.zsh"
################################################################
# Source utility functions
################################################################
-source $script_location/functions/utilities.zsh
+source "${p9k_directory}/functions/utilities.zsh"
################################################################
# Source color functions
################################################################
-source $script_location/functions/colors.zsh
+source "${p9k_directory}/functions/colors.zsh"
################################################################
# Source VCS_INFO hooks / helper functions
################################################################
-source $script_location/functions/vcs.zsh
+source "${p9k_directory}/functions/vcs.zsh"
+
+# cleanup temporary variables.
+unset p9k_directory
################################################################
# Color Scheme
@@ -337,6 +320,23 @@ prompt_background_jobs() {
fi
}
+# A newline in your prompt, so you can segments on multiple lines.
+prompt_newline() {
+ local lws newline
+ [[ "$1" == "right" ]] && return
+ newline=$'\n'
+ lws=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS
+ if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then
+ newline="${newline}$(print_icon 'MULTILINE_NEWLINE_PROMPT_PREFIX')"
+ fi
+ POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=
+ "$1_prompt_segment" \
+ "$0" \
+ "$2" \
+ "NONE" "NONE" "${newline}"
+ POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws
+}
+
# Segment that indicates usage level of current partition.
set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false
set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
@@ -468,9 +468,24 @@ prompt_battery() {
message="$bat_percent%%"
fi
- # Draw the prompt_segment
- if [[ -n $bat_percent ]]; then
- "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON'
+ # override default icon if we are using battery stages
+ if [[ -n "$POWERLEVEL9K_BATTERY_STAGES" ]]; then
+ local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_STAGES} - 1 ) ))
+ if [[ $segment > 1 ]]; then
+ local offset=$(( ($bat_percent / $segment) + 1 ))
+ # check if the stages are in an array or a string
+ [[ "${(t)POWERLEVEL9K_BATTERY_STAGES}" =~ "array" ]] && POWERLEVEL9K_BATTERY_ICON="$POWERLEVEL9K_BATTERY_STAGES[$offset]" || POWERLEVEL9K_BATTERY_ICON=${POWERLEVEL9K_BATTERY_STAGES:$offset:1}
+ fi
+ fi
+
+ # override the default color if we are using a color level array
+ if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then
+ local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) ))
+ local offset=$(( ($bat_percent / $segment) + 1 ))
+ "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON"
+ else
+ # Draw the prompt_segment
+ "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON"
fi
}
@@ -572,6 +587,61 @@ prompt_context() {
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
}
+################################################################
+# User: user (who am I)
+# Note that if $DEFAULT_USER is not set, this prompt segment will always print
+set_default POWERLEVEL9K_USER_TEMPLATE "%n"
+prompt_user() {
+ local current_state="DEFAULT"
+ typeset -AH user_state
+ if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]]; then
+ if [[ $(print -P "%#") == '#' ]]; then
+ user_state=(
+ "STATE" "ROOT"
+ "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}"
+ "BACKGROUND_COLOR" "${DEFAULT_COLOR}"
+ "FOREGROUND_COLOR" "yellow"
+ "VISUAL_IDENTIFIER" "ROOT_ICON"
+ )
+ else
+ user_state=(
+ "STATE" "DEFAULT"
+ "CONTENT" "$USER"
+ "BACKGROUND_COLOR" "${DEFAULT_COLOR}"
+ "FOREGROUND_COLOR" "011"
+ "VISUAL_IDENTIFIER" "USER_ICON"
+ )
+ fi
+ "$1_prompt_segment" "${0}_${user_state[STATE]}" "$2" "${user_state[BACKGROUND_COLOR]}" "${user_state[FOREGROUND_COLOR]}" "${user_state[CONTENT]}" "${user_state[VISUAL_IDENTIFIER]}"
+ fi
+}
+
+################################################################
+# Host: machine (where am I)
+set_default POWERLEVEL9K_HOST_TEMPLATE "%m"
+prompt_host() {
+ local current_state="LOCAL"
+ typeset -AH host_state
+ if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then
+ host_state=(
+ "STATE" "REMOTE"
+ "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}"
+ "BACKGROUND_COLOR" "${DEFAULT_COLOR}"
+ "FOREGROUND_COLOR" "yellow"
+ "VISUAL_IDENTIFIER" "SSH_ICON"
+ )
+ else
+ host_state=(
+ "STATE" "LOCAL"
+ "CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}"
+ "BACKGROUND_COLOR" "${DEFAULT_COLOR}"
+ "FOREGROUND_COLOR" "011"
+ "VISUAL_IDENTIFIER" "HOST_ICON"
+ )
+ fi
+ "$1_prompt_segment" "$0_${host_state[STATE]}" "$2" "${host_state[BACKGROUND_COLOR]}" "${host_state[FOREGROUND_COLOR]}" "${host_state[CONTENT]}" "${host_state[VISUAL_IDENTIFIER]}"
+}
+
# The 'custom` prompt provides a way for users to invoke commands and display
# the output in a segment.
prompt_custom() {
@@ -619,6 +689,7 @@ prompt_command_execution_time() {
# Dir: current working directory
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
+set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false
prompt_dir() {
local current_path="$(print -P "%~")"
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then
@@ -745,7 +816,7 @@ prompt_dir() {
fi
if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" ]]; then
- current_path="$( echo "${current_path}" | sed "s/^~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/")"
+ current_path=${current_path/#\~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}}
fi
typeset -AH dir_states
@@ -753,9 +824,12 @@ prompt_dir() {
"DEFAULT" "FOLDER_ICON"
"HOME" "HOME_ICON"
"HOME_SUBFOLDER" "HOME_SUB_ICON"
+ "NOT_WRITABLE" "LOCK_ICON"
)
local current_state="DEFAULT"
- if [[ $(print -P "%~") == '~' ]]; then
+ if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then
+ current_state="NOT_WRITABLE"
+ elif [[ $(print -P "%~") == '~' ]]; then
current_state="HOME"
elif [[ $(print -P "%~") == '~'* ]]; then
current_state="HOME_SUBFOLDER"
@@ -798,12 +872,12 @@ prompt_detect_virt() {
if [[ "$virt" == "none" ]]; then
if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then
virt="chroot"
- "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$virt"
+ "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
else
;
fi
else
- "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$virt"
+ "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
fi
}
@@ -848,6 +922,16 @@ prompt_ip() {
"$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON'
}
+set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun"
+# prompt if vpn active
+prompt_vpn_ip() {
+ for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_VPN_IP_INTERFACE" | cut -d":" -f1)
+ do
+ ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2)
+ "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON'
+ done
+}
+
prompt_load() {
# The load segment can have three different states
local current_state="unknown"
@@ -897,13 +981,16 @@ prompt_node_version() {
# Node version from NVM
# Only prints the segment if different than the default value
prompt_nvm() {
- [[ ! $(type nvm) =~ 'nvm is a shell function'* ]] && return
- local node_version=$(nvm current)
- [[ -z "${node_version}" ]] || [[ ${node_version} = "none" ]] && return
- local nvm_default=$(cat $NVM_DIR/alias/default)
+ local node_version nvm_default
+ (( $+functions[nvm_version] )) || return
+
+ node_version=$(nvm_version current)
+ [[ -z "${node_version}" || ${node_version} == "none" ]] && return
+
+ nvm_default=$(nvm_version default)
[[ "$node_version" =~ "$nvm_default" ]] && return
- $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON'
+ $1_prompt_segment "$0" "$2" "magenta" "black" "${node_version:1}" 'NODE_ICON'
}
# NodeEnv Prompt
@@ -1008,13 +1095,10 @@ prompt_rspec_stats() {
# Ruby Version Manager information
prompt_rvm() {
- local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
- [ "$gemset" != "" ] && gemset="@$gemset"
-
- local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $NF}')
+ local version_and_gemset=${rvm_env_string/ruby-}
- if [[ -n "$version$gemset" ]]; then
- "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version$gemset" 'RUBY_ICON'
+ if [[ -n "$version_and_gemset" ]]; then
+ "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON'
fi
}
@@ -1024,17 +1108,57 @@ prompt_ssh() {
fi
}
-# Status: return code if verbose, otherwise just an icon if an error occurred
+# Status: When an error occur, return the error code, or a cross icon if option is set
+# Display an ok icon when no error occur, or hide the segment if option is set to false
+#
+set_default POWERLEVEL9K_STATUS_CROSS false
+set_default POWERLEVEL9K_STATUS_OK true
+set_default POWERLEVEL9K_STATUS_SHOW_PIPESTATUS true
+set_default POWERLEVEL9K_STATUS_HIDE_SIGNAME false
+# old options, retro compatibility
set_default POWERLEVEL9K_STATUS_VERBOSE true
set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false
+
+exit_code_or_status() {
+ local ec=$1
+ if [[ "$POWERLEVEL9K_STATUS_HIDE_SIGNAME" = true ]]; then
+ echo "$ec"
+ elif (( ec <= 128 )); then
+ echo "$ec"
+ else
+ local sig=$(( ec - 128 ))
+ local idx=$(( sig + 1 ))
+ echo "${signals[$idx]}(-${sig})"
+ fi
+}
+
prompt_status() {
- if [[ "$RETVAL" -ne 0 ]]; then
- if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then
- "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL" 'CARRIAGE_RETURN_ICON'
+ local ec_text
+ local ec_sum
+ local ec
+
+ if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then
+ ec_text=$(exit_code_or_status "${RETVALS[1]}")
+ ec_sum=${RETVALS[1]}
+
+ for ec in "${(@)RETVALS[2,-1]}"; do
+ ec_text="${ec_text}|$(exit_code_or_status "$ec")"
+ ec_sum=$(( $ec_sum + $ec ))
+ done
+ else
+ # We use RETVAL instead of the right-most RETVALS item because
+ # PIPE_FAIL may be set.
+ ec_text=$(exit_code_or_status "${RETVAL}")
+ ec_sum=${RETVAL}
+ fi
+
+ if (( ec_sum > 0 )); then
+ if [[ "$POWERLEVEL9K_STATUS_CROSS" == false && "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then
+ "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$ec_text" 'CARRIAGE_RETURN_ICON'
else
"$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON'
fi
- elif [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then
+ elif [[ "$POWERLEVEL9K_STATUS_OK" == true ]] && [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then
"$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "green" "" 'OK_ICON'
fi
}
@@ -1264,6 +1388,24 @@ prompt_dir_writable() {
fi
}
+# Kubernetes Current Context
+prompt_kubecontext() {
+ local kubectl_version=$(kubectl version --client 2>/dev/null)
+
+ if [[ -n "$kubectl_version" ]]; then
+ # Get the current Kubernetes config context's namespaece
+ local k8s_namespace=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}')
+ # Get the current Kuberenetes context
+ local k8s_context=$(kubectl config current-context)
+
+ if [[ -z "$k8s_namespace" ]]; then
+ k8s_namespace="default"
+ fi
+ "$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_context/$k8s_namespace" "KUBERNETES_ICON"
+ fi
+}
+
+
################################################################
# Prompt processing and drawing
################################################################
@@ -1314,15 +1456,16 @@ powerlevel9k_preexec() {
set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false
powerlevel9k_prepare_prompts() {
RETVAL=$?
+ RETVALS=( "$pipestatus[@]" )
_P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START))
# Reset start time
- _P9K_TIMER_START=0xFFFFFFFF
+ _P9K_TIMER_START=0x7FFFFFFF
if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then
PROMPT='$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt)
-$(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')'
+$(print_icon 'MULTILINE_LAST_PROMPT_PREFIX')'
if [[ "$POWERLEVEL9K_RPROMPT_ON_NEWLINE" != true ]]; then
# The right prompt should be on the same line as the first line of the left
# prompt. To do so, there is just a quite ugly workaround: Before zsh draws
@@ -1351,22 +1494,22 @@ NEWLINE='
}
prompt_powerlevel9k_setup() {
- # I decided to use the value below for better supporting 32-bit CPUs, since the previous value "99999999999" was causing issues on my Android phone, which is powered by an armv7l
- # We don't have to change that until 19 January of 2038! :)
+ # The value below was set to better support 32-bit CPUs.
+ # It's the maximum _signed_ integer value on 32-bit CPUs.
+ # Please don't change it until 19 January of 2038. ;)
# Disable false display of command execution time
- # Maximum integer on 32-bit CPUs
- _P9K_TIMER_START=2147483647
+ _P9K_TIMER_START=0x7FFFFFFF
# The prompt function will set these prompt_* options after the setup function
# returns. We need prompt_subst so we can safely run commands in the prompt
# without them being double expanded and we need prompt_percent to expand the
# common percent escape sequences.
- prompt_opts=(subst percent cr)
+ prompt_opts=(cr percent sp subst)
# Borrowed from promptinit, sets the prompt options in case the theme was
# not initialized via promptinit.
- setopt noprompt{bang,cr,percent,subst} "prompt${^prompt_opts[@]}"
+ setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}"
# Display a warning if the terminal does not support 256 colors
local term_colors
@@ -1420,4 +1563,11 @@ prompt_powerlevel9k_setup() {
add-zsh-hook preexec powerlevel9k_preexec
}
+prompt_powerlevel9k_teardown() {
+ add-zsh-hook -D precmd powerlevel9k_\*
+ add-zsh-hook -D preexec powerlevel9k_\*
+ PROMPT='%m%# '
+ RPROMPT=
+}
+
prompt_powerlevel9k_setup "$@"
diff --git a/test-in-docker b/test-in-docker
new file mode 100755
index 00000000..3c7255ec
--- /dev/null
+++ b/test-in-docker
@@ -0,0 +1,179 @@
+#!/usr/bin/env zsh
+
+set -eu
+
+# The default ZSH to use.
+default_version='4.3.11'
+
+setopt extended_glob glob_subst numeric_glob_sort
+cd "${${(%):-%x}:A:h}"
+
+# TODO: Crazy Logic to munge TERM to something supported in Ubuntu 14.04
+term=screen-256color
+
+# Note: If versions and frameworks looks complicated, it isn't that bad...
+# ...see Modifiers in zshexpn(1) for details.
+
+# List of ZSH versions
+typeset -a versions
+versions=( docker/base-*/Dockerfile(N.on:h:t:s/base-//) )
+
+# List of frameworks
+typeset -a frameworks
+frameworks=( docker/*/Dockerfile(N.on:h:t) )
+frameworks=${(@)frameworks:#base-*}
+
+# Known Issues
+typeset -A known_issues
+known_issues["4.3.11-antigen"]="Antigen commands that need git won't work; it needs a newer version of git."
+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."
+
+err()
+{
+ print -P "%F{red}Error:%f $*"
+ exit 2
+}
+
+resolve_framework() {
+ local f=$1 found
+ found=${frameworks[(In:-1:)$f*]}
+ if (( found <= $#frameworks )); then
+ echo "${frameworks[$found]}"
+ fi
+}
+
+resolve_version() {
+ local v=$1 found
+ found=${versions[(In:-1:)$v*]}
+ if (( found <= $#versions )); then
+ echo "${versions[$found]}"
+ fi
+}
+
+check_for_known_issues() {
+ local version="$1"
+ local framework="$2"
+ local name="${version}-${framework}"
+
+ if (( ${+known_issues["$name"]} )); then
+ echo
+ print -P "%F{red}Known Issue: %F{yellow}${known_issues["$name"]}%f"
+ echo
+ fi
+}
+
+build_and_run() {
+ local version="$1"
+ local framework="$2"
+ local name="${version}-${framework}"
+
+ check_for_known_issues "$version" "$framework"
+
+ print -P "%F{green}Preparing containers...%f"
+
+ echo -n "p9k:base-${version}: "
+ docker build \
+ --quiet \
+ --tag "p9k:base-${version}" \
+ --file "docker/base-${version}/Dockerfile" \
+ .
+
+ echo -n "p9k:${version}-${framework}: "
+ docker build \
+ --quiet \
+ --build-arg="base=base-${version}" \
+ --tag "p9k:${version}-${framework}" \
+ --file "docker/${framework}/Dockerfile" \
+ .
+
+ print -P "%F{green}Starting ${name} container...%f"
+ exec docker run \
+ --rm \
+ --interactive \
+ --tty \
+ --hostname="${name//./_}" \
+ --env="TERM=${term}" \
+ "p9k:${version}-${framework}"
+}
+
+show_help() {
+ local f v
+ echo "Usage: ${(%):-%x} <framework>|--list"
+ 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 " --help You're soaking in it."
+ echo
+ echo "ZSH versions:"
+ for v in "${(@)versions}"; do
+ echo " $v"
+ done
+ echo
+ echo "Framework containers:"
+ for f in "${(@)frameworks}"; do
+ echo " $f"
+ done
+}
+
+# No arguments
+if (( $# == 0 )); then
+ show_help
+ exit
+fi
+
+# Parse flags and such.
+use_version=$default_version
+use_framework=
+while (( $# > 0 )); do
+ case "$1" in
+ -f | --frameworks )
+ print -l "${(@)frameworks}"
+ exit
+ ;;
+ -v | --versions )
+ print -l "${(@)versions}"
+ exit
+ ;;
+ -z | --zsh )
+ shift
+ local v="$(resolve_version "$1")"
+ if [[ -n "$v" ]]; then
+ use_version=$v
+ else
+ err "No such ZSH version '${1}'"
+ fi
+ ;;
+ -h | --help )
+ show_help
+ exit
+ ;;;
+ -* )
+ err "Unknown option ${1}"
+ show_help
+ 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
+ else
+ err "You can only specify one framework at a time; you already specified '${use_framework}'"
+ fi
+ ;;
+ esac
+ shift
+done
+
+build_and_run "$use_version" "$use_framework"
+
+# EOF
diff --git a/test/segments/dir.spec b/test/segments/dir.spec
index dea54750..ef27e160 100755
--- a/test/segments/dir.spec
+++ b/test/segments/dir.spec
@@ -292,6 +292,31 @@ function testChangingDirPathSeparator() {
unset POWERLEVEL9K_DIR_PATH_SEPARATOR
}
+function testHomeFolderAbbreviation() {
+ local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION
+ local dir=$PWD
+
+ cd ~/
+ # default
+ POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~'
+ assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)"
+
+ # substituted
+ POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq'
+ assertEquals "%K{blue} %F{black}qQq %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd /tmp
+ # default
+ POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~'
+ assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)"
+
+ # substituted
+ POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq'
+ 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'
diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec
new file mode 100755
index 00000000..eaaa2300
--- /dev/null
+++ b/test/segments/kubecontext.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"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function mockKubectl() {
+ case "$1" in
+ 'version')
+ echo 'non-empty text'
+ ;;
+ 'config')
+ case "$2" in
+ 'current-context')
+ echo 'minikube'
+ ;;
+ 'get-contexts')
+ echo '* minikube minikube minikube '
+ ;;
+ esac
+ ;;
+ esac
+}
+
+function mockKubectlOtherNamespace() {
+ case "$1" in
+ 'version')
+ echo 'non-empty text'
+ ;;
+ 'config')
+ case "$2" in
+ 'current-context')
+ echo 'minikube'
+ ;;
+ 'get-contexts')
+ echo '* minikube minikube minikube kube-system'
+ ;;
+ esac
+ ;;
+ esac
+}
+
+function testKubeContext() {
+ alias kubectl=mockKubectl
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
+
+ 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
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
+
+ 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'
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext)
+
+ 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