Sinds een tijdje maak ik gebruik van starship om mijn shell wat meer mogelijkheden te geven. Hiervoor had ik Starship zo ingesteld dat je (bijna) geen verschil zag met de normale shell instelling, maar na een tijdje begon het toch te kriebelen.

Inmiddels ziet mijn shell ($PS1) er zo uit:

Starship prompt

De configuratie (~/.config/starship.toml ziet er als volgt uit)

format = """\
${custom.ssh-detection}$username\
[ at ](italic gray)\
$hostname\
[ in ](italic gray)\
$directory\
$git_branch$git_status
$character
"""
add_newline = true
continuation_prompt = '[>>](gray) '

[custom.ssh-detection]
command = '/usr/local/bin/ssh-connection-helper.sh'
when = ''' env | grep SSH_CONNECTION '''
format = '[$output]($style) '
style = 'bold yellow'

[username]
format = '[$user]($style)'
show_always = true
style_root = 'red'
style_user = 'gray'

[hostname]
format = '[$hostname]($style)'
ssh_only = false
style = 'gray'

[directory]
format = '[$path]($style)[$read_only]($read_only_style)'
#style = 'bold blue'
style = 'bold #3B6EA5'
read_only = ' (ro)'
read_only_style = 'bold red'

[git_branch]
format = ' [on](italic gray) [$symbol$branch(:$remote_branch)]($style) '

[character]
format = '$symbol '
success_symbol = '[\$](gray)'
error_symbol = '[\$](bold red)'

Het genoemde script in /usr/local/bin/ssh-connection-helper.sh ziet er als volgt uit:

#!/usr/bin/bash

# Get the IP that is connected from the environment variable SSH_CONNECTION
ipaddr=$(env | grep SSH_CONNECTION | cut -d '=' -f2 | awk '{print $1}')

echo "(SSH from ${ipaddr})"