Skip to content

Instantly share code, notes, and snippets.

@aphilas
Last active July 14, 2021 12:26
Show Gist options
  • Save aphilas/b6f94690577dde6887de7bfc8474a2d8 to your computer and use it in GitHub Desktop.
Save aphilas/b6f94690577dde6887de7bfc8474a2d8 to your computer and use it in GitHub Desktop.
Custom bash prompt to show chroot, venv, basename of current dir and git branch: (chroot)(venv)curr_dir(git_branch)$
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch of the current git repository
#
# USAGE:
#
# 1. Save this file as ~/.bash_prompt
# 2. Add the following line to the end of your ~/.bashrc or ~/.bash_profile:
# . ~/.bash_prompt
#
# LINEAGE:
#
# Based on work by miki725
#
# https://gist.github.com/miki725/9783474
# handy color escape sequences
BLUE="\[\033[1;34m\]" # 0; instead of 1; for 'light' version of color, 'non-bold' to me
GREEN="\[\033[1;32m\]"
RED="\[\033[1;31m\]"
YELLOW="\[\033[1;33m\]"
RESET="\[\033[0m\]"
# \W to show basename of curr dir, replace with \w for a longer path; feel free to change the colors too
# chroot, venv, curr_dir_base, git_branch
export PS1="${RED}\${debian_chroot:+(\$debian_chroot)}${YELLOW}\${VIRTUAL_ENV:+(\${VIRTUAL_ENV##*/})}${BLUE}\W${GREEN}\$(__git_ps1 '(%s)')${BLUE}\$${RESET} "
# disable default venv prompt change
export VIRTUAL_ENV_DISABLE_PROMPT=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment