Hacker News new | ask | show | jobs
by tetris11 879 days ago
I like this approach. I tried using starship.rs but I have to say it does far more than I want it to and makes me feel like I'm not in control of my shell (e.g. it pulls a schema via an URL without any knowledge from me that it does so).

As a result, I've written my own small and concise PS1 which covers all my use cases:

    ## Add this to ~/.bashrc
    force_color_prompt=yes
    ## show: user+hostname (if ssh), conda, venv, guix, and git
    function prompt_command {
        ## styles and symbols
        local RESET='\[\033[0m\]'     ; local BLD_GRN='\[\033[1;32m\]'; 
        local BLD_YLW='\[\033[1;33m\]'; local BLD_PPL='\[\033[1;35m\]';
        local BLD_CYN='\[\033[1;36m\]'; local BLD_WHT='\[\033[1;37m\]'
        local ITL_YLW='\[\033[3;33m\]'; local SEP='⋮'
    
        PROMPT_DIRTRIM=2
        export PS1=""
        if [ -n "$SSH_CONNECTION" ]; then
            PS1=${PS1}${BLD_CYN}'\u'${BLD_YLW}'@'${BLD_GRN}'\h'${RESET}
        fi
        if [ -n "$CONDA_DEFAULT_ENV" ]; then
            PS1=${PS1}${SEP}${ITL_YLW}${CONDA_DEFAULT_ENV}${RESET}
        fi
        if [ -n "$VIRTUAL_ENV" ]; then
            PS1=${PS1}${SEP}${BLD_WHT}${VIRTUAL_ENV##*/}${RESET}
        fi
        if [ -n "$GUIX_ENVIRONMENT" ]; then
            PS1=${PS1}${SEP}${BLD_GRN}'GUIX'${RESET}
        fi
        if [ -e .git ]; then
            PS1=${PS1}${SEP}${BLD_PPL}$(git branch --show-current)${RESET}
        fi
        PS1=${PS1}${SEP}${BLD_GRN}'\w' # short directory
        PS1=${PS1}${BLD_YLW}'▶ '${RESET}
    }
    export PROMPT_COMMAND=prompt_command

Fast and easy to grok.