Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 61 additions & 4 deletions actions/chce_git_status_PS1.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.(<GIT-STATUS>)[<USER>@<HOST>] <PWD><ONL>$
2.(<GIT-STATUS>) [<USER>@<HOST>] <PWD><ONL>$
3.<USER>@<HOST> <PWD> (<GIT-STATUS>)<ONL>$
4.<USER>@<HOST> \\e[33m<PWD>\\e[00m (<GIT-STATUS>)<ONL>$
5.<USER>@<HOST> \\e[33m<PWD>\\e[00m <GIT-STATUS><ONL>$
6.<USER>@<HOST> \\e[33m<PWD>\\e[00m <GIT-STATUS><ONL><DATE>$
'
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/"<ONL>"/\\n};
else format=${format/"<ONL>"/}
fi

unset FORMATS
unset ONL
unset DOT

#### BUILD PS1 FROM FORMAT ####
format=${format/"<USER>"/\\u}
format=${format/"<HOST>"/\\h}
format=${format/"<PWD>"/\\w}
format=${format/"<GIT-STATUS>"/'$(__git_ps1 %s)'}
if test $format_nr -eq '6'
then
format=${format/"<DATE>"/'$(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"
Expand All @@ -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
Expand Down