From 08548e7a569da128e28dcca9fda90583b678f55d Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Wed, 21 Feb 2024 15:32:36 +0200 Subject: [PATCH 01/27] Add pre-commit hooks. Drop the shebang from z-ps-twtty-7.sh. --- .gitignore | 1 + .pre-commit-config.yaml | 19 +++++++++++++++++++ etc/profile.d/z-ps-twtty-7.sh | 2 -- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.gitignore b/.gitignore index 9b1c8b1..ce63e93 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /dist +/.idea diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3f83867 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-added-large-files + args: [ '--maxkb=64' ] + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-symlinks + - id: check-toml + - id: check-yaml + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: fix-encoding-pragma + - id: mixed-line-ending + args: [ '--fix=lf' ] + - id: trailing-whitespace diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 21c6375..754eba4 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -1,5 +1,3 @@ -#!/bin/bash - # DESCRIPTION # =========== # An attempt to seize industrial… ops, I ment an attempt to make my From bce45e0c3ee13ac1b51c1759b226354112f96900 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Wed, 21 Feb 2024 21:09:11 +0200 Subject: [PATCH 02/27] Try to set up CI with Rocky Linux 9 --- .github/workflows/makefile.yml | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/makefile.yml diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..181ade4 --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,51 @@ +name: Makefile CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + container: rockylinux:9 + + steps: + - name: Install needed packages + run: | + dnf -y install rpmdevtools make xz tar bash git + # one time fix to avoid permission problems later on + git config --global --add safe.directory "$GITHUB_WORKSPACE" + + # Checks-out the repository under $GITHUB_WORKSPACE. + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup RPM build environment + run: rpmdev-setuptree + + - name: List all files here + run: ls -al + + - name: Show GITHUB_WORKSPACE + run: echo "$GITHUB_WORKSPACE" + + - name: List GITHUB_WORKSPACE + run: ls -al "$GITHUB_WORKSPACE" + + - name: List all files here + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + + - name: Show the Makefile help screen + run: make + + - name: Create source distribution tar.xz + run: make dist + + - name: Create RPM packages + run: make rpm + + - name: Clean up + run: make clean From e68638230aae14fdb53f022e3092eb9a2e542fbd Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Thu, 22 Feb 2024 09:13:09 +0200 Subject: [PATCH 03/27] Fix getting version from GIT on EL9. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9c0932c..17010e5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ SHELL:=/bin/bash # Use bash syntax, mitigates dash's printf on Debian -ver:=$(shell git describe --tags --always --match='v[0-9]*.[0-9]*' | cut -c 2-) +ver:=$(shell git describe --tags --always --match='v[0-9]*.[0-9]*' | cut -c 2- | cut -d - -f 1) help: From 5b8a75b75cee460e65aeba301ce54a254a3ae646 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Thu, 22 Feb 2024 11:31:44 +0200 Subject: [PATCH 04/27] General rework of the build process (distribution source and rpm). --- .gitattributes | 7 ++++++ .github/workflows/makefile.yml | 12 ----------- .gitignore | 3 ++- Makefile | 24 +++++++++++++++++---- changelog.sh | 13 +++++++++++ gwebu-profile.spec => gwebu-profile.spec.in | 17 +++++++++++---- 6 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 .gitattributes create mode 100755 changelog.sh rename gwebu-profile.spec => gwebu-profile.spec.in (79%) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..388db68 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +.gitattributes export-ignore +.github export-ignore +.gitignore export-ignore +.pre-commit-config.yaml export-ignore +changelog.sh export-ignore +gwebu-profile.spec.in export-ignore +Makefile export-ignore diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index 181ade4..dd174b5 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -26,18 +26,6 @@ jobs: - name: Setup RPM build environment run: rpmdev-setuptree - - name: List all files here - run: ls -al - - - name: Show GITHUB_WORKSPACE - run: echo "$GITHUB_WORKSPACE" - - - name: List GITHUB_WORKSPACE - run: ls -al "$GITHUB_WORKSPACE" - - - name: List all files here - run: git config --global --add safe.directory "$GITHUB_WORKSPACE" - - name: Show the Makefile help screen run: make diff --git a/.gitignore b/.gitignore index ce63e93..da982b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/dist /.idea +/dist +/gwebu-profile.spec diff --git a/Makefile b/Makefile index 17010e5..f4a9348 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ SHELL:=/bin/bash # Use bash syntax, mitigates dash's printf on Debian -ver:=$(shell git describe --tags --always --match='v[0-9]*.[0-9]*' | cut -c 2- | cut -d - -f 1) +ver:=$(shell git describe --dirty --long --match='v[0-9]*.[0-9]*' | cut -c 2- | cut -d - -f 1,2,4) +rpm_ver:=$(firstword $(subst -, ,$(ver))) +rpm_rev:=$(subst $(rpm_ver)-,,$(ver)) +rpm_rev:=$(subst -,_,$(rpm_rev)) help: @@ -10,17 +13,25 @@ help: @echo "Available targets:" @echo " dist: create source distribution package in dist/" @echo " rpm: create an RPM package" + @echo " changelog: Add a changelog entry to gwebu-profile.spec.in" @echo @echo " clean: clean all generated files" @echo - @echo "Version $(ver)." + @echo "Version $(ver), rpm_ver=$(rpm_ver), rpm_rev=$(rpm_rev)." .PHONY: help .PHONY: dist -dist: +dist: dist/profile.d-$(ver).tar.xz + + +dist/profile.d-$(ver).tar.xz: test -d dist || mkdir dist - git archive --prefix="profile.d-$(ver)/" HEAD | xz -9v > "dist/profile.d-$(ver).tar.xz" + sed 's/^Version: .*/Version: $(rpm_ver)/' < gwebu-profile.spec.in \ + | sed 's/^Release: .*/Release: $(rpm_rev)/' \ + > gwebu-profile.spec + git archive --prefix="profile.d-$(ver)/" --add-file=gwebu-profile.spec HEAD | xz -9 > "$@" + rm gwebu-profile.spec .PHONY: rpm @@ -28,6 +39,11 @@ rpm: dist rpmbuild -ta "dist/profile.d-$(ver).tar.xz" +.PHONY: changelog +changelog: + ./changelog.sh + + .PHONY: clean clean: rm -rf dist diff --git a/changelog.sh b/changelog.sh new file mode 100755 index 0000000..3b89442 --- /dev/null +++ b/changelog.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +ver=$(git describe --dirty --long --match='v[0-9]*.[0-9]*' | cut -c 2- | cut -d - -f 1,2,4) +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) +" + +awk -v change="${change}" '/^%changelog/ {print; print change; next} 1' gwebu-profile.spec.in \ + > gwebu-profile.spec.tmp && mv gwebu-profile.spec.tmp gwebu-profile.spec.in diff --git a/gwebu-profile.spec b/gwebu-profile.spec.in similarity index 79% rename from gwebu-profile.spec rename to gwebu-profile.spec.in index 206b14c..517cb56 100644 --- a/gwebu-profile.spec +++ b/gwebu-profile.spec.in @@ -1,12 +1,13 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile Version: 1.0.0 -Release: 3 -License: GPLv2 -Source0: profile.d-%{version}.tar.xz +Release: 5 BuildArch: noarch +License: GPLv2 +Source0: profile.d-%{version}-%{release}.tar.xz Requires: bash >= 4 + %description This package contains: - z-aliases.sh: @@ -20,21 +21,29 @@ This package contains: All these reside in /etc/profile.d/. + %prep -%setup -q # -n profile.d-%{version} +%setup -q -n profile.d-%{version}-%{release} + %build # No build actions needed for Bash scripts + %install mkdir -p %{buildroot}%{_sysconfdir}/profile.d install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ + %files %defattr(-,root,root,-) %{_sysconfdir}/profile.d/*.sh + %changelog +* Thu Feb 22 2024 Doncho N. Gunchev - 1.0.0-4 +- General rework of the build process (distribution source and rpm). + * Wed Feb 21 2024 Doncho N. Gunchev - 1.0.0-3 - Minor updates. From dc0be5c2a14d62f8c0daa5d007482b2ea34e222e Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Thu, 14 Mar 2024 15:05:34 +0200 Subject: [PATCH 05/27] Detect if the scripts are not sourced and print help. --- etc/profile.d/z-aliases.sh | 5 +++++ etc/profile.d/z-env.sh | 5 +++++ etc/profile.d/z-ps-twtty-7.sh | 5 +++++ etc/profile.d/z-time_style.sh | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index ac8c32e..342c14d 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -1,3 +1,8 @@ +if [ "${BASH_SOURCE-}" = "$0" ]; then + echo -e "You must source this script:\n\tsource $0" >&2 + exit 33 +fi + # show hidden files and directories alias l.='ls -d .[^.]* ..?* --color=tty 2>/dev/null' diff --git a/etc/profile.d/z-env.sh b/etc/profile.d/z-env.sh index fe82f50..2d51b39 100755 --- a/etc/profile.d/z-env.sh +++ b/etc/profile.d/z-env.sh @@ -1,3 +1,8 @@ +if [ "${BASH_SOURCE-}" = "$0" ]; then + echo -e "You must source this script:\n\tsource $0" >&2 + exit 33 +fi + EDITOR=mcedit export EDITOR diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 754eba4..de02975 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -42,6 +42,11 @@ # - http://www.onerussian.com/Linux/bash_history.phtml # - https://debian-administration.org/article/175/BASH_history_forever. +if [ "${BASH_SOURCE-}" = "$0" ]; then + echo -e "You must source this script:\n\tsource $0" >&2 + exit 33 +fi + if [ "$PS1" ] ; then # interactive shell detection # Log the logout event. diff --git a/etc/profile.d/z-time_style.sh b/etc/profile.d/z-time_style.sh index 1412474..9c47dca 100755 --- a/etc/profile.d/z-time_style.sh +++ b/etc/profile.d/z-time_style.sh @@ -1,2 +1,7 @@ +if [ "${BASH_SOURCE-}" = "$0" ]; then + echo -e "You must source this script:\n\tsource $0" >&2 + exit 33 +fi + TIME_STYLE=long-iso export TIME_STYLE From 9026bf704e8287472bff4295d9f193ef7413db5a Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Wed, 3 Apr 2024 10:28:31 +0300 Subject: [PATCH 06/27] Fix ip color on EL 7. iproute2 on EL 7 (ip utility, iproute2-ss170501) does not support --color=auto, only -c[olor]. Signed-off-by: Doncho N. Gunchev --- etc/profile.d/z-aliases.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index 342c14d..cdf9a23 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -13,4 +13,10 @@ alias lll='ls -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' alias less='less -R' # color ip route -alias ip='ip --color=auto' +if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then + # EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0" + alias ip='ip --color=auto' +else + # EL 7 - "ip utility, iproute2-ss170501" + alias ip='ip -c' +fi From 3f8ffe86c98709ba44dd05731777ce10fb0fadb5 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Wed, 3 Apr 2024 10:28:31 +0300 Subject: [PATCH 07/27] Fix ip color on EL 7. iproute2 on EL 7 (ip utility, iproute2-ss170501) does not support --color=auto, only -c[olor]. Signed-off-by: Doncho N. Gunchev --- changelog.sh | 3 +++ gwebu-profile.spec.in | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/changelog.sh b/changelog.sh index 3b89442..5107716 100755 --- a/changelog.sh +++ b/changelog.sh @@ -11,3 +11,6 @@ change="* $(date +'%a %b %d %Y') $(git log -1 --format='%aN <%aE>') - ${rpm_ver} awk -v change="${change}" '/^%changelog/ {print; print change; 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 diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 517cb56..1fcd030 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.0 -Release: 5 +Version: 1.0.1 +Release: 0 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 +* Wed Apr 03 2024 Doncho N. Gunchev - 1.0.1-0 +- Fix ip color on EL 7. + * Thu Feb 22 2024 Doncho N. Gunchev - 1.0.0-4 - General rework of the build process (distribution source and rpm). From 487eb012d02558ef1ab769c56a28d8a338386c35 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Fri, 26 Apr 2024 15:13:11 +0300 Subject: [PATCH 08/27] Let's be MacOS compatible. --- etc/profile.d/z-aliases.sh | 10 ++++++++-- etc/profile.d/z-ps-twtty-7.sh | 4 ++-- gwebu-profile.spec.in | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index cdf9a23..c9541af 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -6,8 +6,14 @@ fi # show hidden files and directories alias l.='ls -d .[^.]* ..?* --color=tty 2>/dev/null' -# long format with ISO dates -alias lll='ls -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' +if ! which ll 2>/dev/null; then + alias ll='ls -l --color=auto' +fi + +if [[ "$OSTYPE" != darwin* ]]; then + # long format with ISO dates + alias lll='ls -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' +fi # color less (restricted) alias less='less -R' diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index de02975..5d1044a 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -52,7 +52,7 @@ if [ "$PS1" ] ; then # interactive shell detection # Log the logout event. function prompt_command_exit() { trap - EXIT - local now=$(date --rfc-3339=ns) + local 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,7 +61,7 @@ function prompt_command_exit() { # Executed before each prompt. Fill the variables needed by PS1 here. function prompt_command() { - local now=$(date --rfc-3339=ns) + local now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds) # Manage the history local HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')" diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 1fcd030..cee66fa 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,6 +1,6 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile -Version: 1.0.1 +Version: 1.0.2 Release: 0 BuildArch: noarch License: GPLv2 @@ -41,6 +41,9 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Fri Apr 26 2024 Doncho N. Gunchev - 1.0.2-0 +- Let's be MacOS compatible. + * Wed Apr 03 2024 Doncho N. Gunchev - 1.0.1-0 - Fix ip color on EL 7. From 0ec8d81216ad9531740cbeb91cbb35cc66925529 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Fri, 26 Apr 2024 16:00:57 +0300 Subject: [PATCH 09/27] Don't add ip aliases on MacOS. --- etc/profile.d/z-aliases.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index c9541af..796eb1a 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -10,19 +10,19 @@ if ! which ll 2>/dev/null; then alias ll='ls -l --color=auto' fi -if [[ "$OSTYPE" != darwin* ]]; then - # long format with ISO dates - alias lll='ls -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' -fi - # color less (restricted) alias less='less -R' -# color ip route -if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then - # EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0" - alias ip='ip --color=auto' -else - # EL 7 - "ip utility, iproute2-ss170501" - alias ip='ip -c' +if [[ "$OSTYPE" != darwin* ]]; then + # long format with ISO dates + alias lll='ls -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' + + # color ip route + if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then + # EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0" + alias ip='ip --color=auto' + else + # EL 7 - "ip utility, iproute2-ss170501" + alias ip='ip -c' + fi fi From 19f325db4c37a2d088ea32209581ded9220f5482 Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Tue, 14 May 2024 10:40:19 +0300 Subject: [PATCH 10/27] Add ls aliases for MacOS (ll, lll). --- etc/profile.d/z-aliases.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index 796eb1a..0b926ec 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -15,7 +15,7 @@ alias less='less -R' if [[ "$OSTYPE" != darwin* ]]; then # long format with ISO dates - alias lll='ls -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' + alias lll='ls --color=auto -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' # color ip route if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then @@ -25,4 +25,8 @@ if [[ "$OSTYPE" != darwin* ]]; then # EL 7 - "ip utility, iproute2-ss170501" alias ip='ip -c' fi +else + # MacOS aliases + alias ll='ls --color=auto -l' + alias lll='ls --color=auto -Al -D "+%Y-%m-%d %H:%M:%S %4Z"' fi From 57b1404c0eca7e389e9c9e55ada464c32b98cc35 Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Tue, 14 May 2024 10:54:50 +0300 Subject: [PATCH 11/27] Fix lll on MacOS. --- etc/profile.d/z-aliases.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index 0b926ec..0aa5fd9 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -28,5 +28,5 @@ if [[ "$OSTYPE" != darwin* ]]; then else # MacOS aliases alias ll='ls --color=auto -l' - alias lll='ls --color=auto -Al -D "+%Y-%m-%d %H:%M:%S %4Z"' + alias lll='ls --color=auto -Al -D "%Y-%m-%d %H:%M:%S %Z"' fi From 2cf378980abecad7d991e02ea0a319ee83fad15d Mon Sep 17 00:00:00 2001 From: Jorge Stefanov Date: Tue, 14 May 2024 11:22:25 +0300 Subject: [PATCH 12/27] adjusted time format for lll --- etc/profile.d/z-aliases.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index 0aa5fd9..1d13aa3 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -15,7 +15,7 @@ alias less='less -R' if [[ "$OSTYPE" != darwin* ]]; then # long format with ISO dates - alias lll='ls --color=auto -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"' + alias lll='ls --color=auto -Al "--time-style=+%Y-%m-%d %H:%M:%S GMT%z"' # color ip route if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then @@ -28,5 +28,5 @@ if [[ "$OSTYPE" != darwin* ]]; then else # MacOS aliases alias ll='ls --color=auto -l' - alias lll='ls --color=auto -Al -D "%Y-%m-%d %H:%M:%S %Z"' + alias lll='ls --color=auto -Al -D "%Y-%m-%d %H:%M:%S GMT%z"' fi From 3df2a4eadee7262ff5a00f17ced9c6d1cdf36a7a Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Thu, 30 May 2024 03:44:09 +0300 Subject: [PATCH 13/27] Add ssh control masters management aliases. Silence a which. --- etc/profile.d/ssh_controlmasters.sh | 9 +++++++++ etc/profile.d/z-aliases.sh | 2 +- gwebu-profile.spec.in | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100755 etc/profile.d/ssh_controlmasters.sh diff --git a/etc/profile.d/ssh_controlmasters.sh b/etc/profile.d/ssh_controlmasters.sh new file mode 100755 index 0000000..5a76d40 --- /dev/null +++ b/etc/profile.d/ssh_controlmasters.sh @@ -0,0 +1,9 @@ +if [ "${BASH_SOURCE-}" = "$0" ]; then + echo -e "You must source this script:\n\tsource $0" >&2 + exit 33 +fi + +# SSH Control Masters tools (setup controlmasters to be in ~/.ssh/controlmasters). +alias ssh_controlmasters_ls='(cd ~/.ssh/controlmasters; ls -A 2>/dev/null || echo "-- No control masters --")' +alias ssh_controlmasters_check='(cd ~/.ssh/controlmasters; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O check "${i%:*}" -p "${i##*:}"; done)' +alias ssh_controlmasters_stop='(cd ~/.ssh/controlmasters; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O stop "${i%:*}" -p "${i##*:}"; done)' diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index 1d13aa3..ffd9259 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -6,7 +6,7 @@ fi # show hidden files and directories alias l.='ls -d .[^.]* ..?* --color=tty 2>/dev/null' -if ! which ll 2>/dev/null; then +if ! which ll >/dev/null 2>&1; then alias ll='ls -l --color=auto' fi diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index cee66fa..a2b9ca6 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: 0 +Release: 5 BuildArch: noarch License: GPLv2 Source0: profile.d-%{version}-%{release}.tar.xz @@ -41,6 +41,21 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Thu May 30 2024 Doncho N. Gunchev - 1.0.2-5 +- Add ssh control masters management aliases. Silence a which. + +* Thu May 30 2024 Jorge Stefanov - 1.0.2-4 +- adjusted time format for lll + +* Tue May 14 2024 Doncho Gunchev - 1.0.2-3 +- Fix lll on MacOS. + +* Tue May 14 2024 Doncho Gunchev - 1.0.2-2 +- Add ls aliases for MacOS (ll, lll). + +* Fri Apr 26 2024 Doncho N. Gunchev - 1.0.2-1 +- Don't add ip aliases on MacOS. + * Fri Apr 26 2024 Doncho N. Gunchev - 1.0.2-0 - Let's be MacOS compatible. From 45d926a3a91256d608638ebcd71656e41f3a922c Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Thu, 30 May 2024 03:57:04 +0300 Subject: [PATCH 14/27] New shebang for changelog.sh, post-commit hook in README.md. --- README.md | 14 ++++++++++++++ changelog.sh | 9 ++++++++- gwebu-profile.spec.in | 7 ++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f96ea2..fa354f7 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,17 @@ This is a collection of /etc/profile.d files used by the gwebu team. Unless explicitly stated in the file itself, the license is [The Unlicense](https://choosealicense.com/licenses/unlicense/). + +## Hooks + +Create the following hook in your local repository to update the RPM changelog for you: + + +```bash +echo '#!/usr/bin/env bash + +set -eu + +./changelog.sh' > .git/hooks/post-commit +chmod a+x .git/hooks/post-commit +``` diff --git a/changelog.sh b/changelog.sh index 5107716..5dc8f29 100755 --- a/changelog.sh +++ b/changelog.sh @@ -1,4 +1,7 @@ -#!/bin/bash +#!/usr/bin/env bash + +set -euo pipefail +shopt -s nullglob dotglob ver=$(git describe --dirty --long --match='v[0-9]*.[0-9]*' | cut -c 2- | cut -d - -f 1,2,4) rpm_ver="${ver%%-*}" @@ -14,3 +17,7 @@ awk -v change="${change}" '/^%changelog/ {print; print change; next} 1' gwebu-pr sed -i "s/Version: .*/Version: ${rpm_ver}/" gwebu-profile.spec.in sed -i "s/Release: .*/Release: ${rpm_numeric_rev}/" gwebu-profile.spec.in + +git add gwebu-profile.spec.in + +echo "gwebu-profile.spec.in changelog updated" diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index a2b9ca6..a03ddce 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: 5 +Release: 6 BuildArch: noarch License: GPLv2 Source0: profile.d-%{version}-%{release}.tar.xz @@ -41,6 +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. + +* Thu May 30 2024 Doncho N. Gunchev - 1.0.2-6 + * Thu May 30 2024 Doncho N. Gunchev - 1.0.2-5 - Add ssh control masters management aliases. Silence a which. From 58223f0e8a7292b16c890f82b9dc9fbc57fe9839 Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Sun, 14 Jul 2024 16:19:38 +0300 Subject: [PATCH 15/27] 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. From b3f0f6635695dc91d42a2c49b92d38ae788a5097 Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Sun, 14 Jul 2024 17:17:48 +0300 Subject: [PATCH 16/27] Quick and dirty build with podman on MacOS. --- Dockerfile-build | 14 ++++++++++++++ Makefile | 11 +++++++++++ build.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 Dockerfile-build create mode 100755 build.sh diff --git a/Dockerfile-build b/Dockerfile-build new file mode 100644 index 0000000..c69d769 --- /dev/null +++ b/Dockerfile-build @@ -0,0 +1,14 @@ +FROM rockylinux:9 as build + +WORKDIR /root/profile.d + +COPY ./ . + +RUN \ + dnf -y update && \ + dnf -y install rpmdevtools make + +# dnf -y install dnf-plugins-core epel-release && \ +# /usr/bin/crb enable && \ + +RUN ./build.sh diff --git a/Makefile b/Makefile index f4a9348..5efc318 100644 --- a/Makefile +++ b/Makefile @@ -47,3 +47,14 @@ changelog: .PHONY: clean clean: rm -rf dist + + +.PHONY: podman_rpm +podman_rpm: + podman buildx build -t podman_rpm_build -f Dockerfile-build . # --platform linux/amd64 + # Extract the RPMs from the container to ./dist/ locally. + if ! test -d dist; then mkdir dist; fi + podman run --rm -d --name=build localhost/podman_rpm_build /usr/bin/bash -c "trap : TERM INT; sleep infinity & wait" + podman cp build:/tmp/RPMS/. ./dist/ + podman stop build + podman image rm localhost/podman_rpm_build diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..95379b3 --- /dev/null +++ b/build.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +set -euo pipefail +shopt -s nullglob dotglob + +if [ "$(uname -s)" != "Linux" ]; then echo "This script only works on Linux!" >&2; exit 254; fi +set -x # debug + +. /etc/os-release +ARCH="${ARCH:-$(uname -m)}" # +VER="${VER:-${VERSION_ID%%\.*}}" # 8 +DIST_PRE="${PLATFORM_ID##*:}" # el8 +DIST="${DIST:-${DIST_PRE%%[0-9]*}}" # el +OUT_DIR="/tmp/RPMS" + +export LANG='en_US.UTF-8' +export LANGUAGE="${LANG}" +export LC_ALL="${LANG}" +export LC_MEASUREMENT="${LANG}" +export LC_MONETARY="${LANG}" +export LC_NUMERIC="${LANG}" +export LC_TIME="${LANG}" + +rm -rf "$OUT_DIR" +mkdir "$OUT_DIR" + +#spectool -g ./*.spec +# +#if [ "$UID" == "0" ]; then +# dnf builddep -y --refresh ./*.spec +#fi + +# make rpmsrc +rpmbuild -ta ./dist/*.tar.xz \ + --define "_sourcedir $PWD/dist" \ + --define "_srcrpmdir $OUT_DIR" \ + --define "_rpmdir $OUT_DIR" \ + +mv "$OUT_DIR"/*/*.rpm "$OUT_DIR/" +rmdir "$OUT_DIR"/* 2>/dev/null || true From 6271df868cd38b0d0ff6f365fd57a66c86fb25a1 Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Mon, 15 Jul 2024 10:54:24 +0300 Subject: [PATCH 17/27] Fix python virtual environment support. This works with python 3.9, 3.10, 3.11 and 3.12 on MacOS. --- Makefile | 12 ++++++------ build.sh | 2 +- etc/profile.d/z-ps-twtty-7.sh | 4 ++-- gwebu-profile.spec.in | 6 +++++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 5efc318..8da1508 100644 --- a/Makefile +++ b/Makefile @@ -11,11 +11,12 @@ help: @echo "▀▀▀▀▀▀" @echo @echo "Available targets:" - @echo " dist: create source distribution package in dist/" - @echo " rpm: create an RPM package" - @echo " changelog: Add a changelog entry to gwebu-profile.spec.in" + @echo " dist: Create source distribution package in dist/." + @echo " rpm: Create an RPM package." + @echo " podman_rpm Create an RPM package using podman on MacOS." + @echo " changelog: Add a changelog entry to gwebu-profile.spec.in." @echo - @echo " clean: clean all generated files" + @echo " clean: Clean all generated files." @echo @echo "Version $(ver), rpm_ver=$(rpm_ver), rpm_rev=$(rpm_rev)." .PHONY: help @@ -50,10 +51,9 @@ clean: .PHONY: podman_rpm -podman_rpm: +podman_rpm: dist podman buildx build -t podman_rpm_build -f Dockerfile-build . # --platform linux/amd64 # Extract the RPMs from the container to ./dist/ locally. - if ! test -d dist; then mkdir dist; fi podman run --rm -d --name=build localhost/podman_rpm_build /usr/bin/bash -c "trap : TERM INT; sleep infinity & wait" podman cp build:/tmp/RPMS/. ./dist/ podman stop build diff --git a/build.sh b/build.sh index 95379b3..b0d3b56 100755 --- a/build.sh +++ b/build.sh @@ -13,7 +13,7 @@ DIST_PRE="${PLATFORM_ID##*:}" # el8 DIST="${DIST:-${DIST_PRE%%[0-9]*}}" # el OUT_DIR="/tmp/RPMS" -export LANG='en_US.UTF-8' +export LANG='C.UTF-8' export LANGUAGE="${LANG}" export LC_ALL="${LANG}" export LC_MEASUREMENT="${LANG}" diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 348ce08..6a06f0f 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -81,9 +81,9 @@ function prompt_command() { local prompt="--($my_D, Err ${my_P[*]}, $my_TTY)---($PWD)--" if [ -n "${VIRTUAL_ENV:-}" ] && [ -n "$_OLD_VIRTUAL_PS1" ]; then - my_VENV="${VIRTUAL_ENV_PROMPT}" + export my_VENV="${VIRTUAL_ENV##*/}" prompt="--($my_D, Err ${my_P[*]}, $my_TTY, $my_VENV)---($PWD)--" - if [ "${PS1:1:${#VIRTUAL_ENV_PROMPT}}" == "$VIRTUAL_ENV_PROMPT" ]; then + 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}" diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 5d0acac..4611bad 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,6 +1,6 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile -Version: 1.0.3 +Version: 1.0.4 Release: 0 BuildArch: noarch License: GPLv2 @@ -41,6 +41,10 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Mon Jul 15 2024 Doncho Gunchev - 1.0.4-0 +- Fix python virtual environment support. + This works on MacOS with python 3.9, 3.10, 3.11 and 3.12. + * Sun Jul 14 2024 Doncho Gunchev - 1.0.3-0 - Initial python virtual environment support. From 2f07d57c8698c49a04fad755409b30cb49361bde Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Tue, 16 Jul 2024 15:29:37 +0300 Subject: [PATCH 18/27] PyCharm virtual environment with poetry support. --- etc/profile.d/z-ps-twtty-7.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 6a06f0f..bc6f513 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -81,7 +81,11 @@ function prompt_command() { local prompt="--($my_D, Err ${my_P[*]}, $my_TTY)---($PWD)--" if [ -n "${VIRTUAL_ENV:-}" ] && [ -n "$_OLD_VIRTUAL_PS1" ]; then - export my_VENV="${VIRTUAL_ENV##*/}" + if [ -n "$VIRTUAL_ENV_PROMPT" ]; then + export my_VENV="$VIRTUAL_ENV_PROMPT" + else + 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. From df3199976e01511d57ee74e11590ceb5eb8aa54c Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Wed, 16 Oct 2024 09:16:22 +0300 Subject: [PATCH 19/27] fix: Don't alias ip if iproute is not installed. --- etc/profile.d/z-aliases.sh | 17 ++++++++++------- gwebu-profile.spec.in | 5 ++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index ffd9259..9c91d7b 100755 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -17,13 +17,16 @@ if [[ "$OSTYPE" != darwin* ]]; then # long format with ISO dates alias lll='ls --color=auto -Al "--time-style=+%Y-%m-%d %H:%M:%S GMT%z"' - # color ip route - if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then - # EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0" - alias ip='ip --color=auto' - else - # EL 7 - "ip utility, iproute2-ss170501" - alias ip='ip -c' + # if there is iproute installed + if command -v ip > /dev/null; then + # color ip route + if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then + # EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0" + alias ip='ip --color=auto' + else + # EL 7 - "ip utility, iproute2-ss170501" + alias ip='ip -c' + fi fi else # MacOS aliases diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 4611bad..2cd6673 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,6 +1,6 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile -Version: 1.0.4 +Version: 1.0.5 Release: 0 BuildArch: noarch License: GPLv2 @@ -41,6 +41,9 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Wed Oct 16 2024 Doncho Gunchev - 1.0.5-0 +- fix: Don't alias ip if iproute is not installed. + * Mon Jul 15 2024 Doncho Gunchev - 1.0.4-0 - Fix python virtual environment support. This works on MacOS with python 3.9, 3.10, 3.11 and 3.12. From 86034e3f026811dcc00e940244f1f2762f51feeb Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Sat, 15 Feb 2025 23:47:35 +0200 Subject: [PATCH 20/27] Improve python virtual environment support (uv). --- etc/profile.d/z-ps-twtty-7.sh | 6 +----- gwebu-profile.spec.in | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index bc6f513..6a06f0f 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -81,11 +81,7 @@ function prompt_command() { 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 - export my_VENV="$VIRTUAL_ENV_PROMPT" - else - export my_VENV="${VIRTUAL_ENV##*/}" - fi + export my_VENV="${VIRTUAL_ENV##*/}" 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. diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 2cd6673..0c2a7a8 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,6 +1,6 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile -Version: 1.0.5 +Version: 1.0.6 Release: 0 BuildArch: noarch License: GPLv2 @@ -41,6 +41,9 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Sat Feb 15 2025 Doncho Gunchev - 1.0.6-0 +- Improve python virtual environment support (uv). + * Wed Oct 16 2024 Doncho Gunchev - 1.0.5-0 - fix: Don't alias ip if iproute is not installed. From 8416585ac7cffb6ec72da5d7844aa68fb71ad5dd Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Sun, 9 Mar 2025 00:25:26 +0200 Subject: [PATCH 21/27] Improve python virtual environment support (uv) take 2. --- README.md | 14 ++------------ changelog.sh | 2 +- etc/profile.d/z-ps-twtty-7.sh | 9 ++++++++- gwebu-profile.spec.in | 5 ++++- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index fa354f7..a068800 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,6 @@ This is a collection of /etc/profile.d files used by the gwebu team. Unless explicitly stated in the file itself, the license is [The Unlicense](https://choosealicense.com/licenses/unlicense/). -## Hooks +## Automation -Create the following hook in your local repository to update the RPM changelog for you: - - -```bash -echo '#!/usr/bin/env bash - -set -eu - -./changelog.sh' > .git/hooks/post-commit -chmod a+x .git/hooks/post-commit -``` +To update the RPM changelog run ./changelog.sh diff --git a/changelog.sh b/changelog.sh index ce2780a..2021c28 100755 --- a/changelog.sh +++ b/changelog.sh @@ -18,6 +18,6 @@ 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 +# git add gwebu-profile.spec.in echo "gwebu-profile.spec.in changelog updated" diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 6a06f0f..551d621 100755 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -81,7 +81,14 @@ function prompt_command() { local prompt="--($my_D, Err ${my_P[*]}, $my_TTY)---($PWD)--" if [ -n "${VIRTUAL_ENV:-}" ] && [ -n "$_OLD_VIRTUAL_PS1" ]; then - export my_VENV="${VIRTUAL_ENV##*/}" + if [ -n "$VIRTUAL_ENV_PROMPT" ]; then + my_VENV="${VIRTUAL_ENV_PROMPT%) }" + my_VENV="${my_VENV%) }" + export 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. diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 0c2a7a8..c33ba8b 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,6 +1,6 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile -Version: 1.0.6 +Version: 1.0.7 Release: 0 BuildArch: noarch License: GPLv2 @@ -41,6 +41,9 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Sun Mar 09 2025 Doncho N. Gunchev - 1.0.7-0 +- Improve python virtual environment support (uv) take 2. + * Sat Feb 15 2025 Doncho Gunchev - 1.0.6-0 - Improve python virtual environment support (uv). From dc39105663b379ace2df216a2c8235578f606b67 Mon Sep 17 00:00:00 2001 From: Doncho Gunchev Date: Tue, 27 May 2025 10:03:07 +0000 Subject: [PATCH 22/27] Shorten ~/.ssh/controlmasters to ~/.ssh/c (104 char limit on mac). --- etc/profile.d/ssh_controlmasters.sh | 8 ++++---- gwebu-profile.spec.in | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/etc/profile.d/ssh_controlmasters.sh b/etc/profile.d/ssh_controlmasters.sh index 5a76d40..8913c35 100755 --- a/etc/profile.d/ssh_controlmasters.sh +++ b/etc/profile.d/ssh_controlmasters.sh @@ -3,7 +3,7 @@ if [ "${BASH_SOURCE-}" = "$0" ]; then exit 33 fi -# SSH Control Masters tools (setup controlmasters to be in ~/.ssh/controlmasters). -alias ssh_controlmasters_ls='(cd ~/.ssh/controlmasters; ls -A 2>/dev/null || echo "-- No control masters --")' -alias ssh_controlmasters_check='(cd ~/.ssh/controlmasters; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O check "${i%:*}" -p "${i##*:}"; done)' -alias ssh_controlmasters_stop='(cd ~/.ssh/controlmasters; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O stop "${i%:*}" -p "${i##*:}"; done)' +# SSH Control Masters tools (setup controlmasters to be in ~/.ssh/c). +alias ssh_controlmasters_ls='(cd ~/.ssh/c; ls -A 2>/dev/null || echo "-- No control masters --")' +alias ssh_controlmasters_check='(cd ~/.ssh/c; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O check "${i%:*}" -p "${i##*:}"; done)' +alias ssh_controlmasters_stop='(cd ~/.ssh/c; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O stop "${i%:*}" -p "${i##*:}"; done)' diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index c33ba8b..d688c47 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: 0 +Release: 1 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 +* Tue May 27 2025 Doncho Gunchev - 1.0.7-1 +- Shorten ~/.ssh/controlmasters to ~/.ssh/c (104 char limit on mac). + * Sun Mar 09 2025 Doncho N. Gunchev - 1.0.7-0 - Improve python virtual environment support (uv) take 2. From affb7ae553c3513834021fa6fc64aed55e7b6965 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Sun, 2 Nov 2025 15:52:41 +0200 Subject: [PATCH 23/27] 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). From b31cb20161a8f326ca149f7e83a0f140102ab260 Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Sun, 2 Nov 2025 15:52:41 +0200 Subject: [PATCH 24/27] Release 1.0.8, update .pre-commit-config.yaml Add how to release notes. --- Dockerfile-build | 6 ++++-- README.md | 27 +++++++++++++++++++++++++++ gwebu-profile.spec.in | 6 +++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Dockerfile-build b/Dockerfile-build index c69d769..8d3edbd 100644 --- a/Dockerfile-build +++ b/Dockerfile-build @@ -4,11 +4,13 @@ WORKDIR /root/profile.d COPY ./ . +# dnf -y update && \ RUN \ - dnf -y update && \ - dnf -y install rpmdevtools make + dnf -y install rpmdevtools make && \ + dnf -y clean all # dnf -y install dnf-plugins-core epel-release && \ # /usr/bin/crb enable && \ +# dnf -y clean all RUN ./build.sh diff --git a/README.md b/README.md index 65f3cd7..67951ef 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,30 @@ Unless explicitly stated in the file itself, the license is [The Unlicense](http To update the RPM changelog run ./changelog.sh Type `make` to see the available targets (dist, rpm, podman_rpm, changelog, clean). + +## Releases + +To create a new release first tag it: + +```shell +git tag -a v1.0.0 -m "Release 1.0.0" +``` + +then run `./release.sh`. At this point + +```shell +git commit -a --ammend +git tag -a v1.0.0 -m "Release 1.0.0" --force +``` + +This is a chicken and egg problem I have not decided how to solve yet. + +Build the RPMs at this point with `make rpm` or `make podman_rpm`. +Once everything is OK push code and the tag. + +```shell +git push +git push --tags +``` + +And draft a new release on GitHub. diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index 50e5cfe..f33e58b 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: 2 +Version: 1.0.8 +Release: 0 BuildArch: noarch License: GPLv2 Source0: profile.d-%{version}-%{release}.tar.xz @@ -41,7 +41,7 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog -* Sun Nov 02 2025 Doncho N. Gunchev - 1.0.7-2 +* Sun Nov 02 2025 Doncho N. Gunchev - 1.0.8-0 - Fixing VENV again... * Tue May 27 2025 Doncho Gunchev - 1.0.7-1 From dbc138e82e23918ff578da67afebbf4391f77a9d Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Fri, 28 Nov 2025 22:06:29 +0200 Subject: [PATCH 25/27] Added AGENTS.md and .editorconfig --- .editorconfig | 27 +++++++++++++++++++++++++++ AGENTS.md | 22 ++++++++++++++++++++++ etc/profile.d/ssh_controlmasters.sh | 0 etc/profile.d/z-aliases.sh | 0 etc/profile.d/z-env.sh | 0 etc/profile.d/z-ps-twtty-7.sh | 0 etc/profile.d/z-time_style.sh | 0 7 files changed, 49 insertions(+) create mode 100644 .editorconfig create mode 100644 AGENTS.md mode change 100755 => 100644 etc/profile.d/ssh_controlmasters.sh mode change 100755 => 100644 etc/profile.d/z-aliases.sh mode change 100755 => 100644 etc/profile.d/z-env.sh mode change 100755 => 100644 etc/profile.d/z-ps-twtty-7.sh mode change 100755 => 100644 etc/profile.d/z-time_style.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a4761e6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,27 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf +# The POSIX standard requires the last line to end with a new line character. +# All UNIX tools expect a new line at the end of files. Most text editors use this convention too. +insert_final_newline = true +trim_trailing_whitespace = true +max_line_length = 120 + +# Matches multiple files with brace expansion notation +# Set default charset and 4 space indentation +[*.{py,txt,md,rst,c,cxx,cpp,h,hpp,hxx,sh,cfg,ini}] +indent_style = space +indent_size = 4 + +[*.{js,json,html,htm,xml,yaml,yml}] +indent_style = space +indent_size = 2 + +# Tab indentation (no size specified) +[{Makefile,*.go}] +indent_style = tab diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..38ea467 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,22 @@ +# AGENTS.md - Repository Guidelines for Agentic Coding + +## Build & Development Commands +- `make help` - Show all available targets +- `make dist` - Create source distribution in dist/ +- `make rpm` - Build RPM package +- `make podman_rpm` - Build RPM using podman (for MacOS) +- `make changelog` - Add changelog entry via ./changelog.sh +- `make clean` - Clean generated files +- Pre-commit hooks run automatically on commit (see .pre-commit-config.yaml) + +## Code Style Guidelines +- **Shell Scripts**: Use bash syntax, source-safe with `${BASH_SOURCE-}` guard +- **File Permissions**: profile.d scripts must be 0644 (install -m 0644) - they are sourced, not executed +- **Line Endings**: LF only (enforced by pre-commit, see .editorconfig) +- **No trailing whitespace** (enforced by pre-commit, see .editorconfig) +- **Error Handling**: Use `command -v` instead of `which` for portability +- **OS Compatibility**: Support both Linux and MacOS with conditional logic +- **Naming**: Profile.d files use `z-.sh` pattern for alphabetical loading +- **Licensing**: The Unlicense unless explicitly stated otherwise +- **Indentation**: 4 spaces for shell scripts (see .editorconfig) +- **Large Files**: Max 64KB (enforced by pre-commit) diff --git a/etc/profile.d/ssh_controlmasters.sh b/etc/profile.d/ssh_controlmasters.sh old mode 100755 new mode 100644 diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh old mode 100755 new mode 100644 diff --git a/etc/profile.d/z-env.sh b/etc/profile.d/z-env.sh old mode 100755 new mode 100644 diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh old mode 100755 new mode 100644 diff --git a/etc/profile.d/z-time_style.sh b/etc/profile.d/z-time_style.sh old mode 100755 new mode 100644 From 82d22c0bf03c2478aca43e21b0a4c56c059eff7e Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Sun, 30 Nov 2025 16:03:58 +0200 Subject: [PATCH 26/27] Update AGENTS.md (anarko/qwen3-coder-flash:30b) --- AGENTS.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 38ea467..201ce83 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,3 +20,12 @@ - **Licensing**: The Unlicense unless explicitly stated otherwise - **Indentation**: 4 spaces for shell scripts (see .editorconfig) - **Large Files**: Max 64KB (enforced by pre-commit) + +## Testing +- No specific testing framework currently used +- Shell scripts should be tested with basic manual verification +- Use `set -euo pipefail` for robust error handling + +## Cursor/Copilot Rules +- No specific .cursorrules or .github/copilot-instructions.md found +- Follow standard shell script best practices From 60e62585eb03dbe915d913f52e65d5431770342b Mon Sep 17 00:00:00 2001 From: "Doncho N. Gunchev" Date: Sun, 30 Nov 2025 16:58:57 +0200 Subject: [PATCH 27/27] Format the code, add fmt and check targets --- AGENTS.md | 6 +- Makefile | 17 +- build.sh | 24 ++- changelog.sh | 2 +- etc/profile.d/ssh_controlmasters.sh | 2 + etc/profile.d/z-aliases.sh | 2 +- etc/profile.d/z-ps-twtty-7.sh | 292 ++++++++++++++-------------- gwebu-profile.spec.in | 5 +- 8 files changed, 188 insertions(+), 162 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 201ce83..d3b6413 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,6 +6,8 @@ - `make rpm` - Build RPM package - `make podman_rpm` - Build RPM using podman (for MacOS) - `make changelog` - Add changelog entry via ./changelog.sh +- `make check` - Run shellcheck on all shell scripts +- `make fmt` - Format all shell scripts with shfmt - `make clean` - Clean generated files - Pre-commit hooks run automatically on commit (see .pre-commit-config.yaml) @@ -14,7 +16,7 @@ - **File Permissions**: profile.d scripts must be 0644 (install -m 0644) - they are sourced, not executed - **Line Endings**: LF only (enforced by pre-commit, see .editorconfig) - **No trailing whitespace** (enforced by pre-commit, see .editorconfig) -- **Error Handling**: Use `command -v` instead of `which` for portability +- **Error Handling**: Use `command -v` instead of `which` for portability, `set -euo pipefail` - **OS Compatibility**: Support both Linux and MacOS with conditional logic - **Naming**: Profile.d files use `z-.sh` pattern for alphabetical loading - **Licensing**: The Unlicense unless explicitly stated otherwise @@ -23,8 +25,8 @@ ## Testing - No specific testing framework currently used +- Use `make check` to lint shell scripts with shellcheck - Shell scripts should be tested with basic manual verification -- Use `set -euo pipefail` for robust error handling ## Cursor/Copilot Rules - No specific .cursorrules or .github/copilot-instructions.md found diff --git a/Makefile b/Makefile index 8da1508..ea433d4 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ SHELL:=/bin/bash # Use bash syntax, mitigates dash's printf on Debian ver:=$(shell git describe --dirty --long --match='v[0-9]*.[0-9]*' | cut -c 2- | cut -d - -f 1,2,4) rpm_ver:=$(firstword $(subst -, ,$(ver))) -rpm_rev:=$(subst $(rpm_ver)-,,$(ver)) -rpm_rev:=$(subst -,_,$(rpm_rev)) +name_rev:=$(subst $(rpm_ver)-,,$(ver)) +rpm_rev:=$(subst -,_,$(name_rev)) help: @@ -15,6 +15,8 @@ help: @echo " rpm: Create an RPM package." @echo " podman_rpm Create an RPM package using podman on MacOS." @echo " changelog: Add a changelog entry to gwebu-profile.spec.in." + @echo " check: Run shellcheck on all shell scripts." + @echo " fmt: Format all shell scripts with shfmt." @echo @echo " clean: Clean all generated files." @echo @@ -45,6 +47,17 @@ changelog: ./changelog.sh +.PHONY: check +check: + shellcheck --shell=bash --external-sources --source-path=etc/profile.d *.sh etc/profile.d/*.sh + rpmlint *.spec.in + + +.PHONY: fmt +fmt: + shfmt -w -i 4 -ci *.sh etc/profile.d/*.sh + + .PHONY: clean clean: rm -rf dist diff --git a/build.sh b/build.sh index b0d3b56..dd98621 100755 --- a/build.sh +++ b/build.sh @@ -3,13 +3,16 @@ set -euo pipefail shopt -s nullglob dotglob -if [ "$(uname -s)" != "Linux" ]; then echo "This script only works on Linux!" >&2; exit 254; fi +if [ "$(uname -s)" != "Linux" ]; then + echo "This script only works on Linux!" >&2 + exit 254 +fi set -x # debug . /etc/os-release -ARCH="${ARCH:-$(uname -m)}" # -VER="${VER:-${VERSION_ID%%\.*}}" # 8 -DIST_PRE="${PLATFORM_ID##*:}" # el8 +ARCH="${ARCH:-$(uname -m)}" # +VER="${VER:-${VERSION_ID%%\.*}}" # 9 +DIST_PRE="${PLATFORM_ID##*:}" # el9 DIST="${DIST:-${DIST_PRE%%[0-9]*}}" # el OUT_DIR="/tmp/RPMS" @@ -24,17 +27,20 @@ export LC_TIME="${LANG}" rm -rf "$OUT_DIR" mkdir "$OUT_DIR" +# Download all sources and patches. #spectool -g ./*.spec # +# Install all build dependencies. #if [ "$UID" == "0" ]; then -# dnf builddep -y --refresh ./*.spec +# dnf builddep -y --refresh ./*.spec #fi -# make rpmsrc +# make dist + rpmbuild -ta ./dist/*.tar.xz \ - --define "_sourcedir $PWD/dist" \ - --define "_srcrpmdir $OUT_DIR" \ - --define "_rpmdir $OUT_DIR" \ + --define "_sourcedir $PWD/dist" \ + --define "_srcrpmdir $OUT_DIR" \ + --define "_rpmdir $OUT_DIR" mv "$OUT_DIR"/*/*.rpm "$OUT_DIR/" rmdir "$OUT_DIR"/* 2>/dev/null || true diff --git a/changelog.sh b/changelog.sh index 2021c28..7bc771e 100755 --- a/changelog.sh +++ b/changelog.sh @@ -12,7 +12,7 @@ change1="* $(date +'%a %b %d %Y') $(git log -1 --format='%aN <%aE>') - ${rpm_ver change2="- $(git log -1 --format=%s)" 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 + >gwebu-profile.spec.tmp && mv gwebu-profile.spec.tmp 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 diff --git a/etc/profile.d/ssh_controlmasters.sh b/etc/profile.d/ssh_controlmasters.sh index 8913c35..a4b8043 100644 --- a/etc/profile.d/ssh_controlmasters.sh +++ b/etc/profile.d/ssh_controlmasters.sh @@ -5,5 +5,7 @@ fi # SSH Control Masters tools (setup controlmasters to be in ~/.ssh/c). alias ssh_controlmasters_ls='(cd ~/.ssh/c; ls -A 2>/dev/null || echo "-- No control masters --")' +# shellcheck disable=SC2154 alias ssh_controlmasters_check='(cd ~/.ssh/c; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O check "${i%:*}" -p "${i##*:}"; done)' +# shellcheck disable=SC2154 alias ssh_controlmasters_stop='(cd ~/.ssh/c; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O stop "${i%:*}" -p "${i##*:}"; done)' diff --git a/etc/profile.d/z-aliases.sh b/etc/profile.d/z-aliases.sh index 9c91d7b..1dbc5e4 100644 --- a/etc/profile.d/z-aliases.sh +++ b/etc/profile.d/z-aliases.sh @@ -18,7 +18,7 @@ if [[ "$OSTYPE" != darwin* ]]; then alias lll='ls --color=auto -Al "--time-style=+%Y-%m-%d %H:%M:%S GMT%z"' # if there is iproute installed - if command -v ip > /dev/null; then + if command -v ip >/dev/null; then # color ip route if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then # EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0" diff --git a/etc/profile.d/z-ps-twtty-7.sh b/etc/profile.d/z-ps-twtty-7.sh index 4abae88..980def4 100644 --- a/etc/profile.d/z-ps-twtty-7.sh +++ b/etc/profile.d/z-ps-twtty-7.sh @@ -51,140 +51,139 @@ if [ "${BASH_SOURCE-}" = "$0" ]; then exit 33 fi -if [ "$PS1" ] ; then # interactive shell detection +if [ "$PS1" ]; then # interactive shell detection -# Log the logout event. -function prompt_command_exit() { - trap - EXIT - 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%/*}" - echo -e "# Logout,$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-local},login=${my_LoginTime:-$now},now=$now\nlogout" >> "$HistFile" -} + # Log the logout event. + function prompt_command_exit() { + trap - EXIT + 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%/*}" + echo -e "# Logout,$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-local},login=${my_LoginTime:-$now},now=$now\nlogout" >>"$HistFile" + } -# Executed before each prompt. Fill the variables needed by PS1 here. -function prompt_command() { - local now - now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds) + # Executed before each prompt. Fill the variables needed by PS1 here. + function prompt_command() { + local now + now=$(date --rfc-3339=ns 2>/dev/null || date -Iseconds) - # Manage the history - local HistFile - HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')" - mkdir -p "${HistFile%/*}" + # Manage the history + local HistFile + HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')" + mkdir -p "${HistFile%/*}" - if [ -z "$my_LoginTime" ]; then - my_LoginTime="$now" - fi - - # Calculate the width of the prompt: - my_TTY="$(tty)" - my_TTY="${my_TTY:5}" # cut the '/dev' part -> tty/1, pts/2... - my_PWD="${PWD}" - # 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%\)}" - my_VENV="${my_VENV#\(}" - else - # Best guess - export my_VENV="${VIRTUAL_ENV##*/}" + if [ -z "$my_LoginTime" ]; then + my_LoginTime="$now" 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}\ + + # Calculate the width of the prompt: + my_TTY="$(tty)" + my_TTY="${my_TTY:5}" # cut the '/dev' part -> tty/1, pts/2... + my_PWD="${PWD}" + # 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%\)}" + my_VENV="${my_VENV#\(}" + else + # Best guess + export my_VENV="${VIRTUAL_ENV##*/}" + 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 + fi - local fill_size=0 - [ -z "${COLUMNS}" ] && COLUMNS=$(tput cols) - ((fill_size=COLUMNS-${#prompt})) - my_FILL="" - if [ "$fill_size" -gt 0 ]; then - my_FILL="────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────" - while [ "$fill_size" -gt ${#my_FILL} ]; do - my_FILL="${my_FILL}${my_FILL}${my_FILL}${my_FILL}" - done - my_FILL="${my_FILL::$fill_size}" - fi + local fill_size=0 + [ -z "${COLUMNS}" ] && COLUMNS=$(tput cols) + ((fill_size = COLUMNS - ${#prompt})) + my_FILL="" + if [ "$fill_size" -gt 0 ]; then + my_FILL="────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────" + while [ "$fill_size" -gt ${#my_FILL} ]; do + my_FILL="${my_FILL}${my_FILL}${my_FILL}${my_FILL}" + done + my_FILL="${my_FILL::$fill_size}" + fi - if [ "$fill_size" -lt 0 ]; then - my_PWD="…${my_PWD:1-$fill_size}" - fi + if [ "$fill_size" -lt 0 ]; then + my_PWD="…${my_PWD:1-$fill_size}" + fi - local OldCmdNo="$CmdNo" # See if we got new command later. - local Cmd - Cmd="$(history 1)" - CmdNo="${Cmd:0:7}" - if [[ -z "$OldCmdNo" ]]; then - Cmd="login" - else - Cmd="${Cmd:7}" - fi - if [ "$OldCmdNo" != "$CmdNo" ]; then # Only save new commands, not empty lines or Ctrl+C. - echo -e "# PIPESTATUS=${my_P[*]},$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-local},login=$my_LoginTime,now=$now\n$Cmd" >> "$HistFile" - fi -} + local OldCmdNo="$CmdNo" # See if we got new command later. + local Cmd + Cmd="$(history 1)" + CmdNo="${Cmd:0:7}" + if [[ -z "$OldCmdNo" ]]; then + Cmd="login" + else + Cmd="${Cmd:7}" + fi + if [ "$OldCmdNo" != "$CmdNo" ]; then # Only save new commands, not empty lines or Ctrl+C. + echo -e "# PIPESTATUS=${my_P[*]},$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-local},login=$my_LoginTime,now=$now\n$Cmd" >>"$HistFile" + fi + } -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\]' + 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 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 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\]' + # shellcheck disable=SC2034 + local GREEN='\[\033[0;32m\]' + # shellcheck disable=SC2034 + local LIGHT_GREEN='\[\033[1;32m\]' - if [ "${UID}" -ne '0' ]; then - # Normal user colors - local C1="${GREEN}" - local C2="${LIGHT_GREEN}" - local C3="${WHITE}" - else - # root user colors - local C1="${LIGHT_RED}" - local C2="${YELLOW}" - local C3="${WHITE}" - fi + if [ "${UID}" -ne '0' ]; then + # Normal user colors + local C1="${GREEN}" + local C2="${LIGHT_GREEN}" + local C3="${WHITE}" + else + # root user colors + local C1="${LIGHT_RED}" + local C2="${YELLOW}" + local C3="${WHITE}" + fi - case "$TERM" in - xterm*) - TITLEBAR='\[\033]0;\u@\h:\w\007\]' - ;; - *) - TITLEBAR='' - ;; - esac + case "$TERM" in + xterm*) + TITLEBAR='\[\033]0;\u@\h:\w\007\]' + ;; + *) + TITLEBAR='' + ;; + esac - export PS1="$TITLEBAR\ -${C1}┌${C2}─(\ + export PS1="$TITLEBAR${C1}┌${C2}─(\ ${C1}\${my_D}${C2}, ${C1}Err ${C3}\${my_P[*]}${C2}, ${C3}\${my_TTY}\ ${C2})─${C1}─\${my_FILL}${C2}─(\ ${C1}\${my_PWD}\ @@ -194,37 +193,38 @@ ${C1}└${C2}─(\ ${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. - # 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 + 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 - # shellcheck disable=SC2128 - PROMPT_COMMAND="$P;${PROMPT_COMMAND}" + PROMPT_COMMAND="$P" fi - else - # shellcheck disable=SC2178 - PROMPT_COMMAND="$P" + unset P + + trap prompt_command_exit EXIT + shopt -s cmdhist histappend + export HISTCONTROL='ignorespace' # ':erasedups' would prevent logging duplicate commands. + export HISTIGNORE='history:history *' + } + + # Secure bash history + if [ ! -d "$HOME/bash_history" ]; then + mkdir -m 0700 "$HOME/bash_history" fi - unset P - trap prompt_command_exit EXIT - shopt -s cmdhist histappend - export HISTCONTROL='ignorespace' # ':erasedups' would prevent logging duplicate commands. - export HISTIGNORE='history:history *' -} - -# Secure bash history -if [ ! -d "$HOME/bash_history" ]; then - mkdir -m 0700 "$HOME/bash_history" -fi - -# call and unset -twtty; unset twtty + # call and unset + twtty + unset twtty fi diff --git a/gwebu-profile.spec.in b/gwebu-profile.spec.in index f33e58b..f238f4f 100644 --- a/gwebu-profile.spec.in +++ b/gwebu-profile.spec.in @@ -1,6 +1,6 @@ Summary: Gwebu profile.d - cool date, prompt with history, aliases Name: gwebu-profile -Version: 1.0.8 +Version: 1.0.9 Release: 0 BuildArch: noarch License: GPLv2 @@ -41,6 +41,9 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/ %changelog +* Sun Nov 30 2025 Doncho N. Gunchev - 1.0.9-0 +- Format the code, add fmt and check targets + * Sun Nov 02 2025 Doncho N. Gunchev - 1.0.8-0 - Fixing VENV again...