Last active
December 5, 2021 10:20
-
-
Save sam016/9b2b51d1f9ea7d6840f60e4b04e4f18e to your computer and use it in GitHub Desktop.
oh-my-bash's `Font.theme.sh` to enable conda env name
This file contains hidden or 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
#!/usr/bin/env bash | |
# | |
# One line prompt showing the following configurable information | |
# for git: | |
# time (virtual_env) username@hostname pwd git_char|git_branch git_dirty_status|→ | |
# | |
# The → arrow shows the exit status of the last command: | |
# - bold green: 0 exit status | |
# - bold red: non-zero exit status | |
# | |
# Example outside git repo: | |
# 07:45:05 user@host ~ → | |
# | |
# Example inside clean git repo: | |
# 07:45:05 user@host .oh-my-bash ±|master|→ | |
# | |
# Example inside dirty git repo: | |
# 07:45:05 user@host .oh-my-bash ±|master ✗|→ | |
# | |
# Example with virtual environment: | |
# 07:45:05 (venv) user@host ~ → | |
# | |
SCM_NONE_CHAR='' | |
SCM_THEME_PROMPT_DIRTY=" ${red}✗" | |
SCM_THEME_PROMPT_CLEAN="" | |
SCM_THEME_PROMPT_PREFIX="${green}|" | |
SCM_THEME_PROMPT_SUFFIX="${green}|" | |
SCM_GIT_SHOW_MINIMAL_INFO=true | |
CLOCK_THEME_PROMPT_PREFIX='' | |
CLOCK_THEME_PROMPT_SUFFIX=' ' | |
THEME_SHOW_CLOCK=true | |
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$bold_blue"} | |
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"} | |
PYTHON_ENV_THEME_PROMPT_PREFIX='(' | |
PYTHON_ENV_THEME_PROMPT_SUFFIX=') ' | |
function __font_python_venv_prompt { | |
local python_venv="" | |
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then | |
python_venv="${CONDA_DEFAULT_ENV}" | |
fi | |
if [[ -n "${VIRTUAL_ENV}" ]]; then | |
venv_name=$(basename "${VIRTUAL_ENV}") | |
if [[ -n "$python_venv" ]]; then | |
python_path=$(which python) | |
if [[ "$python_path" == "${VIRTUAL_ENV}"* ]]; then | |
python_venv="$venv_name > $python_venv" | |
else | |
python_venv="$python_venv > $venv_name" | |
fi | |
else | |
python_venv="$venv_name" | |
fi | |
fi | |
[[ -n "${python_venv}" ]] && echo "${PYTHON_ENV_THEME_PROMPT_PREFIX}${python_venv}${PYTHON_ENV_THEME_PROMPT_SUFFIX}" | |
} | |
function prompt_command() { | |
# This needs to be first to save last command return code | |
local RC="$?" | |
hostname="${bold_black}\u@\h" | |
virtualenv="${white}$(__font_python_venv_prompt)" | |
# Set return status color | |
if [[ ${RC} == 0 ]]; then | |
ret_status="${bold_green}" | |
else | |
ret_status="${bold_red}" | |
fi | |
# Append new history lines to history file | |
history -a | |
PS1="$(clock_prompt)${virtualenv}${hostname} ${bold_cyan}\W $(scm_prompt_char_info)${ret_status}→ ${normal}" | |
} | |
safe_append_prompt_command prompt_command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment