mirror of
https://github.com/gwebu-team/profile.d.git
synced 2025-12-07 11:55:48 +00:00
Format the code, add fmt and check targets
Some checks failed
Makefile CI / build (push) Has been cancelled
Some checks failed
Makefile CI / build (push) Has been cancelled
This commit is contained in:
parent
82d22c0bf0
commit
60e62585eb
8 changed files with 188 additions and 162 deletions
|
|
@ -6,6 +6,8 @@
|
||||||
- `make rpm` - Build RPM package
|
- `make rpm` - Build RPM package
|
||||||
- `make podman_rpm` - Build RPM using podman (for MacOS)
|
- `make podman_rpm` - Build RPM using podman (for MacOS)
|
||||||
- `make changelog` - Add changelog entry via ./changelog.sh
|
- `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
|
- `make clean` - Clean generated files
|
||||||
- Pre-commit hooks run automatically on commit (see .pre-commit-config.yaml)
|
- 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
|
- **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)
|
- **Line Endings**: LF only (enforced by pre-commit, see .editorconfig)
|
||||||
- **No trailing whitespace** (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
|
- **OS Compatibility**: Support both Linux and MacOS with conditional logic
|
||||||
- **Naming**: Profile.d files use `z-<name>.sh` pattern for alphabetical loading
|
- **Naming**: Profile.d files use `z-<name>.sh` pattern for alphabetical loading
|
||||||
- **Licensing**: The Unlicense unless explicitly stated otherwise
|
- **Licensing**: The Unlicense unless explicitly stated otherwise
|
||||||
|
|
@ -23,8 +25,8 @@
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
- No specific testing framework currently used
|
- No specific testing framework currently used
|
||||||
|
- Use `make check` to lint shell scripts with shellcheck
|
||||||
- Shell scripts should be tested with basic manual verification
|
- Shell scripts should be tested with basic manual verification
|
||||||
- Use `set -euo pipefail` for robust error handling
|
|
||||||
|
|
||||||
## Cursor/Copilot Rules
|
## Cursor/Copilot Rules
|
||||||
- No specific .cursorrules or .github/copilot-instructions.md found
|
- No specific .cursorrules or .github/copilot-instructions.md found
|
||||||
|
|
|
||||||
17
Makefile
17
Makefile
|
|
@ -1,8 +1,8 @@
|
||||||
SHELL:=/bin/bash # Use bash syntax, mitigates dash's printf on Debian
|
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)
|
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_ver:=$(firstword $(subst -, ,$(ver)))
|
||||||
rpm_rev:=$(subst $(rpm_ver)-,,$(ver))
|
name_rev:=$(subst $(rpm_ver)-,,$(ver))
|
||||||
rpm_rev:=$(subst -,_,$(rpm_rev))
|
rpm_rev:=$(subst -,_,$(name_rev))
|
||||||
|
|
||||||
|
|
||||||
help:
|
help:
|
||||||
|
|
@ -15,6 +15,8 @@ help:
|
||||||
@echo " rpm: Create an RPM package."
|
@echo " rpm: Create an RPM package."
|
||||||
@echo " podman_rpm Create an RPM package using podman on MacOS."
|
@echo " podman_rpm Create an RPM package using podman on MacOS."
|
||||||
@echo " changelog: Add a changelog entry to gwebu-profile.spec.in."
|
@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
|
||||||
@echo " clean: Clean all generated files."
|
@echo " clean: Clean all generated files."
|
||||||
@echo
|
@echo
|
||||||
|
|
@ -45,6 +47,17 @@ changelog:
|
||||||
./changelog.sh
|
./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
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf dist
|
rm -rf dist
|
||||||
|
|
|
||||||
24
build.sh
24
build.sh
|
|
@ -3,13 +3,16 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
shopt -s nullglob dotglob
|
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
|
set -x # debug
|
||||||
|
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
ARCH="${ARCH:-$(uname -m)}" #
|
ARCH="${ARCH:-$(uname -m)}" #
|
||||||
VER="${VER:-${VERSION_ID%%\.*}}" # 8
|
VER="${VER:-${VERSION_ID%%\.*}}" # 9
|
||||||
DIST_PRE="${PLATFORM_ID##*:}" # el8
|
DIST_PRE="${PLATFORM_ID##*:}" # el9
|
||||||
DIST="${DIST:-${DIST_PRE%%[0-9]*}}" # el
|
DIST="${DIST:-${DIST_PRE%%[0-9]*}}" # el
|
||||||
OUT_DIR="/tmp/RPMS"
|
OUT_DIR="/tmp/RPMS"
|
||||||
|
|
||||||
|
|
@ -24,17 +27,20 @@ export LC_TIME="${LANG}"
|
||||||
rm -rf "$OUT_DIR"
|
rm -rf "$OUT_DIR"
|
||||||
mkdir "$OUT_DIR"
|
mkdir "$OUT_DIR"
|
||||||
|
|
||||||
|
# Download all sources and patches.
|
||||||
#spectool -g ./*.spec
|
#spectool -g ./*.spec
|
||||||
#
|
#
|
||||||
|
# Install all build dependencies.
|
||||||
#if [ "$UID" == "0" ]; then
|
#if [ "$UID" == "0" ]; then
|
||||||
# dnf builddep -y --refresh ./*.spec
|
# dnf builddep -y --refresh ./*.spec
|
||||||
#fi
|
#fi
|
||||||
|
|
||||||
# make rpmsrc
|
# make dist
|
||||||
|
|
||||||
rpmbuild -ta ./dist/*.tar.xz \
|
rpmbuild -ta ./dist/*.tar.xz \
|
||||||
--define "_sourcedir $PWD/dist" \
|
--define "_sourcedir $PWD/dist" \
|
||||||
--define "_srcrpmdir $OUT_DIR" \
|
--define "_srcrpmdir $OUT_DIR" \
|
||||||
--define "_rpmdir $OUT_DIR" \
|
--define "_rpmdir $OUT_DIR"
|
||||||
|
|
||||||
mv "$OUT_DIR"/*/*.rpm "$OUT_DIR/"
|
mv "$OUT_DIR"/*/*.rpm "$OUT_DIR/"
|
||||||
rmdir "$OUT_DIR"/* 2>/dev/null || true
|
rmdir "$OUT_DIR"/* 2>/dev/null || true
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ change1="* $(date +'%a %b %d %Y') $(git log -1 --format='%aN <%aE>') - ${rpm_ver
|
||||||
change2="- $(git log -1 --format=%s)"
|
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 \
|
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/Version: .*/Version: ${rpm_ver}/" gwebu-profile.spec.in
|
||||||
sed -i.bak "s/Release: .*/Release: ${rpm_numeric_rev}/" gwebu-profile.spec.in
|
sed -i.bak "s/Release: .*/Release: ${rpm_numeric_rev}/" gwebu-profile.spec.in
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,7 @@ fi
|
||||||
|
|
||||||
# SSH Control Masters tools (setup controlmasters to be in ~/.ssh/c).
|
# 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_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)'
|
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)'
|
alias ssh_controlmasters_stop='(cd ~/.ssh/c; [ "$(ls -A)" ] && for i in *; do echo -n "$i: "; ssh -O stop "${i%:*}" -p "${i##*:}"; done)'
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ if [[ "$OSTYPE" != darwin* ]]; then
|
||||||
alias lll='ls --color=auto -Al "--time-style=+%Y-%m-%d %H:%M:%S GMT%z"'
|
alias lll='ls --color=auto -Al "--time-style=+%Y-%m-%d %H:%M:%S GMT%z"'
|
||||||
|
|
||||||
# if there is iproute installed
|
# if there is iproute installed
|
||||||
if command -v ip > /dev/null; then
|
if command -v ip >/dev/null; then
|
||||||
# color ip route
|
# color ip route
|
||||||
if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then
|
if ip -V | grep '^ip utility, iproute2-.*, libbpf' &>/dev/null; then
|
||||||
# EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0"
|
# EL 8+ - "ip utility, iproute2-6.2.0, libbpf 0.5.0"
|
||||||
|
|
|
||||||
|
|
@ -51,140 +51,139 @@ if [ "${BASH_SOURCE-}" = "$0" ]; then
|
||||||
exit 33
|
exit 33
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$PS1" ] ; then # interactive shell detection
|
if [ "$PS1" ]; then # interactive shell detection
|
||||||
|
|
||||||
# Log the logout event.
|
# Log the logout event.
|
||||||
function prompt_command_exit() {
|
function prompt_command_exit() {
|
||||||
trap - EXIT
|
trap - EXIT
|
||||||
local now
|
local now
|
||||||
now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds)
|
now=$(date --rfc-3339=ns 2>/dev/null || date -Iseconds)
|
||||||
local HistFile
|
local HistFile
|
||||||
HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
||||||
mkdir -p "${HistFile%/*}"
|
mkdir -p "${HistFile%/*}"
|
||||||
echo -e "# Logout,$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-local},login=${my_LoginTime:-$now},now=$now\nlogout" >> "$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.
|
# Executed before each prompt. Fill the variables needed by PS1 here.
|
||||||
function prompt_command() {
|
function prompt_command() {
|
||||||
local now
|
local now
|
||||||
now=$(date --rfc-3339=ns 2> /dev/null || date -Iseconds)
|
now=$(date --rfc-3339=ns 2>/dev/null || date -Iseconds)
|
||||||
|
|
||||||
# Manage the history
|
# Manage the history
|
||||||
local HistFile
|
local HistFile
|
||||||
HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
||||||
mkdir -p "${HistFile%/*}"
|
mkdir -p "${HistFile%/*}"
|
||||||
|
|
||||||
if [ -z "$my_LoginTime" ]; then
|
if [ -z "$my_LoginTime" ]; then
|
||||||
my_LoginTime="$now"
|
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##*/}"
|
|
||||||
fi
|
fi
|
||||||
prompt="--($my_D, Err ${my_P[*]}, $my_TTY, Venv $my_VENV)---($PWD)--"
|
|
||||||
# local ps1_prefix
|
# Calculate the width of the prompt:
|
||||||
ps1_prefix="${_OLD_VIRTUAL_PS1%\$\{my_TTY\}*}\${my_TTY}"
|
my_TTY="$(tty)"
|
||||||
ps1_suffix="${_OLD_VIRTUAL_PS1#"$ps1_prefix"}"
|
my_TTY="${my_TTY:5}" # cut the '/dev' part -> tty/1, pts/2...
|
||||||
# The magic with numbers copies the comma with the colors around it.
|
my_PWD="${PWD}"
|
||||||
export PS1="${ps1_prefix}${ps1_prefix:${#ps1_prefix}-39:30}\
|
# 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}"
|
${ps1_prefix:${#ps1_prefix}-81:14}Venv${ps1_prefix:${#ps1_prefix}-63:14} ${my_VENV}${ps1_suffix}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local fill_size=0
|
local fill_size=0
|
||||||
[ -z "${COLUMNS}" ] && COLUMNS=$(tput cols)
|
[ -z "${COLUMNS}" ] && COLUMNS=$(tput cols)
|
||||||
((fill_size=COLUMNS-${#prompt}))
|
((fill_size = COLUMNS - ${#prompt}))
|
||||||
my_FILL=""
|
my_FILL=""
|
||||||
if [ "$fill_size" -gt 0 ]; then
|
if [ "$fill_size" -gt 0 ]; then
|
||||||
my_FILL="────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
|
my_FILL="────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
|
||||||
while [ "$fill_size" -gt ${#my_FILL} ]; do
|
while [ "$fill_size" -gt ${#my_FILL} ]; do
|
||||||
my_FILL="${my_FILL}${my_FILL}${my_FILL}${my_FILL}"
|
my_FILL="${my_FILL}${my_FILL}${my_FILL}${my_FILL}"
|
||||||
done
|
done
|
||||||
my_FILL="${my_FILL::$fill_size}"
|
my_FILL="${my_FILL::$fill_size}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$fill_size" -lt 0 ]; then
|
if [ "$fill_size" -lt 0 ]; then
|
||||||
my_PWD="…${my_PWD:1-$fill_size}"
|
my_PWD="…${my_PWD:1-$fill_size}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local OldCmdNo="$CmdNo" # See if we got new command later.
|
local OldCmdNo="$CmdNo" # See if we got new command later.
|
||||||
local Cmd
|
local Cmd
|
||||||
Cmd="$(history 1)"
|
Cmd="$(history 1)"
|
||||||
CmdNo="${Cmd:0:7}"
|
CmdNo="${Cmd:0:7}"
|
||||||
if [[ -z "$OldCmdNo" ]]; then
|
if [[ -z "$OldCmdNo" ]]; then
|
||||||
Cmd="login"
|
Cmd="login"
|
||||||
else
|
else
|
||||||
Cmd="${Cmd:7}"
|
Cmd="${Cmd:7}"
|
||||||
fi
|
fi
|
||||||
if [ "$OldCmdNo" != "$CmdNo" ]; then # Only save new commands, not empty lines or Ctrl+C.
|
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"
|
echo -e "# PIPESTATUS=${my_P[*]},$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-local},login=$my_LoginTime,now=$now\n$Cmd" >>"$HistFile"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function twtty {
|
function twtty {
|
||||||
# The special "\[" and "\]" are telling bash that the text enclosed will not move the caret.
|
# The special "\[" and "\]" are telling bash that the text enclosed will not move the caret.
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local GRAY='\[\033[1;30m\]'
|
local GRAY='\[\033[1;30m\]'
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local LIGHT_GRAY='\[\033[0;37m\]'
|
local LIGHT_GRAY='\[\033[0;37m\]'
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local WHITE='\[\033[1;37m\]'
|
local WHITE='\[\033[1;37m\]'
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local NO_COLOUR='\[\033[0m\]'
|
local NO_COLOUR='\[\033[0m\]'
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local LIGHT_BLUE='\[\033[1;34m\]'
|
local LIGHT_BLUE='\[\033[1;34m\]'
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local YELLOW='\[\033[1;33m\]'
|
local YELLOW='\[\033[1;33m\]'
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local RED='\[\033[0;31m\]'
|
local RED='\[\033[0;31m\]'
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local LIGHT_RED='\[\033[1;31m\]'
|
local LIGHT_RED='\[\033[1;31m\]'
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local GREEN='\[\033[0;32m\]'
|
local GREEN='\[\033[0;32m\]'
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local LIGHT_GREEN='\[\033[1;32m\]'
|
local LIGHT_GREEN='\[\033[1;32m\]'
|
||||||
|
|
||||||
if [ "${UID}" -ne '0' ]; then
|
if [ "${UID}" -ne '0' ]; then
|
||||||
# Normal user colors
|
# Normal user colors
|
||||||
local C1="${GREEN}"
|
local C1="${GREEN}"
|
||||||
local C2="${LIGHT_GREEN}"
|
local C2="${LIGHT_GREEN}"
|
||||||
local C3="${WHITE}"
|
local C3="${WHITE}"
|
||||||
else
|
else
|
||||||
# root user colors
|
# root user colors
|
||||||
local C1="${LIGHT_RED}"
|
local C1="${LIGHT_RED}"
|
||||||
local C2="${YELLOW}"
|
local C2="${YELLOW}"
|
||||||
local C3="${WHITE}"
|
local C3="${WHITE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$TERM" in
|
case "$TERM" in
|
||||||
xterm*)
|
xterm*)
|
||||||
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
|
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
TITLEBAR=''
|
TITLEBAR=''
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
export PS1="$TITLEBAR\
|
export PS1="$TITLEBAR${C1}┌${C2}─(\
|
||||||
${C1}┌${C2}─(\
|
|
||||||
${C1}\${my_D}${C2}, ${C1}Err ${C3}\${my_P[*]}${C2}, ${C3}\${my_TTY}\
|
${C1}\${my_D}${C2}, ${C1}Err ${C3}\${my_P[*]}${C2}, ${C3}\${my_TTY}\
|
||||||
${C2})─${C1}─\${my_FILL}${C2}─(\
|
${C2})─${C1}─\${my_FILL}${C2}─(\
|
||||||
${C1}\${my_PWD}\
|
${C1}\${my_PWD}\
|
||||||
|
|
@ -194,37 +193,38 @@ ${C1}└${C2}─(\
|
||||||
${C1}\${USER}${C2}@${C1}\${HOSTNAME%%.*}\
|
${C1}\${USER}${C2}@${C1}\${HOSTNAME%%.*}\
|
||||||
${C2})${C3}\$${NO_COLOUR} "
|
${C2})${C3}\$${NO_COLOUR} "
|
||||||
|
|
||||||
export PS2="${C2}─${C1}─${C1}─${NO_COLOUR} \[\033[K\]"
|
export PS2="${C2}─${C1}─${C1}─${NO_COLOUR} \[\033[K\]"
|
||||||
# Set my_P to the exit codes of the last command pipe.
|
# Set my_P to the exit codes of the last command pipe.
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
local P='my_P=("${PIPESTATUS[@]}");prompt_command'
|
local P='my_P=("${PIPESTATUS[@]}");prompt_command'
|
||||||
if declare -p PROMPT_COMMAND &>/dev/null; then
|
if declare -p PROMPT_COMMAND &>/dev/null; then
|
||||||
local re='^declare -a '
|
local re='^declare -a '
|
||||||
if [[ "$(declare -p PROMPT_COMMAND)" =~ $re ]]; then # Array, supported since bash 5.1
|
if [[ "$(declare -p PROMPT_COMMAND)" =~ $re ]]; then # Array, supported since bash 5.1
|
||||||
PROMPT_COMMAND=("$P" "${PROMPT_COMMAND[@]}")
|
PROMPT_COMMAND=("$P" "${PROMPT_COMMAND[@]}")
|
||||||
else # String
|
else # String
|
||||||
|
# shellcheck disable=SC2178
|
||||||
|
# shellcheck disable=SC2128
|
||||||
|
PROMPT_COMMAND="$P;${PROMPT_COMMAND}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
# shellcheck disable=SC2178
|
# shellcheck disable=SC2178
|
||||||
# shellcheck disable=SC2128
|
PROMPT_COMMAND="$P"
|
||||||
PROMPT_COMMAND="$P;${PROMPT_COMMAND}"
|
|
||||||
fi
|
fi
|
||||||
else
|
unset P
|
||||||
# shellcheck disable=SC2178
|
|
||||||
PROMPT_COMMAND="$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
|
fi
|
||||||
unset P
|
|
||||||
|
|
||||||
trap prompt_command_exit EXIT
|
# call and unset
|
||||||
shopt -s cmdhist histappend
|
twtty
|
||||||
export HISTCONTROL='ignorespace' # ':erasedups' would prevent logging duplicate commands.
|
unset twtty
|
||||||
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
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
Summary: Gwebu profile.d - cool date, prompt with history, aliases
|
Summary: Gwebu profile.d - cool date, prompt with history, aliases
|
||||||
Name: gwebu-profile
|
Name: gwebu-profile
|
||||||
Version: 1.0.8
|
Version: 1.0.9
|
||||||
Release: 0
|
Release: 0
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
License: GPLv2
|
License: GPLv2
|
||||||
|
|
@ -41,6 +41,9 @@ install -m 0644 etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d/
|
||||||
|
|
||||||
|
|
||||||
%changelog
|
%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
|
* Sun Nov 02 2025 Doncho N. Gunchev <dgunchev@gmail.com> - 1.0.8-0
|
||||||
- Fixing VENV again...
|
- Fixing VENV again...
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue