Merge branch 'master' into chruby_options

pull/22/head
Dan 7 years ago committed by GitHub
commit fbb85e77e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -1 +1,2 @@
test-vm/.vagrant test-vm/.vagrant
*.swp

@ -28,3 +28,4 @@ script:
- test/segments/rust_version.spec - test/segments/rust_version.spec
- test/segments/go_version.spec - test/segments/go_version.spec
- test/segments/vcs.spec - test/segments/vcs.spec
- test/segments/kubecontext.spec

@ -1,3 +1,42 @@
## v0.6.4
- `load` segment now has configurable averages.
- Update to `dir` segment to add `dir_writable` feature.
- `status` segment can now display POSIX signal name of exit code.
- 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.
- Fixed issue with visual artifacts with quick consecutive commands.
- Updated 'ananconda' segment for more uniform styling.
- `rvm` segment can now support usernames with dashes.
- Fixed Python icon reference in some font configurations.
- Vi mode indicator fixed.
- Fixes for Docker segment.
- Added new Docker-based testing system.
- Significant enhancements to the `battery` segment. Check out the README to
read more!
- New truncation strategy that truncates until the path becomes unique.
### 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.3 ## v0.6.3
- Fixed susceptibility to [pw3nage exploit](https://github.com/njhartwell/pw3nage). - Fixed susceptibility to [pw3nage exploit](https://github.com/njhartwell/pw3nage).
@ -26,6 +65,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. 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 ## v0.6.0
- Fixed a bug where the tag display was broken on detached HEADs. - Fixed a bug where the tag display was broken on detached HEADs.

@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at bhilburn@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

@ -1,6 +1,6 @@
![](https://raw.githubusercontent.com/bhilburn/powerlevel9k-logo/master/logo-banner.png) ![](https://raw.githubusercontent.com/bhilburn/powerlevel9k-logo/master/logo-banner.png)
--- ---
[![Build Status](https://travis-ci.org/bhilburn/powerlevel9k.svg?branch=next)](https://travis-ci.org/bhilburn/powerlevel9k) [![Build Status](https://travis-ci.org/bhilburn/powerlevel9k.svg?branch=master)](https://travis-ci.org/bhilburn/powerlevel9k)
[![Join the chat at https://gitter.im/bhilburn/powerlevel9k](https://badges.gitter.im/bhilburn/powerlevel9k.svg)](https://gitter.im/bhilburn/powerlevel9k?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/bhilburn/powerlevel9k](https://badges.gitter.im/bhilburn/powerlevel9k.svg)](https://gitter.im/bhilburn/powerlevel9k?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Powerlevel9k is a theme for ZSH which uses [Powerline Powerlevel9k is a theme for ZSH which uses [Powerline
@ -92,15 +92,18 @@ The segments that are currently available are:
* `dir_writable` - Displays a lock icon, if you do not have write permissions on the current folder. * `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. * [`disk_usage`](#disk_usage) - Disk usage of your current partition.
* `history` - The command number for the current line. * `history` - The command number for the current line.
* [`host`](#host) - Your current host name
* [`ip`](#ip) - Shows the current IP address. * [`ip`](#ip) - Shows the current IP address.
* [`vpn_ip`](#vpn_ip) - Shows the current VPN IP address.
* [`public_ip`](#public_ip) - Shows your public IP address. * [`public_ip`](#public_ip) - Shows your public IP address.
* `load` - Your machine's load averages. * [`load`](#load) - Your machine's load averages.
* `os_icon` - Display a nice little icon, depending on your operating system. * `os_icon` - Display a nice little icon, depending on your operating system.
* `ram` - Show free RAM. * `ram` - Show free RAM.
* `root_indicator` - An indicator if the user has superuser status. * `root_indicator` - An indicator if the user has superuser status.
* [`status`](#status) - The return code of the previous command. * [`status`](#status) - The return code of the previous command.
* `swap` - Prints the current swap size. * `swap` - Prints the current swap size.
* [`time`](#time) - System time. * [`time`](#time) - System time.
* [`user`](#user) - Your current username
* [`vi_mode`](#vi_mode)- Your prompt's Vi editing mode (NORMAL|INSERT). * [`vi_mode`](#vi_mode)- Your prompt's Vi editing mode (NORMAL|INSERT).
* `ssh` - Indicates whether or not you are in an SSH session. * `ssh` - Indicates whether or not you are in an SSH session.
@ -126,6 +129,7 @@ The segments that are currently available are:
* [`chruby`](#chruby) - Ruby environment information using `chruby` (if one is active). * [`chruby`](#chruby) - Ruby environment information using `chruby` (if one is active).
* [`rbenv`](#rbenv) - Ruby environment information using `rbenv` (if one is active). * [`rbenv`](#rbenv) - Ruby environment information using `rbenv` (if one is active).
* [`rspec_stats`](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. * [`rspec_stats`](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec.
* `rvm` - Ruby environment information using `$GEM_HOME` and `$MY_RUBY_HOME` (if one is active).
* **Rust Segments:** * **Rust Segments:**
* `rust_version` - Display the current rust version and [logo](https://www.rust-lang.org/logos/rust-logo-blk.svg). * `rust_version` - Display the current rust version and [logo](https://www.rust-lang.org/logos/rust-logo-blk.svg).
* **Swift Segments:** * **Swift Segments:**
@ -136,6 +140,7 @@ The segments that are currently available are:
* [`aws`](#aws) - The current AWS profile, if active. * [`aws`](#aws) - The current AWS profile, if active.
* `aws_eb_env` - The current Elastic Beanstalk Environment. * `aws_eb_env` - The current Elastic Beanstalk Environment.
* `docker_machine` - The current Docker Machine. * `docker_machine` - The current Docker Machine.
* `kubecontext` - The current context of your `kubectl` configuration.
**Other:** **Other:**
* [`custom_command`](#custom_command) - Create a custom segment to display the * [`custom_command`](#custom_command) - Create a custom segment to display the
@ -143,6 +148,7 @@ The segments that are currently available are:
* [`command_execution_time`](#command_execution_time) - Display the time the current command took to execute. * [`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. * [`todo`](http://todotxt.com/) - Shows the number of tasks in your todo.txt tasks file.
* `detect_virt` - Virtualization detection with systemd * `detect_virt` - Virtualization detection with systemd
* `newline` - Continues the prompt on a new line.
--------------------------------------------------------------------------------- ---------------------------------------------------------------------------------
@ -184,9 +190,8 @@ your `~/.zshrc`:
##### battery ##### battery
This segment will display your current battery status (fails gracefully on 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 systems without a battery). It is supported on both OSX and Linux (note that it requires `acpi` on Linux).
requires `acpi` on Linux).
| Variable | Default Value | Description | | Variable | Default Value | Description |
|----------|---------------|-------------| |----------|---------------|-------------|
@ -201,6 +206,60 @@ Note that you can [modify the `_FOREGROUND`
color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization) color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)
without affecting the icon color. 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)` |
##### chruby ##### chruby
This segment shows the version of Ruby being used when using `chruby` to change your current Ruby stack. This segment shows the version of Ruby being used when using `chruby` to change your current Ruby stack.
@ -272,13 +331,13 @@ 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 You can customize the `context` segment. For example, you can make it to print the
full hostname by setting full hostname by setting
``` ```
POWERLEVEL9K_CONTEXT_TEMPLATE="%n@`hostname -f`" POWERLEVEL9K_CONTEXT_TEMPLATE="%n@`hostname -f`"
``` ```
You can set the `POWERLEVEL9K_CONTEXT_HOST_DEPTH` variable to change how the 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] 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 . 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 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 hostname. Setting N to a negative integer will show that many segments from the
@ -320,10 +379,11 @@ Customizations available are:
| Strategy Name | Description | | Strategy Name | Description |
|---------------|-------------| |---------------|-------------|
|Default|Truncate whole directories from left. How many is defined by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`| |Default|Truncate whole directories from left. How many is defined by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`|
|`truncate_middle`|Truncates the middle part of a folder. E.g. you are in a folder named "~/MySuperProjects/AwesomeFiles/BoringOffice", then it will truncated to "~/MyS..cts/Awe..les/BoringOffice", if `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3` is also set (controls the amount of characters to be left).| |`truncate_middle`|Truncates the middle part of a folder. E.g. you are in a folder named `~/MySuperProjects/AwesomeFiles/BoringOffice`, then it will truncated to `~/MyS..cts/Awe..les/BoringOffice`, if `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3` is also set (controls the amount of characters to be left).|
|`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.| |`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.|
|`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.| |`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.|
|`truncate_with_folder_marker`|Search for a file that is specified by `POWERLEVEL9K_SHORTEN_FOLDER_MARKER` and truncate everything before that (if found, otherwise stop on $HOME and ROOT).| |`truncate_with_folder_marker`|Search for a file that is specified by `POWERLEVEL9K_SHORTEN_FOLDER_MARKER` and truncate everything before that (if found, otherwise stop on $HOME and ROOT).|
|`truncate_to_unique`|Parse all parent path components and truncate them to the shortest unique length. If you copy & paste the result to a shell, after hitting `TAB` it should expand to the original path unambiguously.|
For example, if you wanted the truncation behavior of the `fish` shell, which For example, if you wanted the truncation behavior of the `fish` shell, which
truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following:
@ -359,7 +419,11 @@ You can also customize the leading tilde character when you are in `$HOME` using
# Double quotes are important here! # Double quotes are important here!
POWERLEVEL9K_HOME_FOLDER_ABBREVIATION="%F{red} $(print_icon 'HOME_ICON') %F{black}" 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 ##### disk_usage
@ -371,6 +435,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_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.| |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 ##### ip
This segment tries to examine all currently used network interfaces and prints This segment tries to examine all currently used network interfaces and prints
@ -381,6 +467,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`.| |`POWERLEVEL9K_IP_INTERFACE`|None|The NIC for which you wish to display the IP address. Example: `eth0`.|
##### vpn_ip
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 ##### public_ip
This segment will display your public IP address. There are several methods of obtaining this This segment will display your public IP address. There are several methods of obtaining this
@ -404,6 +498,26 @@ 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_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| |`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained|
##### load
Displays one of your load averages with appropriate state coloring. The thresholds are:
- `0.7 * NUM_CORES <`: critical
- `0.5 * NUM_CORES <`: warning
- `less`: normal
| Variable | Default Value | Description |
|----------|---------------|-------------|
|`POWERLEVEL9K_LOAD_WHICH`|5|Which average to show. Possible values: 1, 5 or 15|
##### 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 ##### rbenv
This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack. This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack.
@ -413,6 +527,10 @@ It figures out the version being used by taking the output of the `rbenv version
* If `rbenv` is not in $PATH, nothing will be shown. * If `rbenv` is not in $PATH, nothing will be shown.
* If the current Ruby version is the same as the global Ruby version, nothing will be shown. * If the current Ruby version is the same as the global Ruby version, nothing will be shown.
| Variable | Default Value | Description |
|----------|---------------|-------------|
|`POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW`|`false`|Set to true if you wish to show the rbenv segment even if the current Ruby version is the same as the global Ruby version|
##### rspec_stats ##### rspec_stats
See [Unit Test Ratios](#unit-test-ratios), below. See [Unit Test Ratios](#unit-test-ratios), below.
@ -423,8 +541,10 @@ This segment shows the return code of the last command.
| Variable | Default Value | Description | | 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_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_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_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 ##### ram
@ -453,6 +573,23 @@ segment, as well:
# Output time, date, and a symbol from the "Awesome Powerline Font" set # Output time, date, and a symbol from the "Awesome Powerline Font" set
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}" 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 ##### vcs
By default, the `vcs` segment will provide quite a bit of information. Further By default, the `vcs` segment will provide quite a bit of information. Further
@ -465,6 +602,10 @@ customization is provided via:
|`POWERLEVEL9K_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.| |`POWERLEVEL9K_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.|
|`POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY`|`true`|Set to `false` to not reflect submodule status in the top-level repository prompt.| |`POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY`|`true`|Set to `false` to not reflect submodule status in the top-level repository prompt.|
|`POWERLEVEL9K_VCS_HIDE_TAGS`|`false`|Set to `true` to stop tags being displayed in the segment.| |`POWERLEVEL9K_VCS_HIDE_TAGS`|`false`|Set to `true` to stop tags being displayed in the segment.|
|`POWERLEVEL9K_VCS_GIT_HOOKS`|`(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname)`|Layout of the segment for git repositories.|
|`POWERLEVEL9K_VCS_HG_HOOKS`|`(vcs-detect-changes)`|Layout of the segment for Mercurial repositories.|
|`POWERLEVEL9K_VCS_SVN_HOOKS`|`(vcs-detect-changes svn-detect-changes)`|Layout of the segment for SVN repositories.|
|`POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND`|`red`|The color of the foreground font during actions (e.g., `REBASE`).|
##### vcs symbols ##### vcs symbols
@ -509,6 +650,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 Just enough to give you a quick overview about the test situation of the project
you are dealing with. 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 ### tl; dr
Want to just get a quick start? Check out the [Show Off Your Want to just get a quick start? Check out the [Show Off Your

@ -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 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`. 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 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 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! 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). For how to run the machines see [here](test-vm/README.md).

@ -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

@ -0,0 +1 @@
curl -sL https://git.io/antibody | bash -s

@ -0,0 +1,2 @@
source <(antibody init)
antibody bundle ~/p9k/

@ -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

@ -0,0 +1,12 @@
#!/bin/zsh
mkdir ~/antigen
curl \
-qLsSf \
-o ~/antigen/antigen.zsh \
https://git.io/antigen
source ~/antigen/antigen.zsh
# EOF

@ -0,0 +1,4 @@
source ~/antigen/antigen.zsh
antigen theme "${HOME}/p9k" powerlevel9k --no-local-clone
antigen apply

@ -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"]

@ -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"]

@ -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"]

@ -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"]

@ -0,0 +1,5 @@
ARG base
FROM p9k:${base}
COPY ./ p9k/
COPY docker/dotfile/zshrc .zshrc

@ -0,0 +1 @@
source "${HOME}/p9k/prompt_powerlevel9k_setup"

@ -0,0 +1,2 @@
Defaults:fred !requiretty
fred ALL=(ALL) NOPASSWD: ALL

@ -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/

@ -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

@ -0,0 +1,5 @@
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="powerlevel9k/powerlevel9k"
plugins=(git rake ruby)
source $ZSH/oh-my-zsh.sh

@ -0,0 +1,7 @@
ARG base
FROM p9k:${base}
COPY docker/prezto/install.zsh /tmp/
RUN zsh /tmp/install.zsh
COPY ./ p9k/

@ -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

@ -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

@ -0,0 +1,5 @@
#!/bin/zsh
git clone https://github.com/tarjoilija/zgen.git "${HOME}/.zgen"
# EOF

@ -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

@ -0,0 +1,7 @@
ARG base
FROM p9k:${base}
COPY docker/zim/install.zsh /tmp/
RUN zsh /tmp/install.zsh
COPY ./ p9k/

@ -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

@ -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

@ -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"

@ -0,0 +1,5 @@
#!zsh
source ~/.zplug/init.zsh
zplug "${HOME}/p9k", use:"powerlevel9k.zsh-theme", from:local, as:theme
zplug load --verbose

@ -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

@ -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

@ -0,0 +1,5 @@
#!zsh
zplugin load psprint zsh-navigation-tools
zplugin load psprint---zprompts
zplugin snippet ~/p9k/powerlevel9k.zsh-theme

@ -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

@ -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

@ -0,0 +1,3 @@
source ~/.zpm/zpm.zsh
zpm load powerlevel9k

@ -0,0 +1,7 @@
ARG base
FROM p9k:${base}
COPY docker/zulu/install.zsh /tmp/
RUN zsh /tmp/install.zsh
COPY ./ p9k/

@ -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

@ -35,13 +35,15 @@ case $POWERLEVEL9K_MODE in
TODO_ICON $'\u2611' # ☑ TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\uE894' #  BATTERY_ICON $'\uE894' # 
DISK_ICON $'\uE1AE ' #  DISK_ICON $'\uE1AE ' # 
OK_ICON $'\u2713' # ✓ OK_ICON $'\u2714' # ✔
FAIL_ICON $'\u2718' # ✘ FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF' SYMFONY_ICON 'SF'
NODE_ICON $'\u2B22' # ⬢ NODE_ICON $'\u2B22' # ⬢
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' 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 $'\uE26E' #  APPLE_ICON $'\uE26E' # 
WINDOWS_ICON $'\uE26F' # 
FREEBSD_ICON $'\U1F608 ' # 😈 FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE270' #  ANDROID_ICON $'\uE270' # 
LINUX_ICON $'\uE271' #  LINUX_ICON $'\uE271' # 
@ -67,7 +69,7 @@ case $POWERLEVEL9K_MODE in
VCS_TAG_ICON $'\uE817 ' #  VCS_TAG_ICON $'\uE817 ' # 
VCS_BOOKMARK_ICON $'\uE87B' #  VCS_BOOKMARK_ICON $'\uE87B' # 
VCS_COMMIT_ICON $'\uE821 ' #  VCS_COMMIT_ICON $'\uE821 ' # 
VCS_BRANCH_ICON $'\uE220' #  VCS_BRANCH_ICON $'\uE220 ' # 
VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_REMOTE_BRANCH_ICON $'\u2192' # →
VCS_GIT_ICON $'\uE20E ' #  VCS_GIT_ICON $'\uE20E ' # 
VCS_GIT_GITHUB_ICON $'\uE20E ' # VCS_GIT_GITHUB_ICON $'\uE20E ' #
@ -76,13 +78,15 @@ case $POWERLEVEL9K_MODE in
VCS_HG_ICON $'\uE1C3 ' #  VCS_HG_ICON $'\uE1C3 ' # 
VCS_SVN_ICON '(svn) ' VCS_SVN_ICON '(svn) '
RUST_ICON '' RUST_ICON ''
PYTHON_ICON $'\U1F40D' # 🐍 PYTHON_ICON $'\ue63c' # 
SWIFT_ICON '' SWIFT_ICON ''
GO_ICON '' GO_ICON ''
PUBLIC_IP_ICON '' PUBLIC_IP_ICON ''
LOCK_ICON $'\UE138' #  LOCK_ICON $'\UE138' # 
EXECUTION_TIME_ICON $'\UE89C' #  EXECUTION_TIME_ICON $'\UE89C' # 
SSH_ICON '(ssh)' SSH_ICON '(ssh)'
VPN_ICON '(vpn)'
KUBERNETES_ICON $'\U2388' # ⎈
) )
;; ;;
'awesome-fontconfig') 'awesome-fontconfig')
@ -106,13 +110,15 @@ case $POWERLEVEL9K_MODE in
TODO_ICON $'\u2611' # ☑ TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\U1F50B' # 🔋 BATTERY_ICON $'\U1F50B' # 🔋
DISK_ICON $'\uF0A0 ' #  DISK_ICON $'\uF0A0 ' # 
OK_ICON $'\u2713' # ✓ OK_ICON $'\u2714' # ✔
FAIL_ICON $'\u2718' # ✘ FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF' SYMFONY_ICON 'SF'
NODE_ICON $'\u2B22' # ⬢ NODE_ICON $'\u2B22' # ⬢
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ 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' #  APPLE_ICON $'\uF179' # 
WINDOWS_ICON $'\uF17A' # 
FREEBSD_ICON $'\U1F608 ' # 😈 FREEBSD_ICON $'\U1F608 ' # 😈
ANDROID_ICON $'\uE17B' #  ANDROID_ICON $'\uE17B' # 
LINUX_ICON $'\uF17C' #  LINUX_ICON $'\uF17C' # 
@ -134,7 +140,7 @@ case $POWERLEVEL9K_MODE in
VCS_TAG_ICON $'\uF217 ' #  VCS_TAG_ICON $'\uF217 ' # 
VCS_BOOKMARK_ICON $'\uF27B' #  VCS_BOOKMARK_ICON $'\uF27B' # 
VCS_COMMIT_ICON $'\uF221 ' #  VCS_COMMIT_ICON $'\uF221 ' # 
VCS_BRANCH_ICON $'\uF126' #  VCS_BRANCH_ICON $'\uF126 ' # 
VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_REMOTE_BRANCH_ICON $'\u2192' # →
VCS_GIT_ICON $'\uF1D3 ' #  VCS_GIT_ICON $'\uF1D3 ' # 
VCS_GIT_GITHUB_ICON $'\uF113 ' #  VCS_GIT_GITHUB_ICON $'\uF113 ' # 
@ -143,13 +149,15 @@ case $POWERLEVEL9K_MODE in
VCS_HG_ICON $'\uF0C3 ' #  VCS_HG_ICON $'\uF0C3 ' # 
VCS_SVN_ICON '(svn) ' VCS_SVN_ICON '(svn) '
RUST_ICON $'\uE6A8' #  RUST_ICON $'\uE6A8' # 
PYTHON_ICON $'\U1F40D' # 🐍 PYTHON_ICON $'\ue63c' # 
SWIFT_ICON '' SWIFT_ICON ''
GO_ICON '' GO_ICON ''
PUBLIC_IP_ICON '' PUBLIC_IP_ICON ''
LOCK_ICON $'\UE138' #  LOCK_ICON $'\UF023' # 
EXECUTION_TIME_ICON $'\uF253' EXECUTION_TIME_ICON $'\uF253'
SSH_ICON '(ssh)' SSH_ICON '(ssh)'
VPN_ICON $'\uF023'
KUBERNETES_ICON $'\U2388' # ⎈
) )
;; ;;
'nerdfont-complete'|'nerdfont-fontconfig') 'nerdfont-complete'|'nerdfont-fontconfig')
@ -178,8 +186,10 @@ case $POWERLEVEL9K_MODE in
SYMFONY_ICON $'\uE757' #  SYMFONY_ICON $'\uE757' # 
NODE_ICON $'\uE617 ' #  NODE_ICON $'\uE617 ' # 
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ 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' #  APPLE_ICON $'\uF179' # 
WINDOWS_ICON $'\uF17A' # 
FREEBSD_ICON $'\UF30E ' #  FREEBSD_ICON $'\UF30E ' # 
ANDROID_ICON $'\uF17B' #  ANDROID_ICON $'\uF17B' # 
LINUX_ICON $'\uF17C' #  LINUX_ICON $'\uF17C' # 
@ -217,6 +227,8 @@ case $POWERLEVEL9K_MODE in
LOCK_ICON $'\UF023' #  LOCK_ICON $'\UF023' # 
EXECUTION_TIME_ICON $'\uF252' #  EXECUTION_TIME_ICON $'\uF252' # 
SSH_ICON $'\uF489' #  SSH_ICON $'\uF489' # 
VPN_ICON '(vpn)'
KUBERNETES_ICON $'\U2388' # ⎈
) )
;; ;;
*) *)
@ -240,13 +252,15 @@ case $POWERLEVEL9K_MODE in
TODO_ICON $'\u2611' # ☑ TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\U1F50B' # 🔋 BATTERY_ICON $'\U1F50B' # 🔋
DISK_ICON $'hdd ' DISK_ICON $'hdd '
OK_ICON $'\u2713' # ✓ OK_ICON $'\u2714' # ✔
FAIL_ICON $'\u2718' # ✘ FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF' SYMFONY_ICON 'SF'
NODE_ICON $'\u2B22' # ⬢ NODE_ICON $'\u2B22' # ⬢
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\u2500' 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 'OSX' APPLE_ICON 'OSX'
WINDOWS_ICON 'WIN'
FREEBSD_ICON 'BSD' FREEBSD_ICON 'BSD'
ANDROID_ICON 'And' ANDROID_ICON 'And'
LINUX_ICON 'Lx' LINUX_ICON 'Lx'
@ -268,7 +282,7 @@ case $POWERLEVEL9K_MODE in
VCS_TAG_ICON '' VCS_TAG_ICON ''
VCS_BOOKMARK_ICON $'\u263F' # ☿ VCS_BOOKMARK_ICON $'\u263F' # ☿
VCS_COMMIT_ICON '' VCS_COMMIT_ICON ''
VCS_BRANCH_ICON $'\uE0A0' #  VCS_BRANCH_ICON $'\uE0A0 ' # 
VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_REMOTE_BRANCH_ICON $'\u2192' # →
VCS_GIT_ICON '' VCS_GIT_ICON ''
VCS_GIT_GITHUB_ICON '' VCS_GIT_GITHUB_ICON ''
@ -284,6 +298,8 @@ case $POWERLEVEL9K_MODE in
LOCK_ICON $'\UE0A2' LOCK_ICON $'\UE0A2'
EXECUTION_TIME_ICON 'Dur' EXECUTION_TIME_ICON 'Dur'
SSH_ICON '(ssh)' SSH_ICON '(ssh)'
VPN_ICON '(vpn)'
KUBERNETES_ICON $'\U2388' # ⎈
) )
;; ;;
esac esac

@ -85,6 +85,10 @@ case $(uname) in
OS='OSX' OS='OSX'
OS_ICON=$(print_icon 'APPLE_ICON') OS_ICON=$(print_icon 'APPLE_ICON')
;; ;;
CYGWIN_NT-*)
OS='Windows'
OS_ICON=$(print_icon 'WINDOWS_ICON')
;;
FreeBSD) FreeBSD)
OS='BSD' OS='BSD'
OS_ICON=$(print_icon 'FREEBSD_ICON') OS_ICON=$(print_icon 'FREEBSD_ICON')
@ -212,7 +216,7 @@ function segmentShouldBeJoined() {
# Given a directory path, truncate it according to the settings for # Given a directory path, truncate it according to the settings for
# `truncate_from_right` # `truncate_from_right`
function truncatePathFromRight() { function truncatePathFromRight() {
local delim_len=${#POWERLEVEL9K_SHORTEN_DELIMITER} local delim_len=${#POWERLEVEL9K_SHORTEN_DELIMITER:-1}
echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER \ echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER \
"s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g" "s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g"
} }

@ -17,7 +17,7 @@ function +vi-git-untracked() {
fi fi
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \
-n $(git status ${FLAGS} | grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then -n $(git status ${FLAGS} | \grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
VCS_WORKDIR_HALF_DIRTY=true VCS_WORKDIR_HALF_DIRTY=true
else else
@ -137,15 +137,15 @@ function +vi-vcs-detect-changes() {
function +vi-svn-detect-changes() { function +vi-svn-detect-changes() {
local svn_status="$(svn status)" local svn_status="$(svn status)"
if [[ -n "$(echo "$svn_status" | grep \^\?)" ]]; then if [[ -n "$(echo "$svn_status" | \grep \^\?)" ]]; then
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
VCS_WORKDIR_HALF_DIRTY=true VCS_WORKDIR_HALF_DIRTY=true
fi fi
if [[ -n "$(echo "$svn_status" | grep \^\M)" ]]; then if [[ -n "$(echo "$svn_status" | \grep \^\M)" ]]; then
hook_com[unstaged]+=" $(print_icon 'VCS_UNSTAGED_ICON')" hook_com[unstaged]+=" $(print_icon 'VCS_UNSTAGED_ICON')"
VCS_WORKDIR_DIRTY=true VCS_WORKDIR_DIRTY=true
fi fi
if [[ -n "$(echo "$svn_status" | grep \^\A)" ]]; then if [[ -n "$(echo "$svn_status" | \grep \^\A)" ]]; then
hook_com[staged]+=" $(print_icon 'VCS_STAGED_ICON')" hook_com[staged]+=" $(print_icon 'VCS_STAGED_ICON')"
VCS_WORKDIR_DIRTY=true VCS_WORKDIR_DIRTY=true
fi fi

@ -17,74 +17,57 @@
################################################################ ################################################################
## Turn on for Debugging ## 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 #zstyle ':vcs_info:*+*:*' debug true
#set -o xtrace #set -o xtrace
# Try to set the installation path # Try to set the installation path
if [[ -n "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then if [[ -n "$POWERLEVEL9K_INSTALLATION_DIR" ]]; then
# If an installation path was set manually, p9k_directory=${POWERLEVEL9K_INSTALLATION_DIR:A}
# 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
else else
print -P "%F{red}Script location could not be found! Maybe your %F{blue}POWERLEVEL9K_INSTALLATION_PATH%F{red} is not correct?%f" if [[ "${(%):-%N}" == '(eval)' ]]; then
return 1 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 fi
script_location="$(dirname $filename)"
################################################################ ################################################################
# Source icon functions # Source icon functions
################################################################ ################################################################
source $script_location/functions/icons.zsh source "${p9k_directory}/functions/icons.zsh"
################################################################ ################################################################
# Source utility functions # Source utility functions
################################################################ ################################################################
source $script_location/functions/utilities.zsh source "${p9k_directory}/functions/utilities.zsh"
################################################################ ################################################################
# Source color functions # Source color functions
################################################################ ################################################################
source $script_location/functions/colors.zsh source "${p9k_directory}/functions/colors.zsh"
################################################################ ################################################################
# Source VCS_INFO hooks / helper functions # 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 # Color Scheme
@ -304,7 +287,7 @@ prompt_anaconda() {
# AWS Profile # AWS Profile
prompt_aws() { prompt_aws() {
local aws_profile="$AWS_DEFAULT_PROFILE" local aws_profile="${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}"
if [[ -n "$aws_profile" ]]; then if [[ -n "$aws_profile" ]]; then
"$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON' "$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON'
@ -337,6 +320,23 @@ prompt_background_jobs() {
fi 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. # Segment that indicates usage level of current partition.
set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false
set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90 set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
@ -468,9 +468,24 @@ prompt_battery() {
message="$bat_percent%%" message="$bat_percent%%"
fi fi
# Draw the prompt_segment # override default icon if we are using battery stages
if [[ -n $bat_percent ]]; then if [[ -n "$POWERLEVEL9K_BATTERY_STAGES" ]]; then
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON' 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 fi
} }
@ -492,7 +507,11 @@ prompt_public_ip() {
if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
typeset -i timediff typeset -i timediff
# if saved IP is more than # if saved IP is more than
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s))) if [[ "$OS" == "OSX" ]]; then
timediff=$(($(date +%s) - $(stat -f "%m" $POWERLEVEL9K_PUBLIC_IP_FILE)))
else
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
fi
[[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMEOUT ]] && refresh_ip=true [[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMEOUT ]] && refresh_ip=true
# If tmp file is empty get a fresh IP # If tmp file is empty get a fresh IP
[[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true
@ -555,7 +574,7 @@ prompt_context() {
local content="" local content=""
if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
if [[ $(print -P "%#") == '#' ]]; then if [[ $(print -P "%#") == '#' ]]; then
current_state="ROOT" current_state="ROOT"
@ -564,7 +583,7 @@ prompt_context() {
content="${POWERLEVEL9K_CONTEXT_TEMPLATE}" content="${POWERLEVEL9K_CONTEXT_TEMPLATE}"
elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then
content="$USER" content="$(whoami)"
else else
return return
fi fi
@ -572,6 +591,61 @@ prompt_context() {
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" "$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 ]] || [[ "$(whoami)" != "$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" "$(whoami)"
"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 'custom` prompt provides a way for users to invoke commands and display
# the output in a segment. # the output in a segment.
prompt_custom() { prompt_custom() {
@ -619,8 +693,12 @@ prompt_command_execution_time() {
# Dir: current working directory # Dir: current working directory
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false
prompt_dir() { prompt_dir() {
local current_path="$(print -P "%~")" local tmp="$IFS"
local IFS=""
local current_path=$(pwd | sed -e "s,^$HOME,~,")
local IFS="$tmp"
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then
set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026'
@ -709,8 +787,31 @@ prompt_dir() {
# the current path. # the current path.
current_path=$current_path${PWD#${last_marked_folder}*} current_path=$current_path${PWD#${last_marked_folder}*}
;; ;;
truncate_to_unique)
# for each parent path component find the shortest unique beginning
# characters sequence. Source: https://stackoverflow.com/a/45336078
paths=(${(s:/:)PWD})
cur_path='/'
cur_short_path='/'
for directory in ${paths[@]}
do
cur_dir=''
for (( i=0; i<${#directory}; i++ )); do
cur_dir+="${directory:$i:1}"
matching=("$cur_path"/"$cur_dir"*/)
if [[ ${#matching[@]} -eq 1 ]]; then
break
fi
done
cur_short_path+="$cur_dir/"
cur_path+="$directory/"
done
current_path="${cur_short_path: : -1}"
;;
*) *)
current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" if [[ $current_path != "~" ]]; then
current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")"
fi
;; ;;
esac esac
fi fi
@ -724,7 +825,7 @@ prompt_dir() {
fi fi
if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" ]]; then 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 fi
typeset -AH dir_states typeset -AH dir_states
@ -732,9 +833,12 @@ prompt_dir() {
"DEFAULT" "FOLDER_ICON" "DEFAULT" "FOLDER_ICON"
"HOME" "HOME_ICON" "HOME" "HOME_ICON"
"HOME_SUBFOLDER" "HOME_SUB_ICON" "HOME_SUBFOLDER" "HOME_SUB_ICON"
"NOT_WRITABLE" "LOCK_ICON"
) )
local current_state="DEFAULT" 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" current_state="HOME"
elif [[ $(print -P "%~") == '~'* ]]; then elif [[ $(print -P "%~") == '~'* ]]; then
current_state="HOME_SUBFOLDER" current_state="HOME_SUBFOLDER"
@ -777,12 +881,12 @@ prompt_detect_virt() {
if [[ "$virt" == "none" ]]; then if [[ "$virt" == "none" ]]; then
if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then
virt="chroot" virt="chroot"
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$virt" "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
else else
; ;
fi fi
else else
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$virt" "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
fi fi
} }
@ -827,9 +931,22 @@ prompt_ip() {
"$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON' "$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
}
set_default POWERLEVEL9K_LOAD_WHICH 5
prompt_load() { prompt_load() {
# The load segment can have three different states # The load segment can have three different states
local current_state="unknown" local current_state="unknown"
local load_select=2
local load_avg
local cores local cores
typeset -AH load_states typeset -AH load_states
@ -839,32 +956,47 @@ prompt_load() {
'normal' 'green' 'normal' 'green'
) )
if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then case "$POWERLEVEL9K_LOAD_WHICH" in
load_avg_1min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) 1)
if [[ "$OS" == "OSX" ]]; then load_select=1
cores=$(sysctl -n hw.logicalcpu) ;;
else 5)
cores=$(sysctl -n hw.ncpu) load_select=2
fi ;;
else 15)
load_avg_1min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) load_select=3
cores=$(nproc) ;;
fi esac
case "$OS" in
OSX|BSD)
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | sed -n ${load_select}p)
if [[ "$OS" == "OSX" ]]; then
cores=$(sysctl -n hw.logicalcpu)
else
cores=$(sysctl -n hw.ncpu)
fi
;;
*)
load_avg=$(cut -d" " -f${load_select} /proc/loadavg)
cores=$(nproc)
esac
# Replace comma # Replace comma
load_avg_1min=${load_avg_1min//,/.} load_avg=${load_avg//,/.}
if [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.7") ]]; then if [[ "$load_avg" -gt $((${cores} * 0.7)) ]]; then
current_state="critical" current_state="critical"
elif [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.5") ]]; then elif [[ "$load_avg" -gt $((${cores} * 0.5)) ]]; then
current_state="warning" current_state="warning"
else else
current_state="normal" current_state="normal"
fi fi
"$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_1min" 'LOAD_ICON' "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg" 'LOAD_ICON'
} }
# Node version # Node version
prompt_node_version() { prompt_node_version() {
local node_version=$(node -v 2>/dev/null) local node_version=$(node -v 2>/dev/null)
@ -876,13 +1008,16 @@ prompt_node_version() {
# Node version from NVM # Node version from NVM
# Only prints the segment if different than the default value # Only prints the segment if different than the default value
prompt_nvm() { prompt_nvm() {
[[ ! $(type nvm) =~ 'nvm is a shell function'* ]] && return local node_version nvm_default
local node_version=$(nvm current) (( $+functions[nvm_version] )) || return
[[ -z "${node_version}" ]] || [[ ${node_version} = "none" ]] && return
local nvm_default=$(cat $NVM_DIR/alias/default) node_version=$(nvm_version current)
[[ -z "${node_version}" || ${node_version} == "none" ]] && return
nvm_default=$(nvm_version default)
[[ "$node_version" =~ "$nvm_default" ]] && return [[ "$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 # NodeEnv Prompt
@ -932,14 +1067,15 @@ prompt_ram() {
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON' "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON'
} }
set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false
# rbenv information # rbenv information
prompt_rbenv() { prompt_rbenv() {
if which rbenv 2>/dev/null >&2; then if command which rbenv 2>/dev/null >&2; then
local rbenv_version_name="$(rbenv version-name)" local rbenv_version_name="$(rbenv version-name)"
local rbenv_global="$(rbenv global)" local rbenv_global="$(rbenv global)"
# Don't show anything if the current Ruby is the same as the global Ruby. # Don't show anything if the current Ruby is the same as the global Ruby.
if [[ $rbenv_version_name == $rbenv_global ]]; then if [[ $rbenv_version_name == $rbenv_global && "$POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW" = false ]]; then
return return
fi fi
@ -1000,13 +1136,10 @@ prompt_rspec_stats() {
# Ruby Version Manager information # Ruby Version Manager information
prompt_rvm() { prompt_rvm() {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') local version_and_gemset=${rvm_env_string/ruby-}
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') if [[ -n "$version_and_gemset" ]]; then
"$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON'
if [[ -n "$version$gemset" ]]; then
"$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version$gemset" 'RUBY_ICON'
fi fi
} }
@ -1016,17 +1149,62 @@ prompt_ssh() {
fi 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_VERBOSE true
set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false 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() { prompt_status() {
if [[ "$RETVAL" -ne 0 ]]; then local ec_text
if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then local ec_sum
"$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL" 'CARRIAGE_RETURN_ICON' local ec
if [[ $POWERLEVEL9K_STATUS_SHOW_PIPESTATUS == true ]]; then
if (( $#RETVALS > 1 )); then
ec_text=$(exit_code_or_status "${RETVALS[1]}")
ec_sum=${RETVALS[1]}
else
ec_text=$(exit_code_or_status "${RETVAL}")
ec_sum=${RETVAL}
fi
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 else
"$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON'
fi 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' "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "green" "" 'OK_ICON'
fi fi
} }
@ -1178,7 +1356,7 @@ powerlevel9k_vcs_init() {
prompt_vcs() { prompt_vcs() {
VCS_WORKDIR_DIRTY=false VCS_WORKDIR_DIRTY=false
VCS_WORKDIR_HALF_DIRTY=false VCS_WORKDIR_HALF_DIRTY=false
current_state="" local current_state=""
# Actually invoke vcs_info manually to gather all information. # Actually invoke vcs_info manually to gather all information.
vcs_info vcs_info
@ -1205,12 +1383,12 @@ set_default POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT"
set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL" set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL"
prompt_vi_mode() { prompt_vi_mode() {
case ${KEYMAP} in case ${KEYMAP} in
main|viins)
"$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING"
;;
vicmd) vicmd)
"$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING" "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING"
;; ;;
main|viins|*)
"$1_prompt_segment" "$0_INSERT" "$2" "$DEFAULT_COLOR" "blue" "$POWERLEVEL9K_VI_INSERT_MODE_STRING"
;;
esac esac
} }
@ -1225,18 +1403,10 @@ prompt_virtualenv() {
} }
# pyenv: current active python version (with restrictions) # pyenv: current active python version (with restrictions)
# More information on pyenv (Python version manager like rbenv and rvm): # https://github.com/pyenv/pyenv#choosing-the-python-version
# https://github.com/yyuu/pyenv
# the prompt parses output of pyenv version and only displays the first word
prompt_pyenv() { prompt_pyenv() {
local pyenv_version="$(pyenv version 2>/dev/null)" if [[ -n "$PYENV_VERSION" ]]; then
pyenv_version="${pyenv_version%% *}" "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$PYENV_VERSION" 'PYTHON_ICON'
# XXX: The following should return the same as above.
# This reads better for devs familiar with sed/awk/grep/cut utilities
# Using shell expansion/substitution may hamper future maintainability
#local pyenv_version="$(pyenv version 2>/dev/null | head -n1 | cut -d' ' -f1)"
if [[ -n "$pyenv_version" && "$pyenv_version" != "system" ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$pyenv_version" 'PYTHON_ICON'
fi fi
} }
@ -1256,12 +1426,42 @@ prompt_dir_writable() {
fi 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
local k8s_final_text=""
if [[ "$k8s_context" == "k8s_namespace" ]]; then
# No reason to print out the same identificator twice
k8s_final_text="$k8s_context"
else
k8s_final_text="$k8s_context/$k8s_namespace"
fi
"$1_prompt_segment" "$0" "$2" "magenta" "white" "$k8s_final_text" "KUBERNETES_ICON"
fi
}
################################################################ ################################################################
# Prompt processing and drawing # Prompt processing and drawing
################################################################ ################################################################
# Main prompt # Main prompt
build_left_prompt() { build_left_prompt() {
local index=1 local index=1
local element
for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do
# Remove joined information in direct calls # Remove joined information in direct calls
element=${element%_joined} element=${element%_joined}
@ -1306,15 +1506,16 @@ powerlevel9k_preexec() {
set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false
powerlevel9k_prepare_prompts() { powerlevel9k_prepare_prompts() {
RETVAL=$? RETVAL=$?
RETVALS=( "$pipestatus[@]" )
_P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START)) _P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START))
# Reset start time # Reset start time
_P9K_TIMER_START=0xFFFFFFFF _P9K_TIMER_START=0x7FFFFFFF
if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then
PROMPT='$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt) 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 if [[ "$POWERLEVEL9K_RPROMPT_ON_NEWLINE" != true ]]; then
# The right prompt should be on the same line as the first line of the left # 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 # prompt. To do so, there is just a quite ugly workaround: Before zsh draws
@ -1343,28 +1544,28 @@ NEWLINE='
} }
prompt_powerlevel9k_setup() { 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 # The value below was set to better support 32-bit CPUs.
# We don't have to change that until 19 January of 2038! :) # 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 # Disable false display of command execution time
# Maximum integer on 32-bit CPUs _P9K_TIMER_START=0x7FFFFFFF
_P9K_TIMER_START=2147483647
# The prompt function will set these prompt_* options after the setup function # 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 # 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 # without them being double expanded and we need prompt_percent to expand the
# common percent escape sequences. # 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 # Borrowed from promptinit, sets the prompt options in case the theme was
# not initialized via promptinit. # 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 # Display a warning if the terminal does not support 256 colors
local term_colors local term_colors
term_colors=$(echotc Co 2>/dev/null) term_colors=$(echotc Co 2>/dev/null)
if (( ! $? && ${term_colors:-0} < 256 )); then if (( ! $? && ${term_colors:-0} < 256 )); then
print -P "%F{red}WARNING!%f Your terminal appears to support less than 256 colors!" print -P "%F{red}WARNING!%f Your terminal appears to support fewer than 256 colors!"
print -P "If your terminal supports 256 colors, please export the appropriate environment variable" print -P "If your terminal supports 256 colors, please export the appropriate environment variable"
print -P "_before_ loading this theme in your \~\/.zshrc. In most terminal emulators, putting" print -P "_before_ loading this theme in your \~\/.zshrc. In most terminal emulators, putting"
print -P "%F{blue}export TERM=\"xterm-256color\"%f at the top of your \~\/.zshrc is sufficient." print -P "%F{blue}export TERM=\"xterm-256color\"%f at the top of your \~\/.zshrc is sufficient."
@ -1412,4 +1613,11 @@ prompt_powerlevel9k_setup() {
add-zsh-hook preexec powerlevel9k_preexec 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 "$@" prompt_powerlevel9k_setup "$@"

@ -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

@ -36,6 +36,27 @@ function testTruncateFoldersWorks() {
unset POWERLEVEL9K_SHORTEN_STRATEGY unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncateFolderWithHomeDirWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
CURRENT_DIR=$(pwd)
cd ~
FOLDER="powerlevel9k-test-${RANDOM}"
mkdir -p $FOLDER
cd $FOLDER
# Switch back to home folder as this causes the problem.
cd ..
assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)"
rmdir $FOLDER
cd ${CURRENT_DIR}
unset CURRENT_DIR
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
}
function testTruncateMiddleWorks() { function testTruncateMiddleWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle'
@ -72,6 +93,26 @@ function testTruncationFromRightWorks() {
unset POWERLEVEL9K_SHORTEN_STRATEGY unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncationFromRightWithEmptyDelimiter() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_DELIMITER=""
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
assertEquals "%K{blue} %F{black}/tmp/po/1/12/123/12/12/12/12/12/123456789 %k%F{blue}%f " "$(build_left_prompt)"
cd -
rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
unset POWERLEVEL9K_SHORTEN_DELIMITER
unset POWERLEVEL9K_SHORTEN_STRATEGY
}
function testTruncateWithFolderMarkerWorks() { function testTruncateWithFolderMarkerWorks() {
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
@ -272,6 +313,31 @@ function testChangingDirPathSeparator() {
unset POWERLEVEL9K_DIR_PATH_SEPARATOR 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() { function testOmittingFirstCharacterWorks() {
POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
POWERLEVEL9K_FOLDER_ICON='folder-icon' POWERLEVEL9K_FOLDER_ICON='folder-icon'
@ -361,4 +427,25 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat
unset POWERLEVEL9K_SHORTEN_STRATEGY 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'
mkdir -p /tmp/powerlevel9k-test/adam/devl
mkdir -p /tmp/powerlevel9k-test/alice/devl
mkdir -p /tmp/powerlevel9k-test/alice/docs
mkdir -p /tmp/powerlevel9k-test/bob/docs
cd /tmp/powerlevel9k-test/alice/devl
assertEquals "%K{blue} %F{black}txXxpxXxalxXxde %k%F{blue}%f " "$(build_left_prompt)"
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
}
source shunit2/source/2.1/src/shunit2 source shunit2/source/2.1/src/shunit2

@ -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

@ -21,7 +21,7 @@ function testColorOverridingForCleanStateWorks() {
cd $FOLDER cd $FOLDER
git init 1>/dev/null git init 1>/dev/null
assertEquals "%K{white} %F{cyan}master %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)"
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
@ -47,7 +47,7 @@ function testColorOverridingForModifiedStateWorks() {
git commit -m "test" 1>/dev/null git commit -m "test" 1>/dev/null
echo "test" > testfile echo "test" > testfile
assertEquals "%K{yellow} %F{red}master ● %k%F{yellow}%f " "$(build_left_prompt)" assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)"
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
@ -68,7 +68,7 @@ function testColorOverridingForUntrackedStateWorks() {
git init 1>/dev/null git init 1>/dev/null
touch testfile touch testfile
assertEquals "%K{yellow} %F{cyan}master ? %k%F{yellow}%f " "$(build_left_prompt)" assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)"
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test

Loading…
Cancel
Save