linux:bash:ps1

Diferències

Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.

Enllaç a la visualització de la comparació

Ambdós costats versió prèvia Revisió prèvia
Següent revisió
Revisió prèvia
linux:bash:ps1 [08/07/2018 00:19] matelinux:bash:ps1 [04/09/2018 05:59] (actual) mate
Línia 1: Línia 1:
 = PS1 = PS1
 == simples == simples
-{{:misproyectos:clitools:pasted:20171207-160802.png}}+{{:linux:bash:ps1:20171207-160802.png}}
 <code bash> <code bash>
 export PS1="\[\e]0;\u@\h \w\a\]\[\e[00;33m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[00;33m\]\h\[\e[0m\]\[\e[00;37m\]:\[\e[0m\]\[\e[00;34m\]\w\[\e[0m\]\[\e[00;37m\]\n\$ \[\e[0m\]" export PS1="\[\e]0;\u@\h \w\a\]\[\e[00;33m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[00;33m\]\h\[\e[0m\]\[\e[00;37m\]:\[\e[0m\]\[\e[00;34m\]\w\[\e[0m\]\[\e[00;37m\]\n\$ \[\e[0m\]"
 </code> </code>
  
-{{:misproyectos:clitools:pasted:20171207-160640.png}}+{{:linux:bash:ps1:20171207-160640.png}}
 <code bash> <code bash>
 export PS1="\[$(tput sgr0)\]\033[38;5;15m\033[38;5;11m\u\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m@\[$(tput sgr0)\]\033[38;5;15m\033[38;5;11m\h\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m:\[$(tput sgr0)\]\033[38;5;15m\033[38;5;2m\w\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m\n\[$(tput sgr0)\]\\$\[$(tput sgr0)\] \[$(tput sgr0)\]" export PS1="\[$(tput sgr0)\]\033[38;5;15m\033[38;5;11m\u\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m@\[$(tput sgr0)\]\033[38;5;15m\033[38;5;11m\h\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m:\[$(tput sgr0)\]\033[38;5;15m\033[38;5;2m\w\[$(tput sgr0)\]\033[38;5;15m\033[38;5;15m\n\[$(tput sgr0)\]\\$\[$(tput sgr0)\] \[$(tput sgr0)\]"
Línia 12: Línia 12:
  
 == soporte GIT == soporte GIT
 +/vía: [[https://stackoverflow.com/questions/4133904/ps1-line-with-git-current-branch-and-colors]]
 +<code bash>
 +function we_are_in_git_work_tree {
 +    git rev-parse --is-inside-work-tree &> /dev/null
 +}
 +
 +function parse_git_branch {
 +    if we_are_in_git_work_tree
 +    then
 +    local BR=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD 2> /dev/null)
 +    if [ "$BR" == HEAD ]
 +    then
 +        local NM=$(git name-rev --name-only HEAD 2> /dev/null)
 +        if [ "$NM" != undefined ]
 +        then echo -n "@$NM"
 +        else git rev-parse --short HEAD 2> /dev/null
 +        fi
 +    else
 +        echo -n $BR
 +    fi
 +    fi
 +}
 +
 +function parse_git_status {
 +    if we_are_in_git_work_tree
 +    then 
 +    local ST=$(git status --short 2> /dev/null)
 +    if [ -n "$ST" ]
 +    then echo -n " + "
 +    else echo -n " - "
 +    fi
 +    fi
 +}
 +
 +function pwd_depth_limit_2 {
 +    if [ "$PWD" = "$HOME" ]
 +    then echo -n "~"
 +    else pwd | sed -e "s|.*/\(.*/.*\)|\1|"
 +    fi
 +}
 +
 +COLBROWN="\[\033[1;33m\]"
 +COLRED="\[\033[1;31m\]"
 +COLCLEAR="\[\033[0m\]"
 +
 +# export all these for subshells
 +export -f parse_git_branch parse_git_status we_are_in_git_work_tree pwd_depth_limit_2
 +export PS1="$COLRED<$COLBROWN \$(pwd_depth_limit_2)$COLRED\$(parse_git_status)$COLBROWN\$(parse_git_branch) $COLRED>$COLCLEAR "
 +export TERM="xterm-color"
 +</code>
 === ejemplos y fuentes de ideas === ejemplos y fuentes de ideas
 +funciones: [[https://medium.freecodecamp.org/bash-shortcuts-to-enhance-your-git-workflow-5107d64ea0ff]]
 <code bash __git_ps1()> <code bash __git_ps1()>
 export PS1="\n\[\033[1;30m\][$$:$PPID - \j:\!\[\033[1;30m\]]\[\033[0;36m\] \T \ export PS1="\n\[\033[1;30m\][$$:$PPID - \j:\!\[\033[1;30m\]]\[\033[0;36m\] \T \
  • linux/bash/ps1.1531034377.txt.gz
  • Darrera modificació: 08/07/2018 00:19
  • per mate