Skip to content

Instantly share code, notes, and snippets.

@otonielguajardo
Last active September 1, 2024 19:12
Show Gist options
  • Save otonielguajardo/2c04ff30f81c01723869280211fc4e82 to your computer and use it in GitHub Desktop.
Save otonielguajardo/2c04ff30f81c01723869280211fc4e82 to your computer and use it in GitHub Desktop.
ohmyzh plugin that creates a phpver_prompt_info function that you can use in your theme to display your current version of php
# ohmyzh plugin that creates a phpver_prompt_info function that you can use in your theme to display your current version of php
# It uses two variables to control how that is shown:
# ZSH_THEME_PHPVER_PREFIX: sets the prefix of the PHPVER. Defaults to [
# ZSH_THEME_PHPVER_SUFFIX: sets the suffix of the PHPVER. Defaults to ]
function phpver_prompt_info(){
if [[ -f "composer.json" ]]; then
if php_version=$(/usr/bin/env php --version 2>/dev/null); then
PHPVER="$(echo "$php_version" | awk 'NR==1 {split($2, version_parts, "."); print version_parts[1] "." version_parts[2]}')"
fi
fi
[[ -n ${PHPVER} ]] || return
echo "${ZSH_THEME_PHPVER_PREFIX=[}${PHPVER:t:gs/%/%%}${ZSH_THEME_PHPVER_SUFFIX=]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment