anki-code / xontrib-prompt-bar

The bar prompt for xonsh shell with customizable sections and Starship support.
BSD 2-Clause "Simplified" License
49 stars 2 forks source link

Creating a field from env var #2

Closed hemna closed 3 years ago

hemna commented 3 years ago

I have an environment var that I change quite a bit and wanted to have the value show up on the bar, but it doesn't seem to update.

Parts of my ~/.xonshrc

...
$PROMPT_FIELDS['ccloud'] = __xonsh__.env.get("CCLOUD_NAME", None)
$XONTRIB_PROMPT_BAR_RIGHT = '{ccloud#section}{env_name#section}{gitstatus_noc#section}{date_time_tz}'

If source ~/.xonshrc then the value gets updated, but if I just change the env var $CCLOUD_NAME, then it doesn't get updated.

hemna commented 3 years ago

I was able to get it working by making it a function

def _cloud_name():
    return __xonsh__.env.get("CCLOUD_NAME", None)

$PROMPT_FIELDS['ccloud'] = _cloud_name
anki-code commented 3 years ago

Yep! The lambda also works:

$PROMPT_FIELDS['ccloud'] = lambda: __xonsh__.env.get("CCLOUD_NAME", None)

If you like prompt-bar please star the repo :)