diff options
-rw-r--r-- | CHANGELOG.md | 8 | ||||
-rw-r--r-- | README.md | 122 | ||||
-rw-r--r-- | functions/icons.zsh | 19 | ||||
-rw-r--r-- | functions/vcs.zsh | 15 | ||||
-rwxr-xr-x | powerlevel9k.zsh-theme | 197 |
5 files changed, 272 insertions, 89 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ae0c77..8060e0fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## next + +### `dir` changes + +Added an option to configure the path separator. If you want something +else than an ordinary slash, you could set +`POWERLEVEL9K_DIR_PATH_SEPARATOR` to whatever you want. + ## v0.5.0 ### `load` and `ram` changes @@ -76,10 +76,10 @@ variables to your `~/.zshrc`. So if you wanted to set these variables manually, you would put the following in your `~/.zshrc`: - - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) - POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) - +```zsh +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) +POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) +``` #### Available Prompt Segments The segments that are currently available are: @@ -90,6 +90,7 @@ The segments that are currently available are: * [`dir`](#dir) - Your current working directory. * `history` - The command number for the current line. * [`ip`](#ip) - Shows the current IP address. +* [`public_ip`](#public_ip) - Shows your public IP address. * `load` - Your machine's load averages. * `os_icon` - Display a nice little icon, depending on your operating system. * `ram` - Show free RAM. @@ -123,6 +124,8 @@ The segments that are currently available are: * [`rspec_stats`](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec. * **Rust Segments:** * `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:** * **AWS Segments:** @@ -134,6 +137,7 @@ The segments that are currently available are: * [`custom_command`](#custom_command) - Create a custom segment to display the output of an arbitrary command. * [`todo`](http://todotxt.com/) - Shows the number of tasks in your todo.txt tasks file. +* `detect-virt` - Virtualization detection with systemd --------------------------------------------------------------------------------- @@ -198,28 +202,28 @@ The `custom_...` segment allows you to turn the output of a custom command into a prompt segment. As an example, if you wanted to create a custom segment to display your WiFi signal strength, you might define a custom segment called `custom_wifi_signal` like this: - - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="echo signal: \$(nmcli device wifi | grep yes | awk '{print \$8}')" - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="blue" - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="yellow" - +```zsh +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="echo signal: \$(nmcli device wifi | grep yes | awk '{print \$8}')" +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="blue" +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="yellow" +``` If you prefer, you can also define the function in your `.zshrc` rather than putting it in-line with the variable export, as shown above. Just don't forget to invoke your function from your segment! Example code that achieves the same result as the above: +```zsh +zsh_wifi_signal(){ + local signal=$(nmcli device wifi | grep yes | awk '{print $8}') + local color='%F{yellow}' + [[ $signal -gt 75 ]] && color='%F{green}' + [[ $signal -lt 50 ]] && color='%F{red}' + echo -n "%{$color%}\uf230 $signal%{%f%}" # \uf230 is +} - zsh_wifi_signal(){ - local signal=$(nmcli device wifi | grep yes | awk '{print $8}') - local color='%F{yellow}' - [[ $signal -gt 75 ]] && color='%F{green}' - [[ $signal -lt 50 ]] && color='%F{red}' - echo -n "%{$color%}\uf230 $signal%{%f%}" # \uf230 is - } - - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="zsh_wifi_signal" - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) - +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="zsh_wifi_signal" +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) +``` The command, above, gives you the wireless signal segment shown below: ![signal](http://i.imgur.com/hviMATC.png) @@ -237,9 +241,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 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 | |----------|---------------|-------------| |`DEFAULT_USER`|None|Username to consider a "default context" (you can also use `$USER`)| +|`POWERLEVEL9K_CONTEXT_HOST_DEPTH`|%m|Customizable host depth on prompt| ##### dir @@ -253,11 +265,11 @@ Powerline" fonts, there are additional glyphs, as well: | None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183452/40f79286-b58f-11e5-9b8c-ed1343a07b08.png) | Outside of your home folder | To turn off these icons you could set these variables to an empty string. - - POWERLEVEL9K_HOME_ICON='' - POWERLEVEL9K_HOME_SUB_ICON='' - POWERLEVEL9K_FOLDER_ICON='' - +```zsh +POWERLEVEL9K_HOME_ICON='' +POWERLEVEL9K_HOME_SUB_ICON='' +POWERLEVEL9K_FOLDER_ICON='' +``` You can limit the output to a certain length by truncating long paths. Customizations available are: @@ -269,11 +281,11 @@ Customizations available are: 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: - - POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 - POWERLEVEL9K_SHORTEN_DELIMITER="" - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" - +```zsh +POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 +POWERLEVEL9K_SHORTEN_DELIMITER="" +POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" +``` In each case you have to specify the length you want to shorten the directory to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in others whole directories. @@ -288,6 +300,12 @@ The `truncate_with_package_name` strategy gives your directory path relative to the path shown would be `my-cool-project`. If you navigate to `$HOME/projects/my-project/src`, then the path shown would be `my-cool-project/src`. Please note that this currently looks for `.git` directory to determine the root of the project. +If you want to customize the directory separator, you could set: +```zsh +# You'll need patched awesome-terminal fonts for that example +POWERLEVEL9K_DIR_PATH_SEPARATOR="%f "$'\uE0B1'" %F" +``` + ##### ip This segment tries to examine all currently used network interfaces and prints @@ -298,6 +316,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`.| +##### 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 This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack. @@ -317,7 +358,8 @@ This segment shows the return code of the last command. | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to hide this segment when the last command completed successfully.| +|`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to not show the error code when the last command returned an error and optionally hide this segment when the last command completed successfully by setting `POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE` to false.| +|`POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE`|`false`|Set to true if you wish to show this segment when the last command completed successfully in non-verbose mode.| ##### ram @@ -336,16 +378,16 @@ See [Unit Test Ratios](#unit-test-ratios), below. |`POWERLEVEL9K_TIME_FORMAT`|`'H:M:S'`|ZSH time format to use in this segment.| As an example, if you wanted a reversed time format, you would use this: - - # Reversed time format - POWERLEVEL9K_TIME_FORMAT='%D{%S:%M:%H}' - +```zsh +# Reversed time format +POWERLEVEL9K_TIME_FORMAT='%D{%S:%M:%H}' +``` If you are using an "Awesome Powerline Font", you can add a time symbol to this segment, as well: - - # Output time, date, and a symbol from the "Awesome Powerline Font" set - POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}" - +```zsh +# Output time, date, and a symbol from the "Awesome Powerline Font" set +POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}" +``` ##### vcs By default, the `vcs` segment will provide quite a bit of information. Further diff --git a/functions/icons.zsh b/functions/icons.zsh index 575d1f5f..43847427 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -68,10 +68,15 @@ case $POWERLEVEL9K_MODE in VCS_BRANCH_ICON $'\uE220 ' # VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_GIT_ICON $'\uE20E ' # + VCS_GIT_GITHUB_ICON $'\uE20E ' # + VCS_GIT_BITBUCKET_ICON $'\uE20E ' # + VCS_GIT_GITLAB_ICON $'\uE20E ' # VCS_HG_ICON $'\uE1C3 ' # VCS_SVN_ICON '(svn) ' RUST_ICON '' PYTHON_ICON $'\U1F40D' # 🐍 + SWIFT_ICON '' + PUBLIC_IP_ICON '' ) ;; 'awesome-fontconfig') @@ -121,11 +126,16 @@ case $POWERLEVEL9K_MODE in VCS_COMMIT_ICON $'\uF221 ' # VCS_BRANCH_ICON $'\uF126 ' # 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_SVN_ICON '(svn) ' RUST_ICON $'\uE6A8' # PYTHON_ICON $'\U1F40D' # 🐍 + SWIFT_ICON '' + PUBLIC_IP_ICON '' ) ;; *) @@ -176,10 +186,15 @@ case $POWERLEVEL9K_MODE in VCS_BRANCH_ICON $'\uE0A0 ' # VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_GIT_ICON '' + VCS_GIT_GITHUB_ICON '' + VCS_GIT_BITBUCKET_ICON '' + VCS_GIT_GITLAB_ICON '' VCS_HG_ICON '' VCS_SVN_ICON '' - RUST_ICON '' + RUST_ICON '' PYTHON_ICON '' + SWIFT_ICON 'Swift' + PUBLIC_IP_ICON '' ) ;; esac diff --git a/functions/vcs.zsh b/functions/vcs.zsh index a0aa2b6c..5defa9bc 100644 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -62,7 +62,7 @@ function +vi-git-remotebranch() { set_default POWERLEVEL9K_VCS_HIDE_TAGS false function +vi-git-tagname() { - if [[ "$POWERLEVE9K_VCS_HIDE_TAGS" == "false" ]]; then + if [[ "$POWERLEVEL9K_VCS_HIDE_TAGS" == "false" ]]; then # If we are on a tag, append the tagname to the current branch string. local tag tag=$(git describe --tags --exact-match HEAD 2>/dev/null) @@ -110,7 +110,18 @@ function +vi-hg-bookmarks() { function +vi-vcs-detect-changes() { if [[ "${hook_com[vcs]}" == "git" ]]; then - vcs_visual_identifier='VCS_GIT_ICON' + + 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' + fi + elif [[ "${hook_com[vcs]}" == "hg" ]]; then vcs_visual_identifier='VCS_HG_ICON' elif [[ "${hook_com[vcs]}" == "svn" ]]; then diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d56e46f4..c3f2be74 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -339,7 +339,7 @@ prompt_background_jobs() { prompt_battery() { # The battery can have four different states - default to 'unknown'. - local current_state="unknown" + local current_state='unknown' typeset -AH battery_states battery_states=( 'low' 'red' @@ -350,43 +350,37 @@ prompt_battery() { # Set default values if the user did not configure them set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 - if [[ $OS =~ OSX && -f /usr/sbin/ioreg && -x /usr/sbin/ioreg ]]; then - # Pre-Grep as much information as possible to save some memory and - # avoid pollution of the xtrace output. - local raw_data="$(ioreg -n AppleSmartBattery | grep -E "MaxCapacity|TimeRemaining|CurrentCapacity|ExternalConnected|IsCharging")" + if [[ $OS =~ OSX && -f /usr/bin/pmset && -x /usr/bin/pmset ]]; then + # obtain battery information from system + local raw_data="$(pmset -g batt | awk 'FNR==2{print}')" # return if there is no battery on system - [[ -z $(echo $raw_data | grep MaxCapacity) ]] && return - - # Convert time remaining from minutes to hours:minutes date string - local time_remaining=$(echo $raw_data | grep TimeRemaining | awk '{ print $5 }') - if [[ -n $time_remaining ]]; then - # this value is set to a very high number when the system is calculating - [[ $time_remaining -gt 10000 ]] && local tstring="..." || local tstring=${(f)$(/bin/date -u -r $(($time_remaining * 60)) +%k:%M)} - fi + [[ -z $(echo $raw_data | grep "InternalBattery") ]] && return - # 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 }') + # Time remaining on battery operation (charging/discharging) + local tstring=$(echo $raw_data | awk -F ';' '{print $3}' | awk '{print $1}') + # If time has not been calculated by system yet + [[ $tstring =~ '(\(no|not)' ]] && tstring="..." - if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then - typeset -i 10 bat_percent - bat_percent=$(( (current_capacity * 100) / max_capacity )) - fi + # percent of battery charged + typeset -i 10 bat_percent + bat_percent=$(echo $raw_data | grep -o '[0-9]*%' | sed 's/%//') local remain="" # Logic for string output - if [[ $(echo $raw_data | grep ExternalConnected | awk '{ print $5 }') =~ "Yes" ]]; then - # Battery is charging - if [[ $(echo $raw_data | grep IsCharging | awk '{ print $5 }') =~ "Yes" ]]; then + case $(echo $raw_data | awk -F ';' '{print $2}' | awk '{$1=$1};1') in + # for a short time after attaching power, status will be 'AC attached;' + 'charging'|'finishing charge'|'AC attached') current_state="charging" remain=" ($tstring)" - else + ;; + 'discharging') + [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" + remain=" ($tstring)" + ;; + *) current_state="charged" - fi - else - [[ $bat_percent -lt $POWERLEVEL9K_BATTERY_LOW_THRESHOLD ]] && current_state="low" || current_state="disconnected" - remain=" ($tstring)" - fi + ;; + esac fi if [[ $OS =~ Linux ]]; then @@ -411,7 +405,7 @@ prompt_battery() { local time_remaining=$(acpi | awk '{ print $5 }') if [[ $time_remaining =~ rate ]]; then local tstring="..." - elif [[ $time_remaining =~ "[:digit:]+" ]]; then + elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M 2> /dev/null)} fi fi @@ -433,15 +427,89 @@ prompt_battery() { 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) # Note that if $DEFAULT_USER is not set, this prompt segment will always print prompt_context() { + set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m" if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then if [[ $(print -P "%#") == '#' ]]; then # Shell runs as root - "$1_prompt_segment" "$0_ROOT" "$2" "$DEFAULT_COLOR" "yellow" "$USER@%m" + "$1_prompt_segment" "$0_ROOT" "$2" "$DEFAULT_COLOR" "yellow" "$USER@$POWERLEVEL9K_CONTEXT_HOST_DEPTH" else - "$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@%m" + "$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@$POWERLEVEL9K_CONTEXT_HOST_DEPTH" fi fi } @@ -458,6 +526,7 @@ prompt_custom() { } # Dir: current working directory +set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" prompt_dir() { local current_path='%~' if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then @@ -503,17 +572,25 @@ prompt_dir() { current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; esac + fi + if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then + current_path=$(print -P "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g") fi - local current_icon='' + typeset -AH dir_states + dir_states=( + "DEFAULT" "FOLDER_ICON" + "HOME" "HOME_ICON" + "HOME_SUBFOLDER" "HOME_SUB_ICON" + ) + local current_state="DEFAULT" if [[ $(print -P "%~") == '~' ]]; then - "$1_prompt_segment" "$0_HOME" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_ICON' + current_state="HOME" elif [[ $(print -P "%~") == '~'* ]]; then - "$1_prompt_segment" "$0_HOME_SUBFOLDER" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_SUB_ICON' - else - "$1_prompt_segment" "$0_DEFAULT" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'FOLDER_ICON' + current_state="HOME_SUBFOLDER" fi + "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}" } # Docker machine @@ -540,6 +617,26 @@ prompt_history() { "$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() { for key in ${(@k)icons}; do # The lower color spectrum in ZSH makes big steps. Choosing @@ -750,17 +847,16 @@ prompt_rvm() { # Status: return code if verbose, otherwise just an icon if an error occurred set_default POWERLEVEL9K_STATUS_VERBOSE true +set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false prompt_status() { - if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then - if [[ "$RETVAL" -ne 0 ]]; then + if [[ "$RETVAL" -ne 0 ]]; then + if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL" 'CARRIAGE_RETURN_ICON' else - "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "046" "" 'OK_ICON' - fi - else - if [[ "$RETVAL" -ne 0 ]]; then "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' fi + elif [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then + "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "046" "" 'OK_ICON' fi } @@ -967,6 +1063,17 @@ prompt_pyenv() { fi } +# Swift version +prompt_swift_version() { + local swift_version=($(swift --version 2>/dev/null)) + [[ -z "${swift_version}" ]] && return + + # Extract semantic version + swift_version=$(echo ${swift_version} | sed -e 's/[^0-9.]*\([0-9.]*\).*/\1/') + + "$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON' +} + ################################################################ # Prompt processing and drawing ################################################################ @@ -1040,7 +1147,7 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" fi } -powerlevel9k_init() { +prompt_powerlevel9k_setup() { # Display a warning if the terminal does not support 256 colors local term_colors term_colors=$(echotc Co) @@ -1092,5 +1199,5 @@ powerlevel9k_init() { add-zsh-hook precmd powerlevel9k_prepare_prompts } -powerlevel9k_init "$@" +prompt_powerlevel9k_setup "$@" |