antonmedv / countdown

Terminal countdown timer
MIT License
1.07k stars 110 forks source link

Your prompt #3

Closed retr0h closed 5 years ago

retr0h commented 5 years ago

This isn't really related to countdown, but in the gif on the main page, you have a pretty rad colorful prompt. Any chance you could provide the details on how to accomplish that ;)

Thanks!

antonmedv commented 5 years ago

Here it is:

image

# Prompt

PATH_COLOR="\[$(tput setaf 47)\]"
GIT_BRANCH_COLOR="\[$(tput setaf 51)\]"
PROMPT_COLOR="\[$(tput setaf 76)\]"
COLOR_RED="\[$(tput setaf 161)\]"
COLOR_YELLOW="\[$(tput setaf 220)\]"
COLOR_GREEN="\[$(tput setaf 76)\]"
RESET="\[$(tput sgr0)\]"

function find_git_branch {
  local branch
  if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
    if [[ "$branch" == "HEAD" ]]; then
      branch='detached*'
    fi
    GIT_BRANCH=" ${GIT_BRANCH_COLOR}⎇ $branch${RESET}"
  else
    GIT_BRANCH=""
  fi
}

function set_tab_title {
    echo -ne "\033]0;${PWD##*/}\007"
}

function set_ps1 {  
    find_git_branch;
    set_tab_title;
    if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
    export PS1="⌘ ${PATH_COLOR}\W${RESET}${GIT_BRANCH} ${COLOR_RED}❯${COLOR_YELLOW}❯${COLOR_GREEN}❯${RESET} "
    else
        export PS1="\W ❯ "
    fi
}

export PROMPT_COMMAND="set_ps1;"
retr0h commented 5 years ago

Thanks 👍 \m/