Skip to content

Powerline10k

Powerline10k is a ZSH theme, which introduces Segments (small pieces of context) to the prompt.

The source code, Installation Instructions and Examples can be found on the Github Page.

P10k allow you to create your own custom segments, for functionality not provided within the core.

Hetzner Hcloud Context

A simple segment that displays the currently active Hcloud context.

Example of the Hetzner Hcloud Context

zsh
#!/usr/bin/env zsh
# File: ~/.config/.p10k/prompt-hcloud_ctx.zsh
function prompt_hcloud_ctx() {
  local _hcloud_context
  # [[ -z $_hcloud_context ]] && _hcloud_context=$(hcloud context list | awk '$1 ~ /^\*/ {print $2}')
  [[ -z $_hcloud_context ]] && _hcloud_context=$(awk -F\" '$1 ~ /^active_context/{print $2}' ~/.config/hcloud/cli.toml)
  [[ -n $_hcloud_context ]] || return
  p10k segment -f red3 -i 'H' -t "$_hcloud_context"
}

Magento Version

A segment, that displays the relevant Magento project version parsed from the composer files.

Example of the Magento version Context

zsh
#!/usr/bin/env zsh
# File: ~/.config/.p10k/prompt-magento-ver.zsh
function prompt_magento_version() {
  _p9k_upglob 'composer.(json|lock)' && return
  local dir=$_p9k__parent_dirs[$?]
  local lock=$dir/composer.lock
  local json=$dir/composer.json

  if [[ -r $lock ]]; then
    if ! _p9k_cache_stat_get $0 $lock; then
      local v=$(grep -E -A1 "\"name\": \"magento/product-(community|enterprise)-edition\"" "$lock" 2> /dev/null | awk -F\" 'END{print $4}')
      _p9k_cache_stat_set "$v"
    fi
  elif [[ -r $json ]]; then
    if ! _p9k_cache_stat_get $0 $json; then
      local v=$(grep -E 'magento/product-(community|enterprise)-edition' "$json" 2> /dev/null | awk -F\" '{print $4}')
      _p9k_cache_stat_set "$v"
    fi
  fi

  [[ -n $_p9k__cache_val[1] ]] || return
  p10k segment -f orangered1 -i '' -t "${_p9k__cache_val[1]}"
}