git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/.bash
diff options
context:
space:
mode:
Diffstat (limited to '.bash')
-rw-r--r--.bash/aliases.bash210
-rw-r--r--.bash/exec.bash17
-rw-r--r--.bash/postexec.bash24
-rw-r--r--.bash/prompt.bash155
-rw-r--r--.bash/vars.bash47
5 files changed, 412 insertions, 41 deletions
diff --git a/.bash/aliases.bash b/.bash/aliases.bash
index 86334b7..42e1639 100644
--- a/.bash/aliases.bash
+++ b/.bash/aliases.bash
@@ -6,18 +6,37 @@
if [ "$TERM" != "dumb" ];then
eval "$(dircolors -b)"
alias ls="ls --color=auto"
- alias grep="grep --color=auto"
- alias egrep="egrep --color=auto"
+ case "$OSNAME" in
+ 'sunos') ;;
+ *)
+ alias grep="grep --color=auto"
+ alias egrep="egrep --color=auto"
+ ;;
+ esac
+fi
+# shellcheck disable=SC2139
+if [ -n "$EDITOR" ]; then
+ alias editor="$EDITOR"
+elif [ -n "$VISUAL" ]; then
+ alias editor="$VISUAL"
+elif [ -x "/usr/bin/vim" ]; then
+ alias editor="/usr/bin/vim"
+elif [ -x "/usr/bin/vi" ]; then
+ alias editor="/usr/bin/vi"
+else
+ alias editor="/usr/bin/edit"
fi
alias lst="ls -l --time-style=full-iso"
alias cls=' echo -ne "\033c"'
alias pip-update="sudo pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip install -U"
alias matrix='cmatrix -sbu6 -C cyan'
+alias tbc='tbclock -e -H2 -M7 -S3'
command -v colordiff >/dev/null 2>&1&&alias diff="colordiff"
-command -v colormake >/dev/null 2>&1&&alias make="colormake"
+#command -v colormake >/dev/null 2>&1&&alias make="colormake"
alias perllint="perl -Mstrict -Mdiagnostics -cw"
alias scredit='gimp "${SCRSHDIR}/$(ls -rt1 $SCRSHDIR/|tail -n1)"'
alias scrview='pqiv -i "${SCRSHDIR}/$(ls -rt1 $SCRSHDIR/|tail -n1)"'
+alias scrls='ls -l "${SCRSHDIR}/$(ls -rt1 $SCRSHDIR/|tail -n1)"'
alias fuck='sudo $(history -p \!\!)'
alias x509-out='openssl x509 -text -certopt no_version,no_pubkey,no_sigdump,no_aux,no_header -noout -in'
alias isocreate='rm -vf /tmp/image.iso && mkisofs -v -r -J -translation-table -hide-joliet-trans-tbl -iso-level 4 -o /tmp/image.iso'
@@ -73,7 +92,7 @@ alias sshk='ssh -o PasswordAuthentication=yes -o PreferredAuthentications=keyboa
alias sshg="ssh-with-gpg"
function add-sshagent-init {
for KEY in "${SSHKEYS[@]}";do
- FFPRINT="$(ssh-keygen -Esha256 -lf "$KEY")"
+ FFPRINT="$(ssh-keygen -Esha256 -lf "$KEY")" || return 1
if ! ssh-add -l 2>/dev/null | grep "$FFPRINT" >/dev/null; then
ssh-add -q "$KEY"
fi
@@ -90,11 +109,51 @@ xstat() {
printf "%s\t%s\n" "${crtime}" "${target}"
done
}
+# ----- DECORATIVE STUFF ----- #
+function coleval {
+ mycols="$COLUMNS"
+ if [ -z "$COLUMNS" ]; then mycols="$(tput cols 2>/dev/null)"; fi
+ if [ -z "$COLUMNS" ]; then mycols=20; fi
+ printf '%b' "$mycols"
+}
+function hsep {
+ mycols="$(coleval)"
+ nocalc=0
+ declare mychar
+ while [ "$#" -gt 0 ]; do
+ case "$1" in
+ '-i') nocalc=1; shift ;;
+ *) mychar="$1"; shift ;;
+ esac
+ done
+ [ -z "$mychar" ] && return 1
+ [ "$(printf '%b' "$mychar" | wc --chars)" -ne 1 ] && return 2
+ if [ "$nocalc" -ne 1 ]; then
+ # if we encounter a one-char three-byte character, we may have hit a Unicode
+ # symbol that indeed is a little wider. Use bashes mathematical division- it rounds
+ # down, but this is what we want as we cannot split a character into parts :-)
+ # The result might be significantly narrower than the terminal's width, but for
+ # now we don't have any better math.
+ [ "$(printf '%b' "$mychar" | wc --bytes)" -eq 3 ] && mycols="$(( 4 * mycols / 9 ))"
+ fi
+ for (( i=0;i<mycols;++i )); do
+ printf '%b' "$mychar"
+ done
+ printf '\n'
+}
+alias hdash='hsep "-"'
+alias hddash='hsep "="'
+#alias hline='hsep -i "─"'
+alias hline='hsep -i "─"'
+alias hdline='hsep -i "═"'
+alias hfline='hsep -i "━"'
# ----- PACKAGE MANAGERS ----- #
-if [ -x "/usr/bin/pikaur" ];then
- alias pkgclean="pikaur --no-confirm -Sc"
+if [ -x "/usr/bin/paru" ];then
+ alias pkgclean="paru --noconfirm -Sc"
+elif [ -x "/usr/bin/pikaur" ];then
+ alias pkgclean="pikaur --noconfirm -Sc"
elif [ -x "/usr/bin/pacman" ];then
- alias pkgclean="/usr/bin/sudo /usr/bin/pacman --no-confirm -Sc"
+ alias pkgclean="/usr/bin/sudo /usr/bin/pacman --noconfirm -Sc"
elif [ -x "/usr/bin/apt" ];then
alias pkgclean="/usr/bin/sudo /usr/bin/apt clean"
elif [ -x "/usr/bin/dnf" ];then
@@ -102,6 +161,8 @@ elif [ -x "/usr/bin/dnf" ];then
elif [ -x "/usr/bin/zypper" ];then
alias pkgclean="/usr/bin/sudo /usr/bin/zypper clean"
fi
+# ----- RPM ----- #
+alias rpm-listkeys="rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} | %{summary}\n'"
# ----- GRAFANA ----- #
if command -v grafana-cli >/dev/null;then
alias gfpi='sudo grafana-cli plugins install'
@@ -160,6 +221,7 @@ alias certshow="certmgr -L -n"
# ----- APPLICATION CONTROL ----- #
alias browser-set='xdg-settings set default-web-browser'
alias browser-get='xdg-settings get default-web-browser'
+alias default-desktop-apps="editor ~/.config/mimeapps.list"
# ----- CONTAINERS ----- #
if command -v podman >/dev/null;then
alias pcl="podman container list"
@@ -185,3 +247,137 @@ if command -v podman >/dev/null;then
alias pnd="podman network disconnect"
alias ppd="podman pod stop"
fi
+# ----- PUPPET + RUBY ----- #
+# ...yeah, I'm mostly doing ruby stuff for Puppet, erm I mean
+# OpenVox (now that Perforce have turned the Puppet world to a burning heap of garbage)
+alias bake="bundle exec rake"
+# ----- SOFTWARE MGMT ----- #
+# We may want to avoid having old $things[] running on our machine. While package managers
+# should be the absolute priority, there may be things like Ruby gems, Python packages,
+# Rust crates which we may need especially on anything other than an Arch machine.
+# Define a function that runs all updates.
+# This does not care about isolated venv/bundle/whatnot directories, it maintains
+# the installations in the standard user home folders explicitly.
+# DANGER: this may lead to breaking changes in one language while the others still perform
+# fine.
+function update-user-extensions {
+ mystrt='\033[38;2;23;147;209m'
+ mywarn='\033[38;5;178m'
+ mydone='\033[38;5;71m'
+ myrset='\033[0m'
+ # Ruby / user's gems
+ if [ -x '/usr/bin/gem' ]; then
+ printf '%bRuby (through gem)%b\n' "$mystrt" "$myrset"
+ # We expect a file ~/.config/usergems with one gem per line.
+ # Found no way yet to determine --user-installed gems, let alone
+ # those explicitly installed (vs. dependency-only).
+ if [ -r "${HOME}/.config/usergems" ]; then
+ while read -r gem; do
+ gem update "$gem" --user-install || exit 110
+ done < <(cat "${HOME}/.config/usergems")
+ else
+ printf '%b%b not found, not updating gems.%b\n' "$mywarn" "${HOME}/.config/usergems" "$myrset" >&2
+ fi
+ printf '%bdone.%b\n' "$mydone" "$myrset"
+ else
+ printf '%b/usr/bin/gem not found, not updating Ruby user installations.%b\n' "$mywarn" "$myrset"
+ fi
+ # pipx for Python
+ if [ -x '/usr/bin/pipx' ]; then
+ printf '%bPython (through pipx)%b\n' "$mystrt" "$myrset"
+ pipx list --short || exit 111
+ pipx upgrade-all || exit 112
+ printf '%bdone.%b\n' "$mydone" "$myrset"
+ else
+ printf '%b/usr/bin/pipx not found, not updating Python user installations.%b\n' "$mywarn" "$myrset"
+ fi
+ # Rust / user's crates
+ if [ -x '/usr/bin/cargo' ]; then
+ printf '%bRust (through cargo)%b\n' "$mystrt" "$myrset"
+ # For this to work, a user must have run 'cargo install cargo-update' at least once.
+ cargo install-update --all || exit 113
+ printf '%bdone.%b\n' "$mydone" "$myrset"
+ else
+ printf '%b/usr/bin/cargo not found, not updating Rust user installations.%b\n' "$mywarn" "$myrset"
+ fi
+}
+# Display developer environment base versions.
+function list-env-versions {
+ hline
+ printf 'Versions:\n'
+ (
+ printf 'Bash;%b\n' "$BASH_VERSION"
+ if [ -r '/opt/puppetlabs/puppet/VERSION' ]; then
+ printf 'Puppet;%b\n' "$(cat /opt/puppetlabs/puppet/VERSION)"
+ fi
+ ruver="$(ruby -e 'print(RUBY_VERSION)' 2>/dev/null)"
+ rsver="$(/usr/bin/ruby -e 'print(RUBY_VERSION)' 2>/dev/null)"
+ if [ "$ruver" != "$rsver" ]; then
+ printf 'Ruby;%b (System: %b)\n' "$ruver" "$rsver"
+ else
+ printf 'Ruby;%b\n' "$rsver"
+ fi
+ # This is a mere string but in this case this is exactly what we want
+ puver="$(python -c 'from platform import python_version;print(python_version())' 2>/dev/null)"
+ psver="$(/usr/bin/python -c 'from platform import python_version;print(python_version())' 2>/dev/null)"
+ if [ -n "$puver" ] || [ -n "$psver" ]; then
+ if [ "$puver" != "$psver" ]; then
+ printf 'Python;%b (System: %b)\n' "$puver" "$psver"
+ else
+ printf 'Python;%b\n' "$psver"
+ fi
+ fi
+ huver="$(ghci --version 2>/dev/null | awk '{print $NF}')"
+ hsver="$(/usr/bin/ghci --version 2>/dev/null | awk '{print $NF}')"
+ cuver="$(cabal --version 2>/dev/null | awk '{print $NF}')"
+ csver="$(/usr/bin/cabal --version 2>/dev/null | awk '{print $NF}')"
+ stver="$(stack --version 2>/dev/null | head -n1)"
+ if [ -n "$stver" ]; then
+ shver="$(stack ghc -- --version 2>/dev/null | awk '{print $NF}')"
+ fi
+ printf 'Haskell\n'
+ if [ -n "$huver" ] || [ -n "$hsver" ]; then
+ if [ "$huver" != "$hsver" ]; then
+ printf ';GHCI:\t%b (System: %b)\n' "$huver" "$hsver"
+ else
+ printf ';GHCI:\t%b\n' "$psver"
+ fi
+ fi
+ if [ -n "$cuver" ] || [ -n "$csver" ]; then
+ if [ "$cuver" != "$csver" ]; then
+ printf ';Cabal:\t%b (System: %b)\n' "$cuver" "$csver"
+ else
+ printf ';Cabal:\t%b\n' "$psver"
+ fi
+ fi
+ if [ -n "$stver" ]; then
+ printf ';Stack:\t%b, GHC: %b\n' "$stver" "$shver"
+ fi
+ ) | column -ts';' | sed 's/^/\t/'
+ hline
+}
+# ----- OTHER STUFF ----- #
+for cmmd in batcat bat; do
+ if command -v "$cmmd" > /dev/null; then
+ # shellcheck disable=SC2139
+ alias cat="${cmmd} --tabs 4 --wrap never --paging never --style 'plain,rule'"
+ # shellcheck disable=SC2139
+ alias less="${cmmd} --tabs 4 --wrap never --paging always --style 'plain,rule'"
+ alias plain-cat='/usr/bin/cat'
+ alias plc='/usr/bin/cat'
+ alias plain-less='/usr/bin/less'
+ alias pll='/usr/bin/less'
+ export MANPAGER="sh -c 'col -bx | ${cmmd} -l man -p'"
+ export MANROFFOPT="-c"
+ break
+ fi
+done
+if command -v 'thefuck' > /dev/null; then
+ alias wtf='thefuck $(fc -nl -1)'
+fi
+# Flake8. Nice linter, but...
+# They kneeled to USER STUPIDITY when it comes to configuration. Wut?
+# https://flake8.pycqa.org/en/latest/release-notes/4.0.0.html#backwards-incompatible-changes
+# --> https://github.com/pycqa/flake8/pull/1404
+# Users were confused, so ~/.config/flake8 is not supported anymore. lelkek.
+alias flake8='flake8 --config ${HOME}/.config/flake8'
diff --git a/.bash/exec.bash b/.bash/exec.bash
index a59df2a..aeba7ca 100644
--- a/.bash/exec.bash
+++ b/.bash/exec.bash
@@ -7,7 +7,20 @@ set bell-style visible
# start ssh agent. this script will not try to run a new instance
# (unless we specified -f, which we don't).
-if echo "${SSHAGH[@]}" | grep -F --word-regexp "$(hostname -f)" > /dev/null;then
+SSHRUN=0
+case "$OSNAME" in
+ 'sunos')
+ if echo "${SSHAGH[@]}" | grep -E "^$(cat /etc/nodename)\$" > /dev/null; then
+ SSHRUN=1
+ fi
+ ;;
+ *)
+ if echo "${SSHAGH[@]}" | grep -F --word-regexp "$(hostname -f)" > /dev/null;then
+ SSHRUN=1
+ fi
+ ;;
+esac
+if [ "$SSHRUN" -eq 1 ]; then
# do not launch from SSH session, conflicts with user logging on locally afterwards
if [ -z "$SSH_TTY" ];then
"$HOME/bin/ssh-agent-launcher" -q
@@ -20,4 +33,4 @@ fi
# because on some hosts the login path is fucked, unset in .local
# if it causes irritation:
-cd ~ || cd || exit 151
+cd ~ || cd || return 151
diff --git a/.bash/postexec.bash b/.bash/postexec.bash
index 564356a..0eafd2b 100644
--- a/.bash/postexec.bash
+++ b/.bash/postexec.bash
@@ -1,8 +1,26 @@
declare -x SSH_AUTH_SOCK SSH_AGENT_PID
if [ -n "$SSHENVFILE" ] && [ -r "$SSHENVFILE" ];then
if source "$SSHENVFILE"; then
- if echo "${SSHAGH[@]}"|tr ' ' '\n'|grep -P "^$(hostname -f)$" > /dev/null;then
- add-sshagent-init
- fi
+ case "$OSNAME" in
+ 'sunos')
+ if echo "${SSHAGH[@]}"|tr ' ' '\n'|grep -E "^$(cat /etc/nodename)\$"; then
+ add-sshagent-init
+ fi
+ ;;
+ *)
+ if echo "${SSHAGH[@]}"|tr ' ' '\n'|grep -P "^$(hostname -f)\$" > /dev/null;then
+ add-sshagent-init
+ fi
+ ;;
+ esac
fi
fi
+for gitpsrc in "/usr/share/git/git-prompt.sh" "/usr/local/share/git/git-prompt.sh" \
+ "/usr/share/git-completion/prompt.sh" "/usr/local/share/git-completion/prompt.sh"; do
+ if [ -r "$gitpsrc" ]; then
+ source "$gitpsrc"
+ break
+ fi
+done
+
+list-env-versions
diff --git a/.bash/prompt.bash b/.bash/prompt.bash
index 9908c56..dde6134 100644
--- a/.bash/prompt.bash
+++ b/.bash/prompt.bash
@@ -4,38 +4,72 @@
# ----- PROMPT COLOURS ----- #
fgcolor () {
#echo "\\[\\033[38;5;"$1"m\\]"
- echo "\033[38;5;${1}m"
+ printf '\033[38;5;%bm' "$1"
}
fgtcolor () {
- echo "\033[38;2;$1;$2;$3m"
+ printf '\033[38;2;%b;%b;%bm' "$1" "$2" "$3"
}
bgcolor () {
#echo "\\[\\033[48;5;"$1"m\\]"
- echo "\033[48;5;${1}m"
+ printf '\033[48;5;%bm' "$1"
}
# This is Solaris bash compatible, so we cannot use + here for "at least once) but instead use the
# stupid old asterisk (*). Well, here hetting "no digits" practically won't hurt.
MYUID="$(id|sed 's/.*uid=\([0-9]*\).*/\1/g')";export MYUID
# ...because "empty" will hit the "any" condition in the end :)
+if [ -r '/etc/os-release' ]; then
+ OSMAJVER="$(grep '^VERSION_ID' /etc/os-release 2>/dev/null|awk -F= '{print $NF}'|sed 's/"//g'|awk -F\. '{print $1}')"
+fi
case "$MYUID" in
0)
FGC1="fgcolor 88"
case "$OSNAME" in
- debian) FGC3="fgcolor 38";FGC2="fgtcolor 155 15 64";;
+ debian)
+ # Debian 12 = emerald
+ if [ "$OSMAJVER" -ge 12 ];then
+ FGC3="fgcolor 36";FGC2="fgtcolor 155 15 64"
+ else
+ FGC3="fgcolor 38";FGC2="fgtcolor 155 15 64"
+ fi
+ ;;
arch) FGC2="fgcolor 24";FGC3="fgcolor 240";;
- redhat) FGC1="fgcolor 23";FGC2="fgcolor 88";FGC3="fgcolor 203";;
+ redhat|rhel) FGC1="fgcolor 23";FGC2="fgcolor 88";FGC3="fgcolor 203";;
fedora) FGC1="fgcolor 160";FGC2="fgcolor 88";FGC3="fgcolor 203";;
# with the advent of Rocky, we'll match the time to SUSE's blue and the hostname to
# the colour of Geeko:
#*suse|aix) FGC2="fgcolor 22";FGC3="fgcolor 41";;
*sles*) FGC2="fgcolor 22";FGC3="fgcolor 83";;
- *suse*) FGC2="fgcolor 30";FGC3="fgcolor 83";;
+ *suse*)
+ case "$OSNAME" in
+ *leap) FGC2="fgcolor 214";FGC3="fgcolor 83";;
+ *) FGC2="fgcolor 30";FGC3="fgcolor 83";;
+ esac
+ ;;
aix) FGC2="fgcolor 238";FGC3="fgcolor 83";;
*centos*) FGC2="fgcolor 25";FGC3="fgcolor 208";;
- *solaris) FGC2="fgcolor 31";FGC3="fgcolor 124";;
- ubuntu) FGC2="fgcolor 130";FGC3="fgcolor 215";;
- rasp*) FGC2="fgcolor 253";FGC3="fgcolor 126";;
- rocky) FGC2="fgcolor 22";FGC3="fgcolor 41";;
+ *solaris) FGC2="fgcolor 63";FGC3="fgcolor 124";;
+ ubuntu)
+ if [ "$OSMAJVER" -ge 24 ];then
+ if printf "%b" "$TERM"|grep -E 'xterm|256' > /dev/null;then
+ FGC2="fgcolor 125";FGC3="fgcolor 202"
+ else
+ FGC2="fgcolor 53";FGC3="fgcolor 184"
+ fi
+ elif [ "$OSMAJVER" -ge 22 ];then
+ if printf "%b" "$TERM"|grep -E 'xterm|256' > /dev/null;then
+ FGC2="fgcolor 208";FGC3="fgcolor 89"
+ else
+ FGC2="fgcolor 184";FGC3="fgcolor 53"
+ fi
+ else
+ FGC2="fgcolor 130";FGC3="fgcolor 215"
+ fi
+ ;;
+ rasp*) FGC2="fgcolor 253";FGC3="fgcolor 125";;
+ rocky) FGC2="fgcolor 240";FGC3="fgcolor 41";;
+ alma*) FGC1="fgcolor 28";FGC2="fgcolor 88";FGC3="fgcolor 39";;
+ sunos) FGC2="fgcolor 75";FGC3="fgcolor 130";;
+ nobara) FGC2="fgcolor 133";FGC3="fgcolor 63";;
*) FGC2="fgcolor 240";FGC3="fgcolor 244";;
esac
if [ -n "$TERMUX_APK_RELEASE" ]; then
@@ -47,19 +81,49 @@ case "$MYUID" in
*)
FGC2="fgcolor 253"
case "$OSNAME" in
- debian) FGC1="fgtcolor 155 15 64";FGC3="fgcolor 38";;
+ debian)
+ if [ "$OSMAJVER" -ge 12 ];then
+ FGC1="fgtcolor 155 15 64";FGC3="fgcolor 36"
+ else
+ FGC1="fgtcolor 155 15 64";FGC3="fgcolor 38"
+ fi
+ ;;
arch) FGC1="fgcolor 24";FGC3="fgcolor 239";;
- redhat) FGC1="fgcolor 23";FGC3="fgcolor 88";;
+ redhat|rhel) FGC1="fgcolor 23";FGC3="fgcolor 88";;
fedora) FGC1="fgcolor 88";FGC3="fgcolor 203";;
#*suse|aix) FGC1="fgcolor 22";FGC3="fgcolor 41";;
*sles*) FGC1="fgcolor 22";FGC3="fgcolor 83";;
- *suse*) FGC1="fgcolor 30";FGC3="fgcolor 83";;
+ *suse*)
+ case "$OSNAME" in
+ *leap) FGC1="fgcolor 214";FGC3="fgcolor 83";;
+ *) FGC1="fgcolor 30";FGC3="fgcolor 83";;
+ esac
+ ;;
aix) FGC1="fgcolor 238";FGC3="fgcolor 83";;
*centos*) FGC1="fgcolor 25";FGC3="fgcolor 208";;
- *solaris) FGC1="fgcolor 31";FGC3="fgcolor 124";;
- ubuntu) FGC1="fgcolor 130";FGC3="fgcolor 215";;
- rasp*) FGC1="fgcolor 53";FGC3="fgcolor 126";;
- rocky) FGC1="fgcolor 22";FGC3="fgcolor 41";;
+ *solaris) FGC1="fgcolor 63";FGC3="fgcolor 124";;
+ ubuntu)
+ if [ "$OSMAJVER" -ge 24 ];then
+ if printf "%b" "$TERM"|grep -E 'xterm|256' > /dev/null;then
+ FGC1="fgcolor 125";FGC3="fgcolor 202"
+ else
+ FGC1="fgcolor 53";FGC3="fgcolor 184"
+ fi
+ elif [ "$OSMAJVER" -ge 22 ];then
+ if printf "%b" "$TERM"|grep -E 'xterm|256' > /dev/null;then
+ FGC1="fgcolor 89";FGC3="fgcolor 208"
+ else
+ FGC1="fgcolor 53";FGC3="fgcolor 184"
+ fi
+ else
+ FGC1="fgcolor 130";FGC3="fgcolor 215"
+ fi
+ ;;
+ rasp*) FGC1="fgcolor 52";FGC3="fgcolor 125";;
+ rocky) FGC1="fgcolor 240";FGC3="fgcolor 41";;
+ alma*) FGC1="fgcolor 124";FGC2="fgcolor 229";FGC3="fgcolor 39";;
+ sunos) FGC1="fgcolor 75";FGC3="fgcolor 130";;
+ nobara) FGC1="fgcolor 63";FGC3="fgcolor 133";;
*) FGC1="fgcolor 240";FGC3="fgcolor 244";;
esac
if [ -n "$TERMUX_APK_RELEASE" ]; then
@@ -71,7 +135,17 @@ case "$MYUID" in
esac
# HYPERVISOR LAYER 8 SOFTWARE
if pveversion > /dev/null 2>&1;then
- FGC1="fgcolor 236";FGC3="fgcolor 130"
+ case "$MYUID" in
+ 0) FGC2="fgcolor 130";FGC3="fgcolor 236";;
+ *) FGC1="fgcolor 236";FGC3="fgcolor 130";;
+ esac
+fi
+# Automation frameworks
+if printf '%b' "$(hostname -f)" | grep -i openvox > /dev/null; then
+ case "$MYUID" in
+ 0) FGC2="fgcolor 222";FGC3="fgcolor 215";;
+ *) FGC1="fgcolor 215";FGC3="fgcolor 222";;
+ esac
fi
# make it possible to draw user-defined colours
# shellcheck disable=SC1090,SC1091
@@ -81,7 +155,7 @@ fi
UHSEP="@"
[ -n "$TMUX_PANE" ]&&UHSEP="[T]"
[ -n "$BYOBU_WINDOW_NAME" ]&&UHSEP="[B]"
-[ "$(hostname -s)" == "monitoring" ]&&PHN="$(hostname -f)"||PHN="$(hostname -s)"
+[ "$OSNAME" != 'sunos' ]&&[ "$(hostname -s)" == "monitoring" ]&&PHN="$(hostname -f)"||PHN="$(hostname -s)"
# ----- ASSEMBLE THE PROMPT COMMAND ADDITION ----- #
__prompt_command() {
@@ -93,15 +167,52 @@ __prompt_command() {
else
local EXIT2="$EXIT"
fi
+ PS1='\[\033[2m\033[3m\]\#\[\033[0m\] '
+ if [ "$OSVER" ]; then
+ PS1+='\[\033[48;5;237m\033[\033[38;5;253m\] '
+ PS1+="$OSVER"
+ PS1+=' \[\033[0m\] '
+ fi
+ PS1+='\[\033[1m\]\['
+ PS1+="$($FGC1)"
+ PS1+='\]'
case "$MYUID" in
0)
- PS1="\\# \[$(tput bold)\]\[$($FGC1)\]\\u\[$($FGC2)\]@$PHN \[$($FGC3)\]\\w \[$(tput sgr0)\]"
+ # PS1="\[\\033[2m\\033[3m\]\\#\[\\033[0m\] \[$(tput bold)\]\[$($FGC1)\]\\u\[$($FGC2)\]@$PHN \[$($FGC3)\]\\w \[$(tput sgr0)\]\\n"
+ PS1+='\u\['
+ PS1+="($FGC2)"
+ PS1+='\]'
+ PS1+="@$PHN"
+ PS1+='\['
+ PS1+="$($FGC3)"
+ PS1+='\]\w \[\033[0m\]\n'
;;
*)
- PS1="\\# \[$(tput bold)\]\[$($FGC1)\]\t \[$($FGC2)\]\\u$UHSEP\[$($FGC3)\]$PHN \\w \[$(tput sgr0)\]"
+ # PS1="\[\\033[2m\\033[3m\]\\#\[\\033[0m\] \[$(tput bold)\]\[$($FGC1)\]\t \[$($FGC2)\]\\u$UHSEP\[$($FGC3)\]$PHN \\w \[$(tput sgr0)\]\\n"
+ PS1+='\t \['
+ PS1+="$($FGC2)"
+ PS1+='\]\u'
+ PS1+="$UHSEP"
+ PS1+='\['
+ PS1+="$($FGC3)"
+ PS1+='\]'
+ PS1+="$PHN"
+ PS1+=' \w \[\033[0m\]\n'
;;
esac
- if command -v __git_ps1 >/dev/null 2>&1;then PS1+="$(__git_ps1 "%s ")";fi
+ # git-completion. Sources:
+ # - https://github.com/git/git/tree/master/contrib/completion (main)
+ # - https://github.com/felipec/git-completion (fork)
+ # - Debian: easygit (outdated! you may want to use something like /git-prompt inside this repo)
+ # - Arch: git-completion (AUR, with functionality tests) - search for ...share/git(-completion)?/prompt.sh
+ # - Manual measure: this repository, /git-prompt
+ # Why all this fuss? magicmonty takes control over the whole prompt, __git_ps1 only serves a part
+ # of it. We don't like monoliths, we like modules; the latter is good practice.
+ # also, see postexec --> one-time sourcing of git's prompt.sh
+ if command -v __git_ps1 >/dev/null 2>&1;then
+ GIT_PS1_SHOWCOLORHINTS=1; export GIT_PS1_SHOWCOLORHINTS
+ PS1+="$(__git_ps1 "%s ")"
+ fi
if [ "$EXIT" -eq 0 ];then
PS1+="\[\033[0;32m\]# "
elif [ "$EXIT" -eq 255 ]||[ "$EXIT" -eq 127 ];then
diff --git a/.bash/vars.bash b/.bash/vars.bash
index 773d75d..0bdb5d5 100644
--- a/.bash/vars.bash
+++ b/.bash/vars.bash
@@ -18,18 +18,28 @@ SSHAGH+=( "woschd.example.com" )
export SSHAGH
# ----- SHELL ----- #
-for pa in "/usr/local/bin" "${HOME}/bin";do
- if ! printf "%b" "$PATH"|grep -P "^${pa}:|:${pa}:" >/dev/null;then
- export PATH="${pa}:${PATH}"
+for pa in "/usr/local/bin" "${HOME}/bin" "${HOME}/.local/bin" "${HOME}/go/bin";do
+ if [ -x "$pa" ]; then
+ if ! printf "%b" "$PATH"|grep -E "^${pa}:|:${pa}:" >/dev/null;then
+ export PATH="${pa}:${PATH}"
+ fi
fi
done
# $OSNAME
if [ -r "/etc/os-release" ];then
- OSNAME="$(grep ^ID /etc/os-release|awk -F= '{print $NF}'|head -n1)"
+ OSNAME="$(grep ^ID /etc/os-release|awk -F= '{print $NF}'|head -n1|sed 's/"//g')"
+ if grep '^DEBIAN_VERSION_FULL' /etc/os-release >/dev/null 2>&1; then
+ OSVER="$(grep '^DEBIAN_VERSION_FULL' /etc/os-release|awk -F= '{print $NF}'|head -n1|sed 's/"//g')"
+ elif grep '^BUILD_ID' /etc/os-release >/dev/null 2>&1; then
+ OSVER="$(grep '^BUILD_ID' /etc/os-release|awk -F= '{print $NF}'|head -n1|sed 's/"//g')"
+ else
+ OSVER="$(grep '^VERSION_ID' /etc/os-release|awk -F= '{print $NF}'|head -n1|sed 's/"//g')"
+ fi
+elif [ "$(uname -s)" == 'SunOS' ]; then OSNAME="sunos"
elif [ -r "/etc/redhat-release" ];then
- grep -P "^Red[\ ]?[Hh]at" /etc/redhat-release >/dev/null 2>&1 && OSNAME="redhat"
- grep -P "^[Ff]edora" /etc/redhat-release >/dev/null 2>&1 && OSNAME="fedora"
- grep -P "^[Cc]ent[Oo][Ss]" /etc/redhat-release >/dev/null 2>&1 && OSNAME="centos"
+ grep -E "^Red[\ ]?[Hh]at" /etc/redhat-release >/dev/null 2>&1 && OSNAME="redhat"
+ grep -E "^[Ff]edora" /etc/redhat-release >/dev/null 2>&1 && OSNAME="fedora"
+ grep -E "^[Cc]ent[Oo][Ss]" /etc/redhat-release >/dev/null 2>&1 && OSNAME="centos"
[ -z "$OSNAME" ]&&OSNAME="obsolete"
elif [ -r "/etc/SuSE-release" ];then
OSNAME="oldsuse"
@@ -70,6 +80,29 @@ if command -v less >/dev/null;then
export LESSANSIENDCHARS="m"
export LESSANSIMIDCHARS="0123456789:;[?!\"'#%()*+ "
fi
+
+# ----- RUBY ----- #
+# Include local gems' binary path from those gems matching /usr/bin/ruby:
+if [ -x '/usr/bin/ruby' ]; then
+ rubymajmin="$(/usr/bin/ruby -e 'print(RUBY_VERSION.gsub(%r{\.[0-9]+$}, '\'\''))')"
+ rubypath="${HOME}/.gem/ruby/${rubymajmin}.0/bin"
+ unset rubymajmin
+ if [ -d "$rubypath" ]; then
+ if ! printf '%b' "$PATH" | grep -P "(^|:)${rubypath}(:|$)" > /dev/null; then
+ PATH="${PATH}:$rubypath"
+ fi
+ fi
+fi
+
+# ----- RUST ----- #
+# Include local crates' binary path:
+cargopath="${HOME}/.cargo/bin"
+if [ -d "$cargopath" ]; then
+ if ! printf '%b' "$PATH" | grep -P "(^|:)${cargopath}(:|$)" > /dev/null; then
+ PATH="${PATH}:$cargopath"
+ fi
+fi
+
# ----- MISC ----- #
# nopaste
export NOPASTE_SERVICES='pastebin nopaste'