From 21a5cbd988531b5ca08afb6863f22e592170cdef Mon Sep 17 00:00:00 2001 From: Thomas Paul Mann Date: Thu, 1 Dec 2016 21:21:05 +0100 Subject: [PATCH] Add prompt for current installed swift version --- README.md | 2 ++ functions/icons.zsh | 3 +++ powerlevel9k.zsh-theme | 12 +++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d031706..b6769354 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,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:** diff --git a/functions/icons.zsh b/functions/icons.zsh index 2f30cff2..bd1cfa06 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -72,6 +72,7 @@ case $POWERLEVEL9K_MODE in VCS_SVN_ICON '(svn) ' RUST_ICON '' PYTHON_ICON $'\U1F40D' # 🐍 + SWIFT_ICON '' ) ;; 'awesome-fontconfig') @@ -126,6 +127,7 @@ case $POWERLEVEL9K_MODE in VCS_SVN_ICON '(svn) ' RUST_ICON $'\uE6A8' #  PYTHON_ICON $'\U1F40D' # 🐍 + SWIFT_ICON '' ) ;; *) @@ -180,6 +182,7 @@ case $POWERLEVEL9K_MODE in VCS_SVN_ICON '' RUST_ICON '' PYTHON_ICON '' + SWIFT_ICON 'Swift' ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c06d1286..64662144 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -965,6 +965,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 ################################################################ @@ -1091,4 +1102,3 @@ powerlevel9k_init() { } powerlevel9k_init "$@" -