Environment variables in the new status bar

227 views
Skip to first unread message

Walter Dörwald

unread,
Aug 2, 2019, 6:51:57 AM8/2/19
to iterm2-discuss
Hi all!

The new status bar in 3.3 is really great!

I was trying to have a status bar component that displays an environment variable (in my case Python's $VIRTUAL_ENV variable). After many tries I've managed to do that via user variables and an "Interpolated String" component.

I'm using zsh, so in my .zshrc I'm setting the user variable pyvenv from the environment variable like this:

precmd()
{
    iterm2_set_user_var pyvenv $
(basename ${VIRTUAL_ENV:-none})
}


And then I'm defining an "Interpolated String" component with the string value:

🐍 \(user.pyvenv)

Which gives me the result I want.

Is this the best approach, or is there a more direct method?

Servus,
   Walter

George Nachman

unread,
Aug 2, 2019, 11:59:17 AM8/2/19
to iterm2-...@googlegroups.com
You're close. Since it seems like you're using shell integration, you should write a function called iterm2_print_user_vars to avoid clobbering precmd.

function iterm2_print_user_vars() {

    iterm2_set_user_var pyvenv $(basename ${VIRTUAL_ENV:-none})
}

If you're not using shell integration, then precmd is the right way to do it.

--
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/b2eba209-c693-4604-9c29-f72686954f32%40googlegroups.com.

Walter Dörwald

unread,
Aug 5, 2019, 11:18:50 AM8/5/19
to iterm2-discuss
Am Freitag, 2. August 2019 17:59:17 UTC+2 schrieb George Nachman:
You're close. Since it seems like you're using shell integration, you should write a function called iterm2_print_user_vars to avoid clobbering precmd.

function iterm2_print_user_vars() {
    iterm2_set_user_var pyvenv $(basename ${VIRTUAL_ENV:-none})
}

If you're not using shell integration, then precmd is the right way to do it.

That worked, thanks!

Servus,
   Walter

Reply all
Reply to author
Forward
0 new messages