diff --git a/actions/chce_git_status_PS1.sh b/actions/chce_git_status_PS1.sh index efb0a31..c325e2c 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,11 +179,67 @@ 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 + exit -1 +fi + +# Wykorzystuje "features" z globalnego kontekstu +choose_ps1_format() { + echo "Możliwe formaty, \\e... to escape dla oznaczenia koloru" 1>&2 + FORMATS=$' +1.()[@] $ +2.() [@] $ +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|6) : ;; + *) 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 %s)'} + if test $format_nr -eq '6' + then + format=${format/""/'$(date +[%H:%M])'} + fi + + echo $format + 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" @@ -194,7 +250,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