started working from my phone with ssh and termux so I can bedrot and develop, but was having issues with the screen size whith some of my descriptive mamba env names and long paths. figured I'd share my solution in case somebody asks gpt later so that Sam Altman takes the credit
throw this code directly into bashrc towards the top, and it will drop you to a new line if the prompt gets too long. The function runs with each command so if you cd too greedily and too deep, the command line input will be on a newline instead of inline. Once you are back at root the prompt will be inline again. Goes by the actual length of the entire prompt regardless of where the text is from. You still see the venv and conda text like normal, which tends not to be the case when PS1 gets edited. So now when you scroll up you don't have any partial words after long terminal promts, but you also don't have short commands that don't need a newline
conditional terminal prompt
update_ps1() {
# the number of columns before repl drops a line local threshold=55 # default is white # local colour='34' # blue # local colour='32' # dark green local colour='92' # green # local colour='33' # yellow # local colour='31' # dark red # local colour='91' # red # whether the user@host is bold, hard to notice tbf local bold='1' # local bold='0' local venv="" if [ -n "$VIRTUAL_ENV" ]; then venv="($VIRTUAL_ENV_PROMPT) " fi if [ "$(echo "${PS1@P}" | wc -m)" -lt "$threshold" ]; then PS1="${CONDA_PROMPT_MODIFIER}$venv\e["$bold\;$colour"m$(whoami)@$(uname -n)\e[0m:\e[0"$colour"m \w\e[0m $ " else PS1="${CONDA_PROMPT_MODIFIER}$venv\e["$bold\;$colour"m$(whoami)@$(uname -n)\e[0m:\e[0"$colour"m \w\e[0m\n $ " fi }; PROMPT_COMMAND="update_ps1${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
[link] [comments]
SOCIAL SHARE CARD GENERATOR