Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
Següent revisió | Revisió prèvia | ||
linux:bash:ps1 [10/06/2018 00:34] – creat mate | linux:bash:ps1 [04/09/2018 05:59] (actual) – mate | ||
---|---|---|---|
Línia 1: | Línia 1: | ||
= PS1 | = PS1 | ||
- | + | == simples | |
- | {{:misproyectos:clitools:pasted: | + | {{:linux:bash:ps1: |
<code bash> | <code bash> | ||
export PS1=" | export PS1=" | ||
</ | </ | ||
- | {{:misproyectos:clitools:pasted: | + | {{:linux:bash:ps1: |
<code bash> | <code bash> | ||
export PS1=" | export PS1=" | ||
</ | </ | ||
+ | == soporte GIT | ||
+ | /vía: [[https:// | ||
+ | <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 [ " | ||
+ | then | ||
+ | local NM=$(git name-rev --name-only HEAD 2> /dev/null) | ||
+ | if [ " | ||
+ | then echo -n " | ||
+ | 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 " | ||
+ | then echo -n " + " | ||
+ | else echo -n " - " | ||
+ | fi | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | function pwd_depth_limit_2 { | ||
+ | if [ " | ||
+ | then echo -n " | ||
+ | else pwd | sed -e " | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | COLBROWN=" | ||
+ | COLRED=" | ||
+ | COLCLEAR=" | ||
+ | |||
+ | # 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=" | ||
+ | export TERM=" | ||
+ | </ | ||
+ | === ejemplos y fuentes de ideas | ||
+ | funciones: [[https:// | ||
+ | <code bash __git_ps1()> | ||
+ | export PS1=" | ||
+ | \[\033[1; | ||
+ | \[\033[0; | ||
+ | </ | ||
+ | <code bash gestión de colores> | ||
+ | set_prompt() | ||
+ | { | ||
+ | local last_cmd=$? | ||
+ | local txtreset=' | ||
+ | local txtbold=' | ||
+ | local txtblack=' | ||
+ | local txtred=' | ||
+ | local txtgreen=' | ||
+ | local txtyellow=' | ||
+ | local txtblue=' | ||
+ | local txtpurple=' | ||
+ | local txtcyan=' | ||
+ | local txtwhite=' | ||
+ | # unicode " | ||
+ | local fancyx=' | ||
+ | # unicode " | ||
+ | local checkmark=' | ||
+ | # Line 1: Full date + full time (24h) | ||
+ | # Line 2: current path | ||
+ | | ||
+ | # User color: red for root, yellow for others | ||
+ | if [[ $EUID == 0 ]]; then | ||
+ | | ||
+ | else | ||
+ | | ||
+ | fi | ||
+ | # Line 3: user@host | ||
+ | | ||
+ | # Line 4: a red " | ||
+ | if [[ $last_cmd == 0 ]]; then | ||
+ | PS1+=" | ||
+ | else | ||
+ | PS1+=" | ||
+ | fi | ||
+ | # Line 4: green git branch | ||
+ | | ||
+ | # Line 4: good old prompt, $ for user, # for root | ||
+ | | ||
+ | } | ||
+ | PROMPT_COMMAND=' | ||
+ | </ |