Last active
March 25, 2025 15:32
-
-
Save milljm/69f653be030a0c57632a7f4e1bc8f564 to your computer and use it in GitHub Desktop.
Bash profile multi-line, conda/git detection support.
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
#!/bin/bash | |
export HISTSIZE=2000000 | |
export HISTFILESIZE=2000000 | |
export CLICOLOR=1 | |
export LSCOLORS=exfxcxdxbxegedabagacad | |
alias ll="ls --color -latrh $@" | |
alias ls="ls --color $@" | |
########## Pretty Prompt ########### | |
DARKER='\001\033[38;5;234m\002' | |
DARK='\001\033[38;5;238m\002' | |
LIGHTER='\001\033[38;5;231m\002' | |
LIGHT='\001\033[38;5;241m\002' | |
ORANGE='\001\033[38;5;166m\002' | |
GREEN='\001\033[38;5;28m\002' | |
BGREEN='\001\033[38;5;34m\002' | |
BRED='\001\033[38;5;9m\002' | |
AQUA='\001\033[38;5;66m\002' | |
BLUE='\001\033[38;5;67m\002' | |
RESET='\001\033[0m\002' | |
# Do exit code prompt change stuff | |
function exitcode(){ | |
if [[ $? -ge 1 ]]; then | |
printf "${BRED}^ " | |
fi | |
} | |
# Reasons to return true (fast filesystem) | |
function is_fast(){ | |
if [[ -n "${NOGIT}" ]]; then return 1; fi | |
} | |
# Do Conda prompt change stuff | |
function parse_condaprompt(){ | |
if type conda &>/dev/null; then | |
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then | |
printf "${DARK}{conda-env:${AQUA}${CONDA_DEFAULT_ENV}${DARK}}" | |
fi | |
fi | |
} | |
# Do Apptainer promp chnage stuff | |
function parse_apptainer(){ | |
if [[ -n "${MOOSE_APPTAINER_GENERATOR_NAME}" ]]; then | |
printf "${DARK}{apt:${AQUA}${MOOSE_APPTAINER_GENERATOR_NAME//-x86_64*/}${DARK}}" | |
elif [[ -n "${APPTAINER_NAME}" ]]; then | |
printf "${DARK}{apt:${AQUA}${APPTAINER_NAME//-x86_64_*/}${DARK}}" | |
fi | |
} | |
# Add the git branch you are working on if in a git repo | |
function parse_gitbranch(){ | |
BRANCH="$(git branch 2>/dev/null | sed -n 's/* \(.*\)/\1/p')" | |
if [[ ! -z "${BRANCH}" ]] && [[ "${TOO_SLOW}" != "${BRANCH}" ]]; then | |
if is_fast; then | |
CHANGES="$(git diff --stat 2>/dev/null)" | |
fi | |
if [ $? -ge 1 ]; then | |
# TODO: | |
# save state somehow so above logic is false and does not run again for this branch | |
true | |
fi | |
fi | |
if [[ ! -z "${BRANCH}" ]]; then | |
printf "${DARK}(br:${BLUE}${BRANCH}${RESET}" | |
if [[ ! -z "${CHANGES}" ]]; then | |
printf "${DARK}:${BGREEN}+${BRED}-" | |
fi | |
printf "${DARK})" | |
fi | |
} | |
function do_date(){ | |
printf "${DARK}$(date '+%X')" | |
} | |
set_prompt() { | |
_delta='' | |
if [ -n "$last_command_start" ]; then | |
elapsed=$(( SECONDS - last_command_start )) | |
_delta="${DARKER}⌘Δ${AQUA}${elapsed}${DARKER}s${RESET}" | |
else | |
_delta="${DARKER}⌘Δ${AQUA}0${DARKER}s${RESET}" | |
fi | |
last_command_start=$SECONDS | |
PS1=" | |
\$(exitcode)\$(do_date) ${_delta} \$(parse_apptainer)\$(parse_condaprompt)\$(parse_gitbranch) | |
[${GREEN}\u${LIGHTER}@${ORANGE}\h${DARK}][${LIGHTER}\w${DARK}] | |
$ ${RESET}" | |
} | |
shopt -s promptvars | |
PROMPT_COMMAND='set_prompt' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment