11#! /bin/bash
22# Dodanie do aktualnego $PS1 statusu repozytorium gita bieżącego katalogu
3- # Autor : Tomasz Wiśniewski, krystofair @ 2025-09-22
3+ # Autorzy : Tomasz Wiśniewski, krystofair @ 2025-09-22
44
55echo " Jeśli twoja wybrana powłoka nie zadziała, to spróbuj zainstalować do 'bash'."
66sleep 1
@@ -179,11 +179,67 @@ install -m 0644 $GIT_PROMPT_FILE $(dirname $install_path)/$FILENAME
179179
180180if test -e $install_path && test -n " $( cat $install_path | grep __git_ps1) "
181181then
182- echo " Masz to już zainstalowane dla takich wyborów ."
182+ echo " Masz to już zainstalowane."
183183 unset ch_shell
184184 unset installation_type
185185 unset install_path
186- exit 0
186+ exit -1
187+ fi
188+
189+ # Wykorzystuje "features" z globalnego kontekstu
190+ choose_ps1_format () {
191+ echo " Możliwe formaty, \\ e... to escape dla oznaczenia koloru" 1>&2
192+ FORMATS=$'
193+ 1.(<GIT-STATUS>)[<USER>@<HOST>] <PWD><ONL>$
194+ 2.(<GIT-STATUS>) [<USER>@<HOST>] <PWD><ONL>$
195+ 3.<USER>@<HOST> <PWD> (<GIT-STATUS>)<ONL>$
196+ 4.<USER>@<HOST> \\ e[33m<PWD>\\ e[00m (<GIT-STATUS>)<ONL>$
197+ 5.<USER>@<HOST> \\ e[33m<PWD>\\ e[00m <GIT-STATUS><ONL>$
198+ 6.<USER>@<HOST> \\ e[33m<PWD>\\ e[00m <GIT-STATUS><ONL><DATE>$
199+ '
200+ echo " $FORMATS " 1>&2
201+ read -p " Wybierz format: " format_nr
202+ case $format_nr in
203+ 1|2|3|4|5|6) : ;;
204+ * ) echo " Niepoprawny wybor." 1>&2 ; return -1 ;;
205+ esac
206+ format=$( echo " $FORMATS " | grep -F $format_nr .)
207+ format=${format## ??}
208+ read -p " Czy chcesz mieć znak zachęty w nowej linii? Y/n: " r
209+ ONL=${r:- y} ; unset r
210+ if test " $ONL " = y;
211+ then format=${format/ " <ONL>" / \\ n} ;
212+ else format=${format/ " <ONL>" / }
213+ fi
214+
215+ unset FORMATS
216+ unset ONL
217+ unset DOT
218+
219+ # ### BUILD PS1 FROM FORMAT ####
220+ format=${format/ " <USER>" / \\ u}
221+ format=${format/ " <HOST>" / \\ h}
222+ format=${format/ " <PWD>" / \\ w}
223+ format=${format/ " <GIT-STATUS>" / ' $(__git_ps1 %s)' }
224+ if test $format_nr -eq ' 6'
225+ then
226+ format=${format/ " <DATE>" / ' $(date +[%H:%M])' }
227+ fi
228+
229+ echo $format
230+ unset format
231+
232+ return 0
233+ }
234+
235+ if test $ch_shell = bash || test $ch_shell = csh
236+ then
237+ new_ps1=$( choose_ps1_format)
238+ if [[ ! $? -eq 0 ]]; then
239+ echo " Wybrano zły format, nie robię nic, kończę."
240+ echo " Uruchom mnie ponownie."
241+ exit 0
242+ fi
187243fi
188244
189245echo " Dodaję nowe instrukcje do pliku $install_path "
@@ -194,7 +250,8 @@ echo "source $(dirname $install_path)/$FILENAME" >> $install_path
194250echo ' fi' >> $install_path
195251case $ch_shell in
196252 bash|csh)
197- echo $' export PS1=\' $(__git_ps1 \(%s%s\))[\u@\h \w]\n \$ \' ' >> $install_path
253+ echo $" export PS1='$new_ps1 '" >> $install_path
254+ # echo $'export PS1=\'$(__git_ps1 \(%s%s\))[\u@\h \w]\n$ \'' >> $install_path
198255 ;;
199256 zsh)
200257 echo $' setopt PROMPT_SUBST; PS1=\' [%n@%m %c$(__git_ps1 \" (%s)\")]\$ \' ' >> $install_path
0 commit comments