A collection of scripts and configurations for Bash (and others)
Vous ne pouvez pas sélectionner plus de 25 sujets
Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
|
-
- # This function was modified from one found @ https://www.reddit.com/r/linux/comments/2uf5uu/this_is_my_bash_prompt_which_is_your_favorite/?st=jikgswh4&sh=371ba8bf
- function _git_status() {
- local unknown untracked stash clean ahead behind staged dirty diverged
- unknown=$BLUE
- untracked=$GREEN
- stash=$GREEN
- clean=$GREEN
- ahead=$YELLOW
- behind=$YELLOW
- staged=$CYAN
- dirty=$RED
- diverged=$RED
-
-
- branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
- if [[ -n "$branch" ]]; then
- git_status=$(git status 2> /dev/null)
- # If nothing changes the color, we can spot unhandled cases.
- color=$unknown
- if [[ $git_status =~ 'Untracked files' ]]; then
- color=$untracked
- branch="${branch}?"
- fi
- if git stash show &>/dev/null; then
- color=$stash
- branch="${branch}+"
- fi
- if [[ $git_status =~ 'working directory clean' ]]; then
- color=$clean
- fi
- if [[ $git_status =~ 'Your branch is ahead' ]]; then
- color=$ahead
- branch="${branch}>"
- fi
- if [[ $git_status =~ 'Your branch is behind' ]]; then
- color=$behind
- branch="${branch}<"
- fi
- if [[ $git_status =~ 'Changes to be committed' ]]; then
- color=$staged
- fi
- if [[ $git_status =~ 'Changed but not updated' ||
- $git_status =~ 'Changes not staged' ||
- $git_status =~ 'Unmerged paths' ]]; then
- color=$dirty
- fi
- if [[ $git_status =~ 'Your branch'.+diverged ]]; then
- color=$diverged
- branch="${branch}!"
- fi
- echo -n "${color}${branch}${NORMAL}|"
- fi
- }
-
-
- set_prompt() {
- local lec="$?"
- if [ $COLOR_PROMPT = yes ]; then
- if [ $lec -ne 0 ]; then
- smilie="${RED}:(${NORMAL}"
- else
- smilie="${GREEN}:)${NORMAL}"
- fi
- PS1="${debian_chroot:+($debian_chroot)}${BG_PURPLE}${GREEN}\u${NORMAL}${BG_PURPLE}|${BLUE}\w${NORMAL}${BG_PURPLE}|${smilie}${BG_PURPLE}|$(_git_status)${PURPLE}► "
- else
- PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
- fi
- }
-
- PROMPT_COMMAND="set_prompt"
|