Last active
November 9, 2022 20:44
-
-
Save mariomui/344f3af892c6682c0b669302b19f0ff5 to your computer and use it in GitHub Desktop.
Custom Segment to detect poetry shell for p10K prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: << 'END_COMMENT' | |
Place this function in your ~/.p10k.zsh file | |
1) Detects your poetry env, (whehter or not you've entered the directory of your poetry app) | |
2) Detects whether or not shell is active. (POETRY_ACTIVE) | |
3) append my_poetry like so: | |
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( | |
... | |
my_poetry | |
) | |
so now you know if the directory you are in can be poetry shelled, | |
if you have an active poetry shell but have left the directory, and what the name of your virtualenv is when you | |
are shelled and inside the active dev directory. | |
Prolly can refactor the poetry_active stuff to some kindah binarry representation | |
IN-ROOT SHELL-ACTIVE HUD-TEXT | |
1 1 [VIRTUAL-ENV-NAME active] | |
1. 0 poetry inactive | |
0. 1 poetry is still running | |
END_COMMENT | |
function prompt_my_poetry() { | |
local POETRY_ENV="$(poetry env list | grep -e Activated | sed 's/ .*//' | head -1)" | |
if [ ! -z ${POETRY_ENV} ] && [ -z ${POETRY_ACTIVE} ] | |
then | |
p10k segment -b 1 -f 3 -i '⭐' -t "poerty inactive" | |
elif [ ! -z ${POETRY_ENV} ] && [ ! -z $POETRY_ACTIVE ] | |
then | |
p10k segment -b 2 -f 3 -i '⭐' -t "$POETRY_ENV active" | |
elif [ -z ${POETRY_ENV} ] && [ ! -z $POETRY_ACTIVE ] | |
then | |
# if your shell is active and you are outside of the folder. | |
p10k segment -b 3 -f 0 -i '⭐' -t "POETRY is still running" | |
fi | |
if | |
then | |
else | |
fi | |
#bg is background, setting that to 0 to 255 | |
#fg is foreground | |
# i is icon | |
# t is text | |
# https://robotmoon.com/256-colors/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment