Badge does not appear in iterm2 after logging to remote GCP GCE VM Instance.

15 views
Skip to first unread message

Kaushal Shriyan

unread,
Nov 19, 2022, 6:15:48 AM11/19/22
to iterm2-discuss
Hi,

I have the below server hosted in GCP ( Google Cloud Platform) https://cloud.google.com/compute/docs/instances

$gcloud compute ssh jenkins-test to login to the remote server I get the below prompt

[kaushal@jenkins-test ~]$

[kaushal@jenkins-test ~]$ hostname
jenkins-test
[kaushal@jenkins-test ~]$
I have set badge and trigger to display text label that appears in the top right of a terminal session to provide dynamic status the current host name

Badge
\(session.username)@\(session.hostname)

Trigger
^\[(\w+)@(\w+) [~\w_.-]+\]\$    Report User & Host     \1@\2
^\[(\w+)@(\w+) [~\w_.-]+\]#    Report User & Host      \1@\2
^(\w+)@([\w]+):[\w+~_/]+\$    Report User & Host      \1@\2

But I do not see the badge as kaushal@jenkins-test appearing when i login using the below gcloud command

$gcloud compute ssh jenkins-test

Please guide me. Am I missing anything? Thanks in Advance.

Best Regards,

Kaushal

Adrian Bool

unread,
Nov 19, 2022, 8:55:28 AM11/19/22
to iterm2-discuss
Hi Kaushal,

It may be down the hostname of your GCP server.

Your regex is trying to match the hostname with \w+ (one or more word characters) but the '-' in 'jenkins-test' isn't counted as a word character; so no match:

>>> re.match(r'^\w+$', 'jenkins')
<re.Match object; span=(0, 7), match='jenkins'>
>>> re.match(r'^\w+$', 'jenkins-test')
>>>

Try a trigger of:

^\[(\S+)@(\S+) .*\]    Report User & Host     \1@\2


This seems to match your prompt:

>>> match = re.match(r'^\[(\S+)@(\S+) .*\]', '[kaushal@jenkins-test ~]')
>>> match.group(0)
'[kaushal@jenkins-test ~]'
>>> match.group(1)
'kaushal'
>>> match.group(2)
'jenkins-test'


Good luck!

aid


--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/45ed4f69-b7a4-4f71-aa68-4c50f360970bn%40googlegroups.com.

Kaushal Shriyan

unread,
Nov 19, 2022, 11:33:14 AM11/19/22
to iterm2-discuss
On Saturday, 19 November 2022 at 19:25:28 UTC+5:30 a...@logic.org.uk wrote:
Hi Kaushal,

It may be down the hostname of your GCP server.

Your regex is trying to match the hostname with \w+ (one or more word characters) but the '-' in 'jenkins-test' isn't counted as a word character; so no match:

>>> re.match(r'^\w+$', 'jenkins')
<re.Match object; span=(0, 7), match='jenkins'>
>>> re.match(r'^\w+$', 'jenkins-test')
>>>

Try a trigger of:

^\[(\S+)@(\S+) .*\]    Report User & Host     \1@\2


This seems to match your prompt:

>>> match = re.match(r'^\[(\S+)@(\S+) .*\]', '[kaushal@jenkins-test ~]')
>>> match.group(0)
'[kaushal@jenkins-test ~]'
>>> match.group(1)
'kaushal'
>>> match.group(2)
'jenkins-test'


Good luck!

aid


Thanks a lot aid and it worked perfectly. Appreciate it.

Best Regards,

Kaushal

Adrian Bool

unread,
Nov 20, 2022, 10:50:07 AM11/20/22
to iterm2-discuss

Hi,


Here's an updated regex that should match on username, hostname and directory for a number of different hosts/shells:

^\[?(\w+)@([\w\d-]+)[:\s]([\w~/ ]*[\w~/]+)\]?(?:\s%|\s#|\$|#)\s

(If you're using it for Report Directory; be sure to use "\3" as the substitution.)

I've created some test cases for it; which is now sitting on github at:


Cheers,

aid
Reply all
Reply to author
Forward
0 new messages