[SSH]: resolved merge conflict and merged with current next

pull/22/head
Christian Rebischke 8 years ago
commit 15cbe8dbc9
No known key found for this signature in database
GPG Key ID: D21461E3DFE2060D

@ -1,11 +1,57 @@
## next ## next
- Fixed a bug where the tag display was broken on detached HEADs.
- Fixed a bug where SVN detection sometimes failed.
- Fixed the `load` and `ram` segments for BSD.
- Fixed code-points that changed in Awesome fonts.
- Fixed display of "OK_ICON" in `status` segment in non-verbose mode.
- Fixed an issue where dir name truncation that was very short sometimes failed.
- Speed & accuracy improvements to the battery segment.
- Added Github syntax highlighting to README.
- Various documentation cleanup.
### `vcs` changes
The VCS segment can now display icons for remote repo hosting services, including Github, Gitlab, and 'other'.
### `dir` changes ### `dir` changes
Added an option to configure the path separator. If you want something Added an option to configure the path separator. If you want something
else than an ordinary slash, you could set else than an ordinary slash, you could set
`POWERLEVEL9K_DIR_PATH_SEPARATOR` to whatever you want. `POWERLEVEL9K_DIR_PATH_SEPARATOR` to whatever you want.
### New segment 'disk_usage' added
This segment will show the usage level of your current partition.
### New segment 'public_ip' added
Fetches your Public IP (using ident.me) and displays it in your prompt.
### New segment 'swift_version' added
This segment displays the version of Swift that is installed / in your path.
### New segment 'detect_virt' added
Detects and reports if you are in a virtualized session using `systemd`.
## v0.5.0
### `load` and `ram` changes
These two segments now support BSD.
### `vcs` changes
- We implemented a huge speed improvement for this segment.
- Now this segment supports Subversion repositories.
- Add ability to hide tags by setting `POWERLEVEL9K_VCS_HIDE_TAGS` to true.
## `anaconda` changes
Speed improvements for `anaconda` segment.
## v0.4.0 ## v0.4.0
### Development changes ### Development changes
@ -85,6 +131,11 @@ Added new `docker_machine` segment that will show your Docker machine.
A new segment `anaconda` was added that shows the current used A new segment `anaconda` was added that shows the current used
anaconda environment. anaconda environment.
## New segment `pyenv` added
This segment shows your active python version as reported by `pyenv`.
## v0.3.2 ## v0.3.2
### `vcs` changes ### `vcs` changes

@ -1,5 +1,5 @@
## powerlevel9k Theme for ZSH ![](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=next)](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)
@ -46,8 +46,8 @@ Here is `powerlevel9k` in action, with [some simple settings](https://github.com
Be sure to also [check out the Wiki](https://github.com/bhilburn/powerlevel9k/wiki)! Be sure to also [check out the Wiki](https://github.com/bhilburn/powerlevel9k/wiki)!
### Installation ### Installation
There are two installation steps to go from a lame terminal to a "Power Level There are two installation steps to go from a vanilla terminal to a PL9k
9000" terminal. Once you are done, you can optionally customize your prompt. terminal. Once you are done, you can optionally customize your prompt.
[Installation Instructions](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions) [Installation Instructions](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions)
@ -71,14 +71,15 @@ variables to your `~/.zshrc`.
| Variable | Default Value | Description | | Variable | Default Value | Description |
|----------|---------------|-------------| |----------|---------------|-------------|
|`POWERLEVEL9K_LEFT_PROMPT_ELEMENTS`|`(context dir rbenv vcs)`|Segment list for left prompt| |`POWERLEVEL9K_LEFT_PROMPT_ELEMENTS`|`(context dir rbenv vcs)`|Segment list for left prompt|
|`POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS`|`(status history time)`|Segment list for right prompt| |`POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS`|`(status root_indicator background_jobs history time)`|Segment list for right prompt|
So if you wanted to set these variables manually, you would put the following in The table above shows the default values, so if you wanted to set these
variables manually, you would put the following in
your `~/.zshrc`: your `~/.zshrc`:
```zsh ```zsh
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time)
``` ```
#### Available Prompt Segments #### Available Prompt Segments
The segments that are currently available are: The segments that are currently available are:
@ -88,8 +89,10 @@ The segments that are currently available are:
* [`battery`](#battery) - Current battery status. * [`battery`](#battery) - Current battery status.
* [`context`](#context) - Your username and host. * [`context`](#context) - Your username and host.
* [`dir`](#dir) - Your current working directory. * [`dir`](#dir) - Your current working directory.
* [`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.
* [`ip`](#ip) - Shows the current IP address. * [`ip`](#ip) - Shows the current IP address.
* [`public_ip`](#public_ip) - Shows your public IP address.
* `load` - Your machine's load averages. * `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.
@ -123,6 +126,8 @@ The segments that are currently available are:
* [`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.
* **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_version` - Show the version number of the installed Swift.
**Cloud Segments:** **Cloud Segments:**
* **AWS Segments:** * **AWS Segments:**
@ -134,6 +139,7 @@ The segments that are currently available are:
* [`custom_command`](#custom_command) - Create a custom segment to display the * [`custom_command`](#custom_command) - Create a custom segment to display the
output of an arbitrary command. output of an arbitrary command.
* [`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
--------------------------------------------------------------------------------- ---------------------------------------------------------------------------------
@ -237,9 +243,17 @@ it, but only display it if you are not your normal user or on a remote host
To use this feature, make sure the `context` segment is enabled in your prompt To use this feature, make sure the `context` segment is enabled in your prompt
elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`: elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`:
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. 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.
| Variable | Default Value | Description | | Variable | Default Value | Description |
|----------|---------------|-------------| |----------|---------------|-------------|
|`DEFAULT_USER`|None|Username to consider a "default context" (you can also use `$USER`)| |`DEFAULT_USER`|None|Username to consider a "default context" (you can also use `$USER`)|
|`POWERLEVEL9K_CONTEXT_HOST_DEPTH`|%m|Customizable host depth on prompt|
You can use POWERLEVEL9K_HIDE_HOST for hiding the hostname in the prompt You can use POWERLEVEL9K_HIDE_HOST for hiding the hostname in the prompt
when you are not in a ssh session. For example: when you are not in a ssh session. For example:
@ -299,6 +313,16 @@ If you want to customize the directory separator, you could set:
POWERLEVEL9K_DIR_PATH_SEPARATOR="%f "$'\uE0B1'" %F" POWERLEVEL9K_DIR_PATH_SEPARATOR="%f "$'\uE0B1'" %F"
``` ```
##### disk_usage
The `disk_usage` segment will show the usage level of the partition that your current working directory resides in. It can be configured with the following variables.
| Variable | Default Value | Description |
|----------|---------------|-------------|
|POWERLEVEL9K_DISK_USAGE_ONLY_WARNING|false|Hide the segment except when usage levels have hit warning or critical levels.|
|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.|
##### 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
@ -309,6 +333,29 @@ 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`.|
##### public_ip
This segment will display your public IP address. There are several methods of obtaining this
information and by default it will try all of them starting with the most efficient. You can
also specify which method you would like it to use. The methods available are dig using opendns,
curl, or wget. The host used for wget and curl is http://ident.me by default but can be set to
another host if you prefer.
The public_ip segment will attempt to update your public IP address every 5 minutes by default(also
configurable by the user). If you lose connection your cached IP address will be displayed until
your timeout expires at which point every time your prompt is generated a new attempt will be made.
Until an IP is successfully pulled the value of $POWERLEVEL9K_PUBLIC_IP_NONE will be displayed for
this segment. If this value is empty(the default)and $POWERLEVEL9K_PUBLIC_IP_FILE is empty the
segment will not be displayed.
| Variable | Default Value | Description |
|----------|---------------|-------------|
|`POWERLEVEL9K_PUBLIC_IP_FILE`|'/tmp/p8k_public_ip'|This is the file your public IP is cached in.|
|`POWERLEVEL9K_PUBLIC_IP_HOST`|'http://ident.me'|This is the default host to get your public IP.|
|`POWERLEVEL9K_PUBLIC_IP_TIMEOUT`|300|The amount of time in seconds between refreshing your cached IP.|
|`POWERLEVEL9K_PUBLIC_IP_METHOD`|None|You can set this to any of 'dig', 'curl', or 'wget' to only use that method to refresh your IP.|
|`POWERLEVEL9K_PUBLIC_IP_NONE`|None|The string displayed when an IP was not obtained|
##### 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.
@ -424,4 +471,7 @@ portion of the wiki to get going.
information!](https://github.com/bhilburn/powerlevel9k/wiki) information!](https://github.com/bhilburn/powerlevel9k/wiki)
### License ### License
MIT
Project: MIT
Logo: CC-BY-SA. Source repository: https://github.com/bhilburn/powerlevel9k-logo

@ -34,6 +34,7 @@ case $POWERLEVEL9K_MODE in
TEST_ICON $'\uE891' #  TEST_ICON $'\uE891' # 
TODO_ICON $'\u2611' # ☑ TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\uE894' #  BATTERY_ICON $'\uE894' # 
DISK_ICON $'\uE1AE ' # 
OK_ICON $'\u2713' # ✓ OK_ICON $'\u2713' # ✓
FAIL_ICON $'\u2718' # ✘ FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF' SYMFONY_ICON 'SF'
@ -66,12 +67,17 @@ case $POWERLEVEL9K_MODE in
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 ' '$'\uE804 ' #  VCS_REMOTE_BRANCH_ICON $'\u2192' # →
VCS_GIT_ICON $'\uE20E ' #  VCS_GIT_ICON $'\uE20E ' # 
VCS_GIT_GITHUB_ICON $'\uE20E ' #
VCS_GIT_BITBUCKET_ICON $'\uE20E ' #
VCS_GIT_GITLAB_ICON $'\uE20E ' #
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 $'\U1F40D' # 🐍
SWIFT_ICON ''
PUBLIC_IP_ICON ''
) )
;; ;;
'awesome-fontconfig') 'awesome-fontconfig')
@ -92,8 +98,9 @@ case $POWERLEVEL9K_MODE in
TEST_ICON $'\uF291' #  TEST_ICON $'\uF291' # 
TODO_ICON $'\u2611' # ☑ TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\U1F50B' # 🔋 BATTERY_ICON $'\U1F50B' # 🔋
OK_ICON $'\uF23A' #  DISK_ICON $'\uF0A0 ' # 
FAIL_ICON $'\uF281' #  OK_ICON $'\u2713' # ✓
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' # ╭─
@ -120,12 +127,17 @@ case $POWERLEVEL9K_MODE in
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 ' '$'\uF204 ' #  VCS_REMOTE_BRANCH_ICON $'\u2192' # →
VCS_GIT_ICON $'\uF113 ' #  VCS_GIT_ICON $'\uF1D3 ' # 
VCS_GIT_GITHUB_ICON $'\uF113 ' # 
VCS_GIT_BITBUCKET_ICON $'\uF171 ' # 
VCS_GIT_GITLAB_ICON $'\uF296 ' # 
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 $'\U1F40D' # 🐍
SWIFT_ICON ''
PUBLIC_IP_ICON ''
) )
;; ;;
*) *)
@ -146,6 +158,7 @@ case $POWERLEVEL9K_MODE in
TEST_ICON '' TEST_ICON ''
TODO_ICON $'\u2611' # ☑ TODO_ICON $'\u2611' # ☑
BATTERY_ICON $'\U1F50B' # 🔋 BATTERY_ICON $'\U1F50B' # 🔋
DISK_ICON $'hdd '
OK_ICON $'\u2713' # ✓ OK_ICON $'\u2713' # ✓
FAIL_ICON $'\u2718' # ✘ FAIL_ICON $'\u2718' # ✘
SYMFONY_ICON 'SF' SYMFONY_ICON 'SF'
@ -176,10 +189,15 @@ case $POWERLEVEL9K_MODE in
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_BITBUCKET_ICON ''
VCS_GIT_GITLAB_ICON ''
VCS_HG_ICON '' VCS_HG_ICON ''
VCS_SVN_ICON '' VCS_SVN_ICON ''
RUST_ICON '' RUST_ICON ''
PYTHON_ICON '' PYTHON_ICON ''
SWIFT_ICON 'Swift'
PUBLIC_IP_ICON ''
) )
;; ;;
esac esac

@ -110,7 +110,18 @@ function +vi-hg-bookmarks() {
function +vi-vcs-detect-changes() { function +vi-vcs-detect-changes() {
if [[ "${hook_com[vcs]}" == "git" ]]; then if [[ "${hook_com[vcs]}" == "git" ]]; then
local remote=`git ls-remote --get-url`
if [[ "$remote" =~ "github" ]] then
vcs_visual_identifier='VCS_GIT_GITHUB_ICON'
elif [[ "$remote" =~ "bitbucket" ]] then
vcs_visual_identifier='VCS_GIT_BITBUCKET_ICON'
elif [[ "$remote" =~ "gitlab" ]] then
vcs_visual_identifier='VCS_GIT_GITLAB_ICON'
else
vcs_visual_identifier='VCS_GIT_ICON' vcs_visual_identifier='VCS_GIT_ICON'
fi
elif [[ "${hook_com[vcs]}" == "hg" ]]; then elif [[ "${hook_com[vcs]}" == "hg" ]]; then
vcs_visual_identifier='VCS_HG_ICON' vcs_visual_identifier='VCS_HG_ICON'
elif [[ "${hook_com[vcs]}" == "svn" ]]; then elif [[ "${hook_com[vcs]}" == "svn" ]]; then

@ -41,7 +41,7 @@ else
POWERLEVEL9K_INSTALLATION_PATH="$0" POWERLEVEL9K_INSTALLATION_PATH="$0"
fi fi
# Resolve the instllation path # Resolve the installation path
if [[ -L "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then if [[ -L "$POWERLEVEL9K_INSTALLATION_PATH" ]]; then
# If this theme is sourced as a symlink, we need to locate the real URL # If this theme is sourced as a symlink, we need to locate the real URL
filename="$(realpath -P $POWERLEVEL9K_INSTALLATION_PATH 2>/dev/null || readlink -f $POWERLEVEL9K_INSTALLATION_PATH 2>/dev/null || perl -MCwd=abs_path -le 'print abs_path readlink(shift);' $POWERLEVEL9K_INSTALLATION_PATH 2>/dev/null)" filename="$(realpath -P $POWERLEVEL9K_INSTALLATION_PATH 2>/dev/null || readlink -f $POWERLEVEL9K_INSTALLATION_PATH 2>/dev/null || perl -MCwd=abs_path -le 'print abs_path readlink(shift);' $POWERLEVEL9K_INSTALLATION_PATH 2>/dev/null)"
@ -106,7 +106,7 @@ fi
# name. From this function name, we strip the "prompt_"-prefix and # name. From this function name, we strip the "prompt_"-prefix and
# uppercase it. This is then prefixed with "POWERLEVEL9K_" and suffixed # uppercase it. This is then prefixed with "POWERLEVEL9K_" and suffixed
# with either "_BACKGROUND" or "_FOREGROUND", thus giving us the variable # with either "_BACKGROUND" or "_FOREGROUND", thus giving us the variable
# name. So each new segment is user-overwritable by a variable following # name. So each new segment is user-overwritten by a variable following
# this naming convention. # this naming convention.
################################################################ ################################################################
@ -117,7 +117,7 @@ CURRENT_BG='NONE'
# Begin a left prompt segment # Begin a left prompt segment
# Takes four arguments: # Takes four arguments:
# * $1: Name of the function that was orginally invoked (mandatory). # * $1: Name of the function that was originally invoked (mandatory).
# Necessary, to make the dynamic color-overwrite mechanism work. # Necessary, to make the dynamic color-overwrite mechanism work.
# * $2: The array index of the current segment # * $2: The array index of the current segment
# * $3: Background color # * $3: Background color
@ -207,7 +207,7 @@ CURRENT_RIGHT_BG='NONE'
# Begin a right prompt segment # Begin a right prompt segment
# Takes four arguments: # Takes four arguments:
# * $1: Name of the function that was orginally invoked (mandatory). # * $1: Name of the function that was originally invoked (mandatory).
# Necessary, to make the dynamic color-overwrite mechanism work. # Necessary, to make the dynamic color-overwrite mechanism work.
# * $2: The array index of the current segment # * $2: The array index of the current segment
# * $3: Background color # * $3: Background color
@ -337,9 +337,51 @@ prompt_background_jobs() {
fi fi
} }
# Segment that indicates usage level of current partition.
set_default POWERLEVEL9K_DISK_USAGE_ONLY_WARNING false
set_default POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
set_default POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95
prompt_disk_usage() {
local current_state="unknown"
typeset -AH hdd_usage_forecolors
hdd_usage_forecolors=(
'normal' 'yellow'
'warning' "$DEFAULT_COLOR"
'critical' 'white'
)
typeset -AH hdd_usage_backcolors
hdd_usage_backcolors=(
'normal' $DEFAULT_COLOR
'warning' 'yellow'
'critical' 'red'
)
local disk_usage="${$(\df -P . | sed -n '2p' | awk '{ print $5 }')%%\%}"
if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL" ]; then
current_state='warning'
if [ "$disk_usage" -ge "$POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL" ]; then
current_state='critical'
fi
else
if [[ "$POWERLEVEL9K_DISK_USAGE_ONLY_WARNING" == true ]]; then
current_state=''
return
fi
current_state='normal'
fi
local message="${disk_usage}%%"
# Draw the prompt_segment
if [[ -n $disk_usage ]]; then
"$1_prompt_segment" "${0}_${current_state}" "$2" "${hdd_usage_backcolors[$current_state]}" "${hdd_usage_forecolors[$current_state]}" "$message" 'DISK_ICON'
fi
}
prompt_battery() { prompt_battery() {
# The battery can have four different states - default to 'unknown'. # The battery can have four different states - default to 'unknown'.
local current_state="unknown" local current_state='unknown'
typeset -AH battery_states typeset -AH battery_states
battery_states=( battery_states=(
'low' 'red' 'low' 'red'
@ -350,43 +392,37 @@ prompt_battery() {
# Set default values if the user did not configure them # Set default values if the user did not configure them
set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10
if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then if [[ $OS =~ OSX && -f /usr/bin/pmset && -x /usr/bin/pmset ]]; then
# Pre-Grep as much information as possible to save some memory and # obtain battery information from system
# avoid pollution of the xtrace output. local raw_data="$(pmset -g batt | awk 'FNR==2{print}')"
local raw_data="$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging")"
# return if there is no battery on system # return if there is no battery on system
[[ -z $(echo $raw_data | grep MaxCapacity) ]] && return [[ -z $(echo $raw_data | grep "InternalBattery") ]] && return
# Convert time remaining from minutes to hours:minutes date string # Time remaining on battery operation (charging/discharging)
local time_remaining=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }') local tstring=$(echo $raw_data | awk -F ';' '{print $3}' | awk '{print $1}')
if [[ -n $time_remaining ]]; then # If time has not been calculated by system yet
# this value is set to a very high number when the system is calculating [[ $tstring =~ '(\(no|not)' ]] && tstring="..."
[[ $time_remaining -gt 10000 ]] && local tstring="..." || local tstring=${(f)$(/bin/date -u -r $(($time_remaining * 60)) +%k:%M)}
fi
# Get charge values
local max_capacity=$(echo $raw_data | grep MaxCapacity | awk '{ print $5 }')
local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }')
if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then # percent of battery charged
typeset -i 10 bat_percent typeset -i 10 bat_percent
bat_percent=$(( (current_capacity * 100) / max_capacity )) bat_percent=$(echo $raw_data | grep -o '[0-9]*%' | sed 's/%//')
fi
local remain="" local remain=""
# Logic for string output # Logic for string output
if [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]]; then case $(echo $raw_data | awk -F ';' '{print $2}' | awk '{$1=$1};1') in
# Battery is charging # for a short time after attaching power, status will be 'AC attached;'
if [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]]; then 'charging'|'finishing charge'|'AC attached')
current_state="charging" current_state="charging"
remain=" ($tstring)" remain=" ($tstring)"
else ;;
current_state="charged" 'discharging')
fi
else
[[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected"
remain=" ($tstring)" remain=" ($tstring)"
fi ;;
*)
current_state="charged"
;;
esac
fi fi
if [[ $OS =~ Linux ]]; then if [[ $OS =~ Linux ]]; then
@ -397,20 +433,22 @@ prompt_battery() {
# Return if no battery found # Return if no battery found
[[ -z $bat ]] && return [[ -z $bat ]] && return
local capacity=$(cat $bat/capacity)
[[ $(cat $bat/capacity) -gt 100 ]] && local bat_percent=100 || local bat_percent=$(cat $bat/capacity) local battery_status=$(cat $bat/status)
[[ $(cat $bat/status) =~ Charging ]] && local connected=true [[ $capacity -gt 100 ]] && local bat_percent=100 || local bat_percent=$capacity
[[ $(cat $bat/status) =~ Charging && $bat_percent =~ 100 ]] && current_state="charged" [[ $battery_status =~ Charging || $battery_status =~ Full ]] && local connected=true
[[ $(cat $bat/status) =~ Charging && $bat_percent -lt 100 ]] && current_state="charging"
if [[ -z $connected ]]; then if [[ -z $connected ]]; then
[[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected"
else
[[ $bat_percent =~ 100 ]] && current_state="charged"
[[ $bat_percent -lt 100 ]] && current_state="charging"
fi fi
if [[ -f /usr/bin/acpi ]]; then if [[ -f /usr/bin/acpi ]]; then
local time_remaining=$(acpi | awk '{ print $5 }') local time_remaining=$(acpi | awk '{ print $5 }')
if [[ $time_remaining =~ rate ]]; then if [[ $time_remaining =~ rate ]]; then
local tstring="..." local tstring="..."
elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then
local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M)} local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M 2> /dev/null)}
fi fi
fi fi
[[ -n $tstring ]] && local remain=" ($tstring)" [[ -n $tstring ]] && local remain=" ($tstring)"
@ -431,6 +469,79 @@ prompt_battery() {
fi fi
} }
prompt_public_ip() {
# set default values for segment
set_default POWERLEVEL9K_PUBLIC_IP_TIMEOUT "300"
set_default POWERLEVEL9K_PUBLIC_IP_NONE ""
set_default POWERLEVEL9K_PUBLIC_IP_FILE "/tmp/p9k_public_ip"
set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
# Do we need a fresh IP?
local refresh_ip=false
if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
typeset -i timediff
# if saved IP is more than
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
[[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMEOUT ]] && refresh_ip=true
# If tmp file is empty get a fresh IP
[[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true
[[ -n $POWERLEVEL9K_PUBLIC_IP_NONE ]] && [[ $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) =~ "$POWERLEVEL9K_PUBLIC_IP_NONE" ]] && refresh_ip=true
else
touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=true
fi
# grab a fresh IP if needed
if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
# if method specified, don't use fallback methods
if [[ -n $POWERLEVEL9K_PUBLIC_IP_METHOD ]] && [[ $POWERLEVEL9K_PUBLIC_IP_METHOD =~ 'wget|curl|dig' ]]; then
local method=$POWERLEVEL9K_PUBLIC_IP_METHOD
fi
if [[ -n $method ]]; then
case $method in
'dig')
if type -p dig >/dev/null; then
fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)"
[[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip
fi
;;
'curl')
if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then
fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
;;
'wget')
if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
;;
esac
else
if type -p dig >/dev/null; then
fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)"
[[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip
fi
if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then
fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
fi
# write IP to tmp file or clear tmp file if an IP was not retrieved
[[ -n $fresh_ip ]] && echo $fresh_ip > $POWERLEVEL9K_PUBLIC_IP_FILE || echo $POWERLEVEL9K_PUBLIC_IP_NONE > $POWERLEVEL9K_PUBLIC_IP_FILE
fi
# read public IP saved to tmp file
local public_ip=$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)
if [[ -n $public_ip ]]; then
$1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" 'PUBLIC_IP_ICON'
fi
}
# Context: user@hostname (who am I and where am I) # Context: user@hostname (who am I and where am I)
# Note that if $DEFAULT_USER is not set, this prompt segment will always print # Note that if $DEFAULT_USER is not set, this prompt segment will always print
prompt_context() { prompt_context() {
@ -559,6 +670,26 @@ prompt_history() {
"$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h' "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h'
} }
# Detection for virtualization (systemd based systems only)
prompt_detect_virt() {
if ! command -v systemd-detect-virt;then
return
fi
local virt=$(systemd-detect-virt)
local color="yellow"
if [[ "$virt" == "none" ]]; then
if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then
virt="chroot"
"$1_prompt_segment" "$0" "$2" "$color" "$DEFAULT_COLOR" "$virt"
else
;
fi
else
"$1_prompt_segment" "$0" "$2" "$color" "$DEFAULT_COLOR" "$virt"
fi
}
prompt_icons_test() { prompt_icons_test() {
for key in ${(@k)icons}; do for key in ${(@k)icons}; do
# The lower color spectrum in ZSH makes big steps. Choosing # The lower color spectrum in ZSH makes big steps. Choosing
@ -985,6 +1116,15 @@ prompt_pyenv() {
fi fi
} }
# Swift version
prompt_swift_version() {
# Get the first number as this is probably the "main" version number..
local swift_version=$(swift --version 2>/dev/null | grep -o -E "[0-9.]+" | head -n 1)
[[ -z "${swift_version}" ]] && return
"$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON'
}
################################################################ ################################################################
# Prompt processing and drawing # Prompt processing and drawing
################################################################ ################################################################
@ -1058,7 +1198,7 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')"
fi fi
} }
powerlevel9k_init() { prompt_powerlevel9k_setup() {
# 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) term_colors=$(echotc Co)
@ -1110,4 +1250,5 @@ powerlevel9k_init() {
add-zsh-hook precmd powerlevel9k_prepare_prompts add-zsh-hook precmd powerlevel9k_prepare_prompts
} }
powerlevel9k_init "$@" prompt_powerlevel9k_setup "$@"

Loading…
Cancel
Save