From 3b055c87ca40607d20901151dea51ba25f9e05cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20K=C5=82apyta?= <33362868+krystofair@users.noreply.github.com> Date: Wed, 24 Sep 2025 17:39:59 +0200 Subject: [PATCH 1/3] add feature to choose format of PS1, but bash only now --- actions/chce_git_status_PS1.sh | 66 ++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/actions/chce_git_status_PS1.sh b/actions/chce_git_status_PS1.sh index efb0a31..7af2ca2 100755 --- a/actions/chce_git_status_PS1.sh +++ b/actions/chce_git_status_PS1.sh @@ -1,6 +1,6 @@ #!/bin/bash # Dodanie do aktualnego $PS1 statusu repozytorium gita bieżącego katalogu -# Autor: Tomasz Wiśniewski, krystofair @ 2025-09-22 +# Autorzy: Tomasz Wiśniewski, krystofair @ 2025-09-22 echo "Jeśli twoja wybrana powłoka nie zadziała, to spróbuj zainstalować do 'bash'." sleep 1 @@ -179,13 +179,72 @@ install -m 0644 $GIT_PROMPT_FILE $(dirname $install_path)/$FILENAME if test -e $install_path && test -n "$(cat $install_path | grep __git_ps1)" then - echo "Masz to już zainstalowane dla takich wyborów." + echo "Masz to już zainstalowane." unset ch_shell unset installation_type unset install_path exit 0 fi +# Wykorzystuje "features" z globalnego kontekstu +choose_ps1_format() { + echo "Możliwe formaty, \[\033... to oznaczenia kolory" 1>&2 + FORMATS=$' +1.( )[@] \$ +2.( ) [@] \$ +3.@ ( )\$ +4.@ \\[\\033[33m\\]\\[\\033[00m\\] ( )\$ +5.@ \\[\\033[33m\\]\\[\\033[00m\\] \$ +' + echo "$FORMATS" 1>&2 + read -p "Wybierz format: " format_nr + case $format_nr in + 1|2|3|4|5) : ;; + *) echo "Niepoprawny wybor." 1>&2; return -1 ;; + esac + format=$(echo "$FORMATS" | grep -F $format_nr.) + format=${format##??} + read -p "Czy chcesz mieć znak zachęty w nowej linii? Y/n: " r + ONL=${r:-y}; unset r + if test "$ONL" = y; + then format=${format/""/\\n}; + else format=${format/""/} + fi + + unset FORMATS + unset ONL + unset DOT + + #### BUILD PS1 FROM FORMAT #### + format=${format/""/\\u} + format=${format/""/\\h} + format=${format/""/\\w} + format=${format/""/'$(__git_ps1 '} + # funkcja __git_ps1 polega na ilości przekazanych do niej parametrów. + # kolor chyba działa tylko przy jednym parametrze... + IS_GIT_DIRTYSTATE=$(echo $1 | grep 'GIT_PS1_SHOWDIRTYSTATE=y') + if test -n "$IS_GIT_DIRTYSTATE"; + then format=${format/""/'%s%s)'} + else format=${format/""/'%s)'} + fi + + echo $format + unset IS_GIT_DIRTYSTATE + unset format + + return 0 +} + +if test $ch_shell = bash || test $ch_shell = csh +then + new_ps1=$(choose_ps1_format) + if [[ ! $? -eq 0 ]]; then + echo "Wybrano zły format, nie robię nic, kończę." + echo "Uruchom mnie ponownie." + exit 0 + fi +fi + echo "Dodaję nowe instrukcje do pliku $install_path" echo "# === Dodane przez skrypt 'chce_git_status_PS1.sh'. ===" >> $install_path echo "$features" >> $install_path @@ -194,7 +253,8 @@ echo "source $(dirname $install_path)/$FILENAME" >> $install_path echo 'fi' >> $install_path case $ch_shell in bash|csh) - echo $'export PS1=\'$(__git_ps1 \(%s%s\))[\u@\h \w]\n\$ \'' >> $install_path + echo $"export PS1='$new_ps1 '" >> $install_path + # echo $'export PS1=\'$(__git_ps1 \(%s%s\))[\u@\h \w]\n\$ \'' >> $install_path ;; zsh) echo $'setopt PROMPT_SUBST; PS1=\'[%n@%m %c$(__git_ps1 \" (%s)\")]\$ \'' >> $install_path From a9e2700df8fbb9dc7a5e9611090d608bc473da53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20K=C5=82apyta?= <33362868+krystofair@users.noreply.github.com> Date: Thu, 25 Sep 2025 04:30:24 +0200 Subject: [PATCH 2/3] simplify refactory --- actions/chce_git_status_PS1.sh | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/actions/chce_git_status_PS1.sh b/actions/chce_git_status_PS1.sh index 7af2ca2..bd58a4b 100755 --- a/actions/chce_git_status_PS1.sh +++ b/actions/chce_git_status_PS1.sh @@ -183,18 +183,18 @@ then unset ch_shell unset installation_type unset install_path - exit 0 + exit -1 fi # Wykorzystuje "features" z globalnego kontekstu choose_ps1_format() { - echo "Możliwe formaty, \[\033... to oznaczenia kolory" 1>&2 + echo "Możliwe formaty, \\e... to escape dla oznaczenia koloru" 1>&2 FORMATS=$' -1.( )[@] \$ -2.( ) [@] \$ -3.@ ( )\$ -4.@ \\[\\033[33m\\]\\[\\033[00m\\] ( )\$ -5.@ \\[\\033[33m\\]\\[\\033[00m\\] \$ +1.()[@] $ +2.() [@] $ +3.@ ()$ +4.@ \\e[33m\\e[00m ()$ +5.@ \\e[33m\\e[00m $ ' echo "$FORMATS" 1>&2 read -p "Wybierz format: " format_nr @@ -219,17 +219,9 @@ choose_ps1_format() { format=${format/""/\\u} format=${format/""/\\h} format=${format/""/\\w} - format=${format/""/'$(__git_ps1 '} - # funkcja __git_ps1 polega na ilości przekazanych do niej parametrów. - # kolor chyba działa tylko przy jednym parametrze... - IS_GIT_DIRTYSTATE=$(echo $1 | grep 'GIT_PS1_SHOWDIRTYSTATE=y') - if test -n "$IS_GIT_DIRTYSTATE"; - then format=${format/""/'%s%s)'} - else format=${format/""/'%s)'} - fi + format=${format/""/'$(__git_ps1 %s)'} echo $format - unset IS_GIT_DIRTYSTATE unset format return 0 @@ -254,7 +246,7 @@ echo 'fi' >> $install_path case $ch_shell in bash|csh) echo $"export PS1='$new_ps1 '" >> $install_path - # echo $'export PS1=\'$(__git_ps1 \(%s%s\))[\u@\h \w]\n\$ \'' >> $install_path + # echo $'export PS1=\'$(__git_ps1 \(%s%s\))[\u@\h \w]\n$ \'' >> $install_path ;; zsh) echo $'setopt PROMPT_SUBST; PS1=\'[%n@%m %c$(__git_ps1 \" (%s)\")]\$ \'' >> $install_path From 3ff90c8cdcdbd7176b17615c5345c173d3b5c36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20K=C5=82apyta?= <33362868+krystofair@users.noreply.github.com> Date: Thu, 25 Sep 2025 05:00:15 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Ju=C5=BC=20ostatni,=20format,=20podpatrzony?= =?UTF-8?q?=20u=20Gynvaela.=20B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/chce_git_status_PS1.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/actions/chce_git_status_PS1.sh b/actions/chce_git_status_PS1.sh index bd58a4b..c325e2c 100755 --- a/actions/chce_git_status_PS1.sh +++ b/actions/chce_git_status_PS1.sh @@ -195,11 +195,12 @@ choose_ps1_format() { 3.@ ()$ 4.@ \\e[33m\\e[00m ()$ 5.@ \\e[33m\\e[00m $ +6.@ \\e[33m\\e[00m $ ' echo "$FORMATS" 1>&2 read -p "Wybierz format: " format_nr case $format_nr in - 1|2|3|4|5) : ;; + 1|2|3|4|5|6) : ;; *) echo "Niepoprawny wybor." 1>&2; return -1 ;; esac format=$(echo "$FORMATS" | grep -F $format_nr.) @@ -220,6 +221,10 @@ choose_ps1_format() { format=${format/""/\\h} format=${format/""/\\w} format=${format/""/'$(__git_ps1 %s)'} + if test $format_nr -eq '6' + then + format=${format/""/'$(date +[%H:%M])'} + fi echo $format unset format