From affb7ae553c3513834021fa6fc64aed55e7b6965 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Sun, 2 Nov 2025 15:52:41 +0200 Subject: [PATCH] Fixing VENV again... Updated .pre-commit-config.yaml --- .pre-commit-config.yaml | 2 +- README.md | 2 ++ etc/profile.d/z-ps-twtty-7.sh | 50 ++++++++++++++++++++++++++--------- gwebu-profile.spec.in | 5 +++- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f83867..8e45b2d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v6.0.0 hooks: - id: check-added-large-files args: [ '--maxkb=64' ] diff --git a/README.md b/README.md index a068800..65f3cd7 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,5 @@ Unless explicitly stated in the file itself, the license is [The Unlicense](http ## Automation To update the RPM changelog run ./changelog.sh + +Type `make` to see the available targets (dist, rpm, podman_rpm, changelog, clean). diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 551d621..4abae88 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -11,6 +11,10 @@ # alternatively write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# z-ps-twtty-7.sh - Nice bash prompt and history archiver +# by Doncho Gunchev , 2025-11-02 16:27:00 EET +# Improve python virtual environments support. +# # z-ps-twtty-7.sh - Nice bash prompt and history archiver # by Doncho Gunchev , 2024-01-27 15:58 EET # Show PIPESTATUS instead of just $?. Cleanup. @@ -52,7 +56,8 @@ if [ "$PS1" ] ; then # interactive shell detection # Log the logout event. function prompt_command_exit() { trap - EXIT - local now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds) + local now + now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds) local HistFile HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')" mkdir -p "${HistFile%/*}" @@ -61,10 +66,12 @@ function prompt_command_exit() { # Executed before each prompt. Fill the variables needed by PS1 here. function prompt_command() { - local now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds) + local now + now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds) # Manage the history - local HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')" + local HistFile + HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')" mkdir -p "${HistFile%/*}" if [ -z "$my_LoginTime" ]; then @@ -78,23 +85,25 @@ function prompt_command() { # Add all the accessories below ... my_D="$(date '+%Y-%m-%d %H:%M:%S')" # This is for string size calculations only. The variable my_P is set, see PROMPT_COMMAND below. + if [ -z "$my_P" ]; then my_P="ERROR"; fi # make shellcheck happy. local prompt="--($my_D, Err ${my_P[*]}, $my_TTY)---($PWD)--" if [ -n "${VIRTUAL_ENV:-}" ] && [ -n "$_OLD_VIRTUAL_PS1" ]; then if [ -n "$VIRTUAL_ENV_PROMPT" ]; then - my_VENV="${VIRTUAL_ENV_PROMPT%) }" - my_VENV="${my_VENV%) }" - export my_VENV="${my_VENV#(}" + my_VENV="${VIRTUAL_ENV_PROMPT%\ }" + my_VENV="${my_VENV%\)}" + my_VENV="${my_VENV#\(}" else # Best guess export my_VENV="${VIRTUAL_ENV##*/}" fi - prompt="--($my_D, Err ${my_P[*]}, $my_TTY, $my_VENV)---($PWD)--" - if [ "${PS1:0:${#my_VENV}+3}" == "($my_VENV) " ]; 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 + prompt="--($my_D, Err ${my_P[*]}, $my_TTY, Venv $my_VENV)---($PWD)--" + # local ps1_prefix + ps1_prefix="${_OLD_VIRTUAL_PS1%\$\{my_TTY\}*}\${my_TTY}" + ps1_suffix="${_OLD_VIRTUAL_PS1#"$ps1_prefix"}" + # The magic with numbers copies the comma with the colors around it. + export PS1="${ps1_prefix}${ps1_prefix:${#ps1_prefix}-39:30}\ +${ps1_prefix:${#ps1_prefix}-81:14}Venv${ps1_prefix:${#ps1_prefix}-63:14} ${my_VENV}${ps1_suffix}" fi local fill_size=0 @@ -114,7 +123,8 @@ function prompt_command() { fi local OldCmdNo="$CmdNo" # See if we got new command later. - local Cmd="$(history 1)" + local Cmd + Cmd="$(history 1)" CmdNo="${Cmd:0:7}" if [[ -z "$OldCmdNo" ]]; then Cmd="login" @@ -128,18 +138,28 @@ function prompt_command() { function twtty { # The special "\[" and "\]" are telling bash that the text enclosed will not move the caret. + # shellcheck disable=SC2034 local GRAY='\[\033[1;30m\]' + # shellcheck disable=SC2034 local LIGHT_GRAY='\[\033[0;37m\]' + # shellcheck disable=SC2034 local WHITE='\[\033[1;37m\]' + # shellcheck disable=SC2034 local NO_COLOUR='\[\033[0m\]' + # shellcheck disable=SC2034 local LIGHT_BLUE='\[\033[1;34m\]' + # shellcheck disable=SC2034 local YELLOW='\[\033[1;33m\]' + # shellcheck disable=SC2034 local RED='\[\033[0;31m\]' + # shellcheck disable=SC2034 local LIGHT_RED='\[\033[1;31m\]' + # shellcheck disable=SC2034 local GREEN='\[\033[0;32m\]' + # shellcheck disable=SC2034 local LIGHT_GREEN='\[\033[1;32m\]' if [ "${UID}" -ne '0' ]; then @@ -176,15 +196,19 @@ ${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. + # shellcheck disable=SC2016 local P='my_P=("${PIPESTATUS[@]}");prompt_command' if declare -p PROMPT_COMMAND &>/dev/null; then local re='^declare -a ' if [[ "$(declare -p PROMPT_COMMAND)" =~ $re ]]; then # Array, supported since bash 5.1 PROMPT_COMMAND=("$P" "${PROMPT_COMMAND[@]}") else # String + # shellcheck disable=SC2178 + # shellcheck disable=SC2128 PROMPT_COMMAND="$P;${PROMPT_COMMAND}" fi else + # shellcheck disable=SC2178 PROMPT_COMMAND="$P" fi unset P diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index d688c47..50e5cfe 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.7 -Release: 1 +Release: 2 BuildArch: noarch License: GPLv2 Source0: profile.d-%{version}-%{release}.tar.xz @@ -41,6 +41,9 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Sun Nov 02 2025 Doncho N. Gunchev - 1.0.7-2 +- Fixing VENV again... + * Tue May 27 2025 Doncho Gunchev - 1.0.7-1 - Shorten ~/.ssh/controlmasters to ~/.ssh/c (104 char limit on mac).