From 58223f0e8a7292b16c890f82b9dc9fbc57fe9839 Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Sun, 14 Jul 2024 16:19:38 +0300 Subject: [PATCH] Initial python virtual environment support. --- changelog.sh | 12 ++++++------ etc/profile.d/z-ps-twtty-7.sh | 15 +++++++++++++-- gwebu-profile.spec.in | 9 +++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/changelog.sh b/changelog.sh index 5dc8f29..ce2780a 100755 --- a/changelog.sh +++ b/changelog.sh @@ -8,15 +8,15 @@ rpm_ver="${ver%%-*}" rpm_rev="${ver#*-}" rpm_numeric_rev="${rpm_rev%%-*}" -change="* $(date +'%a %b %d %Y') $(git log -1 --format='%aN <%aE>') - ${rpm_ver}-${rpm_numeric_rev} -- $(git log -1 --format=%s) -" +change1="* $(date +'%a %b %d %Y') $(git log -1 --format='%aN <%aE>') - ${rpm_ver}-${rpm_numeric_rev}" +change2="- $(git log -1 --format=%s)" -awk -v change="${change}" '/^%changelog/ {print; print change; next} 1' gwebu-profile.spec.in \ +awk -v change1="${change1}" -v change2="${change2}" '/^%changelog/ {print; print change1; print change2; print ""; next} 1' gwebu-profile.spec.in \ > gwebu-profile.spec.tmp && mv gwebu-profile.spec.tmp gwebu-profile.spec.in -sed -i "s/Version: .*/Version: ${rpm_ver}/" gwebu-profile.spec.in -sed -i "s/Release: .*/Release: ${rpm_numeric_rev}/" gwebu-profile.spec.in +sed -i.bak "s/Version: .*/Version: ${rpm_ver}/" gwebu-profile.spec.in +sed -i.bak "s/Release: .*/Release: ${rpm_numeric_rev}/" gwebu-profile.spec.in +rm -f gwebu-profile.spec.in.bak git add gwebu-profile.spec.in diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 5d1044a..348ce08 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -77,8 +77,19 @@ function prompt_command() { my_PWD="${PWD}" # Add all the accessories below ... my_D="$(date '+%Y-%m-%d %H:%M:%S')" - # This is for string size calculations only. + # This is for string size calculations only. The variable my_P is set, see PROMPT_COMMAND below. local prompt="--($my_D, Err ${my_P[*]}, $my_TTY)---($PWD)--" + + if [ -n "${VIRTUAL_ENV:-}" ] && [ -n "$_OLD_VIRTUAL_PS1" ]; then + my_VENV="${VIRTUAL_ENV_PROMPT}" + prompt="--($my_D, Err ${my_P[*]}, $my_TTY, $my_VENV)---($PWD)--" + if [ "${PS1:1:${#VIRTUAL_ENV_PROMPT}}" == "$VIRTUAL_ENV_PROMPT" ]; then + # PS1 will be restored by virtual environment's deactivate script. + # Yeah, that has to be done better, 172 is correct but magic number. + export PS1="${_OLD_VIRTUAL_PS1:0:172}, ${my_VENV}${_OLD_VIRTUAL_PS1:172}" + fi + fi + local fill_size=0 [ -z "${COLUMNS}" ] && COLUMNS=$(tput cols) ((fill_size=COLUMNS-${#prompt})) @@ -157,7 +168,7 @@ ${C1}\${USER}${C2}@${C1}\${HOSTNAME%%.*}\ ${C2})${C3}\$${NO_COLOUR} " export PS2="${C2}─${C1}─${C1}─${NO_COLOUR} \[\033[K\]" - + # Set my_P to the exit codes of the last command pipe. local P='my_P=("${PIPESTATUS[@]}");prompt_command' if declare -p PROMPT_COMMAND &>/dev/null; then local re='^declare -a ' diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index a03ddce..5d0acac 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,7 +1,7 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile -Version: 1.0.2 -Release: 6 +Version: 1.0.3 +Release: 0 BuildArch: noarch License: GPLv2 Source0: profile.d-%{version}-%{release}.tar.xz @@ -41,10 +41,11 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog -* Thu May 30 2024 Doncho N. Gunchev - 1.0.2-6 -- New shebang for changelog.sh, post-commit hook in README.md. +* Sun Jul 14 2024 Doncho Gunchev - 1.0.3-0 +- Initial python virtual environment support. * Thu May 30 2024 Doncho N. Gunchev - 1.0.2-6 +- New shebang for changelog.sh, post-commit hook in README.md. * Thu May 30 2024 Doncho N. Gunchev - 1.0.2-5 - Add ssh control masters management aliases. Silence a which.