Forked from manekinekko/spaceship-prompt__sections__angular.zsh
Last active
March 30, 2019 00:31
-
-
Save nweldev/600f69b7bc8464ca67005a35eb0f7bb3 to your computer and use it in GitHub Desktop.
Customize your Oh My Zsh SpaceShip theme with Angular and AngularCLI prompt (https://github.com/denysdovhan/spaceship-prompt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ANGULAR | |
SPACESHIP_ANGULAR_SHOW="${SPACESHIP_ANGULAR_SHOW:=true}" | |
SPACESHIP_ANGULAR_PREFIX="${SPACESHIP_ANGULAR_PREFIX:="with "}" | |
SPACESHIP_ANGULAR_SUFFIX="${SPACESHIP_ANGULAR_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}" | |
SPACESHIP_ANGULAR_SYMBOL="${SPACESHIP_ANGULAR_SYMBOL:="🅰️ "}" | |
SPACESHIP_ANGULAR_DEFAULT_VERSION="${SPACESHIP_ANGULAR_DEFAULT_VERSION:=""}" | |
SPACESHIP_ANGULAR_COLOR="${SPACESHIP_ANGULAR_COLOR:="red"}" | |
SPACESHIP_ANGULAR_CLI_SHOW="${SPACESHIP_ANGULAR_CLI_SHOW:=true}" | |
SPACESHIP_ANGULAR_CLI_PREFIX="${SPACESHIP_ANGULAR_CLI_PREFIX:=""}" | |
SPACESHIP_ANGULAR_CLI_SUFFIX="${SPACESHIP_ANGULAR_CLI_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}" | |
SPACESHIP_ANGULAR_CLI_SYMBOL="${SPACESHIP_ANGULAR_CLI_SYMBOL:="🛠️ "}" | |
SPACESHIP_ANGULAR_CLI_DEFAULT_VERSION="${SPACESHIP_ANGULAR_CLI_DEFAULT_VERSION:=""}" | |
SPACESHIP_ANGULAR_CLI_COLOR="${SPACESHIP_ANGULAR_CLI_COLOR:="red"}" | |
SPACESHIP_ANGULAR_DEVKIT_SHOW="${SPACESHIP_ANGULAR_DEVKIT_SHOW:=true}" | |
SPACESHIP_ANGULAR_DEVKIT_PREFIX="${SPACESHIP_ANGULAR_DEVKIT_PREFIX:="with "}" | |
SPACESHIP_ANGULAR_DEVKIT_SUFFIX="${SPACESHIP_ANGULAR_DEVKIT_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}" | |
SPACESHIP_ANGULAR_DEVKIT_SYMBOL="${SPACESHIP_ANGULAR_DEVKIT_SYMBOL:="🅰️🔧 "}" | |
SPACESHIP_ANGULAR_DEVKIT_DEFAULT_VERSION="${SPACESHIP_ANGULAR_DEVKIT_DEFAULT_VERSION:=""}" | |
SPACESHIP_ANGULAR_DEVKIT_COLOR="${SPACESHIP_ANGULAR_DEVKIT_COLOR:="red"}" | |
_get_angular_version() { | |
local pkg_path="node_modules/$1/package.json" | |
if [[ -f "$pkg_path" ]]; then | |
local pkg_version=$(grep -E '"version": "v?([0-9]+\.){1,}' "$pkg_path" | cut -d\" -f4 2> /dev/null) | |
fi | |
if [[ $pkg_version ]]; then | |
echo $pkg_version | |
else | |
node -p "r=require('./package.json'); r.devDependencies['$1'] || r.dependencies['$1']" 2>/dev/null | |
fi | |
} | |
spaceship_angular() { | |
[[ $SPACESHIP_ANGULAR_SHOW == false ]] && return | |
# Show ANGULAR status only inside an NODE/NPM project | |
# [[ -f package.json || -d node_modules ]] && return | |
local angular_version=$(_get_angular_version "@angular/core") | |
[[ $angular_version == "undefined" || $angular_version == "" ]] && return | |
# SPACESHIP_ANGULAR_PREFIX="(" | |
# SPACESHIP_ANGULAR_SYMBOL="@angular/core@" | |
# SPACESHIP_ANGULAR_SUFFIX=") " | |
spaceship::section \ | |
"$SPACESHIP_ANGULAR_COLOR" \ | |
"$SPACESHIP_ANGULAR_PREFIX" \ | |
"${SPACESHIP_ANGULAR_SYMBOL}v${angular_version}" \ | |
"$SPACESHIP_ANGULAR_SUFFIX" | |
} | |
spaceship_angular_cli() { | |
[[ $SPACESHIP_ANGULAR_CLI_SHOW == false ]] && return | |
# Show ANGULAR status only inside an NODE/NPM project | |
# [[ -f package.json || -d node_modules ]] && return | |
local angular_cli_version=$(_get_angular_version "@angular/cli") | |
[[ $angular_cli_version == "undefined" || $angular_cli_version == "" ]] && return | |
# SPACESHIP_ANGULAR_CLI_PREFIX="(" | |
# SPACESHIP_ANGULAR_CLI_SYMBOL="@angular/cli@" | |
# SPACESHIP_ANGULAR_CLI_SUFFIX=") " | |
spaceship::section \ | |
"$SPACESHIP_ANGULAR_CLI_COLOR" \ | |
"$SPACESHIP_ANGULAR_CLI_PREFIX" \ | |
"${SPACESHIP_ANGULAR_CLI_SYMBOL}v${angular_cli_version}" \ | |
"$SPACESHIP_ANGULAR_CLI_SUFFIX" | |
} | |
spaceship_angular_devkit() { | |
[[ $SPACESHIP_ANGULAR_CLI_SHOW == false ]] && return | |
# Show ANGULAR status only inside an NODE/NPM project | |
# [[ -f package.json || -d node_modules ]] && return | |
# Show ANGULAR-DEVKIT status only if not inside an ANGULAR project | |
local angular_cli_version=$(_get_angular_version "@angular/core") | |
[[ $angular_cli_version != "undefined" && $angular_cli_version != "" ]] && return | |
local angular_devkit_version=$(_get_angular_version "@angular-devkit/core") | |
[[ $angular_devkit_version == "undefined" || $angular_devkit_version == "" ]] && return | |
# SPACESHIP_ANGULAR_CLI_PREFIX="(" | |
# SPACESHIP_ANGULAR_CLI_SYMBOL="@angular/cli@" | |
# SPACESHIP_ANGULAR_CLI_SUFFIX=") " | |
spaceship::section \ | |
"$SPACESHIP_ANGULAR_DEVKIT_COLOR" \ | |
"$SPACESHIP_ANGULAR_DEVKIT_PREFIX" \ | |
"${SPACESHIP_ANGULAR_DEVKIT_SYMBOL}v${angular_devkit_version}" \ | |
"$SPACESHIP_ANGULAR_DEVKIT_SUFFIX" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment