#!/usr/bin/env bash

# ssh_segment

# Set default symbols if not already defined in config
# Defaults should be standard symbols.
[[ -z ${PL_SYMBOLS[ssh]} ]] && PL_SYMBOLS[ssh]='╤'

# -----------------------------------------------------------------------------
# append to prompt: indicate if SSH session
# arg: $1 foreground color
# arg: $2 background color
# option variables;
#   PL_SSH_SHOW_HOST: true/false to show host name/ip
#   PL_SSH_USE_IP: true/false to show IP instead of hostname
function ssh_segment {
    if [[ "${SSH_CLIENT}" || "${SSH_TTY}" ]]; then
        local bg_color="$1"
        local fg_color="$2"
        local content="${PL_SYMBOLS[ssh]}"
        if [ "$PL_SSH_SHOW_HOST" = true ]; then
            if [ "$PL_SSH_USE_IP" = true ]; then
                content+=" $(ip_address)"
            else
                content+=" \h"
            fi
        fi
        PS1+="$(segment_end "$fg_color" "$bg_color")"
        PS1+="$(segment_content "$fg_color" "$bg_color" " $content ")"
        __last_color="$bg_color"
    fi
}

