mirror of
https://github.com/gwebu-team/profile.d.git
synced 2025-12-11 13:15:45 +00:00
Compare commits
27 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60e62585eb | |||
| 82d22c0bf0 | |||
| dbc138e82e | |||
| b31cb20161 | |||
| affb7ae553 | |||
|
|
dc39105663 | ||
| 8416585ac7 | |||
|
|
86034e3f02 | ||
|
|
df3199976e | ||
|
|
2f07d57c86 | ||
|
|
6271df868c | ||
|
|
b3f0f66356 | ||
|
|
58223f0e8a | ||
| 45d926a3a9 | |||
| 3df2a4eade | |||
|
|
2cf378980a | ||
|
|
57b1404c0e | ||
|
|
19f325db4c | ||
| 0ec8d81216 | |||
| 487eb012d0 | |||
| 3f8ffe86c9 | |||
| 9026bf704e | |||
| dc0be5c2a1 | |||
| 5b8a75b75c | |||
| e68638230a | |||
| bce45e0c3e | |||
| 08548e7a56 |
18 changed files with 599 additions and 166 deletions
27
.editorconfig
Normal file
27
.editorconfig
Normal file
|
|
@ -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
|
||||
7
.gitattributes
vendored
Normal file
7
.gitattributes
vendored
Normal file
|
|
@ -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
|
||||
39
.github/workflows/makefile.yml
vendored
Normal file
39
.github/workflows/makefile.yml
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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: 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
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
|||
/.idea
|
||||
/dist
|
||||
/gwebu-profile.spec
|
||||
|
|
|
|||
19
.pre-commit-config.yaml
Normal file
19
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v6.0.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
|
||||
33
AGENTS.md
Normal file
33
AGENTS.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# 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 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)
|
||||
|
||||
## 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, `set -euo pipefail`
|
||||
- **OS Compatibility**: Support both Linux and MacOS with conditional logic
|
||||
- **Naming**: Profile.d files use `z-<name>.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)
|
||||
|
||||
## 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
|
||||
|
||||
## Cursor/Copilot Rules
|
||||
- No specific .cursorrules or .github/copilot-instructions.md found
|
||||
- Follow standard shell script best practices
|
||||
16
Dockerfile-build
Normal file
16
Dockerfile-build
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
FROM rockylinux:9 as build
|
||||
|
||||
WORKDIR /root/profile.d
|
||||
|
||||
COPY ./ .
|
||||
|
||||
# dnf -y update && \
|
||||
RUN \
|
||||
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
|
||||
54
Makefile
54
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-)
|
||||
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)))
|
||||
name_rev:=$(subst $(rpm_ver)-,,$(ver))
|
||||
rpm_rev:=$(subst -,_,$(name_rev))
|
||||
|
||||
|
||||
help:
|
||||
|
|
@ -8,19 +11,30 @@ help:
|
|||
@echo "▀▀▀▀▀▀"
|
||||
@echo
|
||||
@echo "Available targets:"
|
||||
@echo " dist: create source distribution package in dist/"
|
||||
@echo " rpm: create an RPM package"
|
||||
@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 " check: Run shellcheck on all shell scripts."
|
||||
@echo " fmt: Format all shell scripts with shfmt."
|
||||
@echo
|
||||
@echo " clean: clean all generated files"
|
||||
@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 +42,32 @@ rpm: dist
|
|||
rpmbuild -ta "dist/profile.d-$(ver).tar.xz"
|
||||
|
||||
|
||||
.PHONY: changelog
|
||||
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
|
||||
|
||||
|
||||
.PHONY: 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.
|
||||
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
|
||||
|
|
|
|||
33
README.md
33
README.md
|
|
@ -2,3 +2,36 @@
|
|||
|
||||
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/).
|
||||
|
||||
## Automation
|
||||
|
||||
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.
|
||||
|
|
|
|||
46
build.sh
Executable file
46
build.sh
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/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%%\.*}}" # 9
|
||||
DIST_PRE="${PLATFORM_ID##*:}" # el9
|
||||
DIST="${DIST:-${DIST_PRE%%[0-9]*}}" # el
|
||||
OUT_DIR="/tmp/RPMS"
|
||||
|
||||
export LANG='C.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"
|
||||
|
||||
# Download all sources and patches.
|
||||
#spectool -g ./*.spec
|
||||
#
|
||||
# Install all build dependencies.
|
||||
#if [ "$UID" == "0" ]; then
|
||||
# dnf builddep -y --refresh ./*.spec
|
||||
#fi
|
||||
|
||||
# make dist
|
||||
|
||||
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
|
||||
23
changelog.sh
Executable file
23
changelog.sh
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/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%%-*}"
|
||||
rpm_rev="${ver#*-}"
|
||||
rpm_numeric_rev="${rpm_rev%%-*}"
|
||||
|
||||
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 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.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
|
||||
|
||||
echo "gwebu-profile.spec.in changelog updated"
|
||||
11
etc/profile.d/ssh_controlmasters.sh
Normal file
11
etc/profile.d/ssh_controlmasters.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
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/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)'
|
||||
32
etc/profile.d/z-aliases.sh
Executable file → Normal file
32
etc/profile.d/z-aliases.sh
Executable file → Normal file
|
|
@ -1,11 +1,35 @@
|
|||
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'
|
||||
|
||||
# long format with ISO dates
|
||||
alias lll='ls -Al "--time-style=+%Y-%m-%d %H:%M:%S %4Z"'
|
||||
if ! which ll >/dev/null 2>&1; then
|
||||
alias ll='ls -l --color=auto'
|
||||
fi
|
||||
|
||||
# color less (restricted)
|
||||
alias less='less -R'
|
||||
|
||||
# color ip route
|
||||
alias ip='ip --color=auto'
|
||||
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"'
|
||||
|
||||
# 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
|
||||
alias ll='ls --color=auto -l'
|
||||
alias lll='ls --color=auto -Al -D "%Y-%m-%d %H:%M:%S GMT%z"'
|
||||
fi
|
||||
|
|
|
|||
5
etc/profile.d/z-env.sh
Executable file → Normal file
5
etc/profile.d/z-env.sh
Executable file → Normal file
|
|
@ -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
|
||||
|
||||
|
|
|
|||
271
etc/profile.d/z-ps-twtty-7.sh
Executable file → Normal file
271
etc/profile.d/z-ps-twtty-7.sh
Executable file → Normal file
|
|
@ -1,5 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
# DESCRIPTION
|
||||
# ===========
|
||||
# An attempt to seize industrial… ops, I ment an attempt to make my
|
||||
|
|
@ -13,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 <dgunchev@gmail.com>, 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 <dgunchev@gmail.com>, 2024-01-27 15:58 EET
|
||||
# Show PIPESTATUS instead of just $?. Cleanup.
|
||||
|
|
@ -44,106 +46,144 @@
|
|||
# - http://www.onerussian.com/Linux/bash_history.phtml
|
||||
# - https://debian-administration.org/article/175/BASH_history_forever.
|
||||
|
||||
if [ "$PS1" ] ; then # interactive shell detection
|
||||
if [ "${BASH_SOURCE-}" = "$0" ]; then
|
||||
echo -e "You must source this script:\n\tsource $0" >&2
|
||||
exit 33
|
||||
fi
|
||||
|
||||
# Log the logout event.
|
||||
function prompt_command_exit() {
|
||||
trap - EXIT
|
||||
local now=$(date --rfc-3339=ns)
|
||||
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"
|
||||
}
|
||||
if [ "$PS1" ]; then # interactive shell detection
|
||||
|
||||
# Executed before each prompt. Fill the variables needed by PS1 here.
|
||||
function prompt_command() {
|
||||
local now=$(date --rfc-3339=ns)
|
||||
# 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"
|
||||
}
|
||||
|
||||
# Manage the history
|
||||
local HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
||||
mkdir -p "${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)
|
||||
|
||||
if [ -z "$my_LoginTime" ]; then
|
||||
my_LoginTime="$now"
|
||||
fi
|
||||
# Manage the history
|
||||
local HistFile
|
||||
HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
||||
mkdir -p "${HistFile%/*}"
|
||||
|
||||
# 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.
|
||||
local prompt="--($my_D, Err ${my_P[*]}, $my_TTY)---($PWD)--"
|
||||
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 [ -z "$my_LoginTime" ]; then
|
||||
my_LoginTime="$now"
|
||||
fi
|
||||
|
||||
if [ "$fill_size" -lt 0 ]; then
|
||||
my_PWD="…${my_PWD:1-$fill_size}"
|
||||
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)--"
|
||||
|
||||
local OldCmdNo="$CmdNo" # See if we got new command later.
|
||||
local 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
|
||||
}
|
||||
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
|
||||
|
||||
function twtty {
|
||||
# The special "\[" and "\]" are telling bash that the text enclosed will not move the caret.
|
||||
local GRAY='\[\033[1;30m\]'
|
||||
local LIGHT_GRAY='\[\033[0;37m\]'
|
||||
local WHITE='\[\033[1;37m\]'
|
||||
local NO_COLOUR='\[\033[0m\]'
|
||||
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 LIGHT_BLUE='\[\033[1;34m\]'
|
||||
local YELLOW='\[\033[1;33m\]'
|
||||
if [ "$fill_size" -lt 0 ]; then
|
||||
my_PWD="…${my_PWD:1-$fill_size}"
|
||||
fi
|
||||
|
||||
local RED='\[\033[0;31m\]'
|
||||
local LIGHT_RED='\[\033[1;31m\]'
|
||||
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 GREEN='\[\033[0;32m\]'
|
||||
local LIGHT_GREEN='\[\033[1;32m\]'
|
||||
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\]'
|
||||
|
||||
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
|
||||
# shellcheck disable=SC2034
|
||||
local LIGHT_BLUE='\[\033[1;34m\]'
|
||||
# shellcheck disable=SC2034
|
||||
local YELLOW='\[\033[1;33m\]'
|
||||
|
||||
case "$TERM" in
|
||||
xterm*)
|
||||
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
|
||||
;;
|
||||
*)
|
||||
TITLEBAR=''
|
||||
;;
|
||||
esac
|
||||
# shellcheck disable=SC2034
|
||||
local RED='\[\033[0;31m\]'
|
||||
# shellcheck disable=SC2034
|
||||
local LIGHT_RED='\[\033[1;31m\]'
|
||||
|
||||
export PS1="$TITLEBAR\
|
||||
${C1}┌${C2}─(\
|
||||
# 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
|
||||
|
||||
case "$TERM" in
|
||||
xterm*)
|
||||
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
|
||||
;;
|
||||
*)
|
||||
TITLEBAR=''
|
||||
;;
|
||||
esac
|
||||
|
||||
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}\
|
||||
|
|
@ -153,33 +193,38 @@ ${C1}└${C2}─(\
|
|||
${C1}\${USER}${C2}@${C1}\${HOSTNAME%%.*}\
|
||||
${C2})${C3}\$${NO_COLOUR} "
|
||||
|
||||
export PS2="${C2}─${C1}─${C1}─${NO_COLOUR} \[\033[K\]"
|
||||
|
||||
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
|
||||
PROMPT_COMMAND="$P;${PROMPT_COMMAND}"
|
||||
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
|
||||
else
|
||||
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
|
||||
|
|
|
|||
5
etc/profile.d/z-time_style.sh
Executable file → Normal file
5
etc/profile.d/z-time_style.sh
Executable file → Normal file
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
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
|
||||
BuildArch: noarch
|
||||
Requires: bash >= 4
|
||||
|
||||
%description
|
||||
This package contains:
|
||||
- z-aliases.sh:
|
||||
a few useful aliases (l., lll) and colors for ip and less.
|
||||
- z-env.sh:
|
||||
default editor, history size and fzf integration.
|
||||
- z-ps-twtty-7.sh:
|
||||
Cool prompt with history organized year-month directories and day by day files.
|
||||
- z-time_style.sh:
|
||||
sets TIME_STYLE=long-iso
|
||||
|
||||
All these reside in /etc/profile.d/.
|
||||
|
||||
%prep
|
||||
%setup -q # -n profile.d-%{version}
|
||||
|
||||
%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
|
||||
* Wed Feb 21 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.0-3
|
||||
- Minor updates.
|
||||
|
||||
* Wed Feb 14 2024 Valentin Todorov <vtodorov@ctw.travel> - 1.0-1
|
||||
- Initial package.
|
||||
100
gwebu-profile.spec.in
Normal file
100
gwebu-profile.spec.in
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
Summary: Gwebu profile.d - cool date, prompt with history, aliases
|
||||
Name: gwebu-profile
|
||||
Version: 1.0.9
|
||||
Release: 0
|
||||
BuildArch: noarch
|
||||
License: GPLv2
|
||||
Source0: profile.d-%{version}-%{release}.tar.xz
|
||||
Requires: bash >= 4
|
||||
|
||||
|
||||
%description
|
||||
This package contains:
|
||||
- z-aliases.sh:
|
||||
a few useful aliases (l., lll) and colors for ip and less.
|
||||
- z-env.sh:
|
||||
default editor, history size and fzf integration.
|
||||
- z-ps-twtty-7.sh:
|
||||
Cool prompt with history organized year-month directories and day by day files.
|
||||
- z-time_style.sh:
|
||||
sets TIME_STYLE=long-iso
|
||||
|
||||
All these reside in /etc/profile.d/.
|
||||
|
||||
|
||||
%prep
|
||||
%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
|
||||
* Sun Nov 30 2025 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.9-0
|
||||
- Format the code, add fmt and check targets
|
||||
|
||||
* Sun Nov 02 2025 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.8-0
|
||||
- Fixing VENV again...
|
||||
|
||||
* Tue May 27 2025 Doncho Gunchev <doncho.gunchev@flyr.com> - 1.0.7-1
|
||||
- Shorten ~/.ssh/controlmasters to ~/.ssh/c (104 char limit on mac).
|
||||
|
||||
* Sun Mar 09 2025 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.7-0
|
||||
- Improve python virtual environment support (uv) take 2.
|
||||
|
||||
* Sat Feb 15 2025 Doncho Gunchev <doncho.gunchev@flyrlabs.com> - 1.0.6-0
|
||||
- Improve python virtual environment support (uv).
|
||||
|
||||
* Wed Oct 16 2024 Doncho Gunchev <doncho.gunchev@flyrlabs.com> - 1.0.5-0
|
||||
- fix: Don't alias ip if iproute is not installed.
|
||||
|
||||
* Mon Jul 15 2024 Doncho Gunchev <doncho.gunchev@flyrlabs.com> - 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 <doncho.gunchev@flyrlabs.com> - 1.0.3-0
|
||||
- Initial python virtual environment support.
|
||||
|
||||
* Thu May 30 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.2-6
|
||||
- New shebang for changelog.sh, post-commit hook in README.md.
|
||||
|
||||
* Thu May 30 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.2-5
|
||||
- Add ssh control masters management aliases. Silence a which.
|
||||
|
||||
* Thu May 30 2024 Jorge Stefanov <georgi.stefanov@flyrlabs.com> - 1.0.2-4
|
||||
- adjusted time format for lll
|
||||
|
||||
* Tue May 14 2024 Doncho Gunchev <doncho.gunchev@flyrlabs.com> - 1.0.2-3
|
||||
- Fix lll on MacOS.
|
||||
|
||||
* Tue May 14 2024 Doncho Gunchev <doncho.gunchev@flyrlabs.com> - 1.0.2-2
|
||||
- Add ls aliases for MacOS (ll, lll).
|
||||
|
||||
* Fri Apr 26 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.2-1
|
||||
- Don't add ip aliases on MacOS.
|
||||
|
||||
* Fri Apr 26 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.2-0
|
||||
- Let's be MacOS compatible.
|
||||
|
||||
* Wed Apr 03 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.1-0
|
||||
- Fix ip color on EL 7.
|
||||
|
||||
* Thu Feb 22 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.0-4
|
||||
- General rework of the build process (distribution source and rpm).
|
||||
|
||||
* Wed Feb 21 2024 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.0-3
|
||||
- Minor updates.
|
||||
|
||||
* Wed Feb 14 2024 Valentin Todorov <vtodorov@ctw.travel> - 1.0-1
|
||||
- Initial package.
|
||||
Loading…
Add table
Add a link
Reference in a new issue