diff options
author | V3n3RiX <venerix@koprulu.sector> | 2024-04-20 12:05:24 +0100 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2024-04-20 12:05:24 +0100 |
commit | da7ae1dd1fccb6b3c0e4763ab983ad96d57bf463 (patch) | |
tree | 0a7a1b7b3ad60c3b21c697e75908b256fc9ed6b1 /app-shells/bash/files/bashrc.d | |
parent | b6cfc0c19effe2d9f7b8ab303cd00636f16da253 (diff) |
gentoo auto-resync : 20:04:2024 - 12:05:23
Diffstat (limited to 'app-shells/bash/files/bashrc.d')
-rw-r--r-- | app-shells/bash/files/bashrc.d/10-gentoo-color.bash | 67 | ||||
-rw-r--r-- | app-shells/bash/files/bashrc.d/10-gentoo-title.bash | 55 |
2 files changed, 122 insertions, 0 deletions
diff --git a/app-shells/bash/files/bashrc.d/10-gentoo-color.bash b/app-shells/bash/files/bashrc.d/10-gentoo-color.bash new file mode 100644 index 000000000000..5a6df5690c08 --- /dev/null +++ b/app-shells/bash/files/bashrc.d/10-gentoo-color.bash @@ -0,0 +1,67 @@ +# /etc/bash/bashrc.d/10-gentoo-color.bash + +if [[ ${NO_COLOR} ]]; then + # Respect the user's wish not to use color. See https://no-color.org/. + gentoo_color=0 +elif [[ ${COLORTERM@a} == *x* && ${COLORTERM} == @(24bit|truecolor) ]]; then + # The COLORTERM environment variable can reasonably be trusted here. + # See https://github.com/termstandard/colors for further information. + gentoo_color=1 +elif unset -v COLORTERM; ! gentoo_color=$(tput colors 2>/dev/null); then + # Either ncurses is not installed or no terminfo database could be + # found. Fall back to a whitelist which covers the majority of terminal + # emulators and virtual console implementations known to support color + # and which remain (somewhat) popular. This will rarely happen, so the + # list need not be exhaustive. + case ${TERM} in + *color* |\ + *direct* |\ + [Ekx]term* |\ + alacritty |\ + aterm |\ + dtterm |\ + foot* |\ + jfbterm |\ + linux |\ + mlterm |\ + rxvt* |\ + screen* |\ + tmux* |\ + wsvt25* ) gentoo_color=1 + esac +elif (( gentoo_color == 16777216 )); then + # Truecolor support is available. Advertise it. + export COLORTERM=truecolor +fi + +if (( gentoo_color <= 0 )); then + # Define a prompt without color. + PS1='\u@\h \w \$ ' +elif (( EUID == 0 )); then + # If root, omit the username and print the hostname in red. + PS1='\[\e[01;31m\]\h\[\e[01;34m\] \w \$\[\e[00m\] ' +else + # Otherwise, print the username and hostname in green. + PS1='\[\e[01;32m\]\u@\h\[\e[01;34m\] \w \$\[\e[00m\] ' +fi + +if (( gentoo_color > 0 )); then + # Colorize the output of grep and several coreutils utilities. + for _ in diff dir egrep fgrep grep ls vdir; do + alias "$_=$_ --color=auto" + done + + # Enable colors for ls(1) and some other utilities that respect the + # LS_COLORS variable. Prefer ~/.dir_colors, per bug #64489. + if hash dircolors 2>/dev/null; then + if [[ -f ~/.dir_colors ]]; then + eval "$(dircolors -b -- ~/.dir_colors)" + elif [[ -f /etc/DIR_COLORS ]]; then + eval "$(dircolors -b /etc/DIR_COLORS)" + else + eval "$(dircolors -b)" + fi + fi +fi + +unset -v gentoo_color diff --git a/app-shells/bash/files/bashrc.d/10-gentoo-title.bash b/app-shells/bash/files/bashrc.d/10-gentoo-title.bash new file mode 100644 index 000000000000..56afcf213045 --- /dev/null +++ b/app-shells/bash/files/bashrc.d/10-gentoo-title.bash @@ -0,0 +1,55 @@ +# /etc/bash/bashrc.d/10-gentoo-title.bash + +# Set window title with the Title Definition String sequence. For screen, the +# sequence defines the window title (%t) and for tmux, the pane_title (#T). +# For tmux to be affected requires that its allow-rename option be enabled. +# https://www.gnu.org/software/screen/manual/html_node/Control-Sequences.html +case ${TERM} in + screen*|tmux*) + genfun_set_pane_title() { + printf '\033k%s\033\\' "${HOSTNAME%%.*}" + } + PROMPT_COMMAND+=('genfun_set_pane_title') + ;; + *) + # If the TTY is that of sshd(8) then proceed no further. Alas, + # there exist many operating environments in which the window + # title would otherwise not be restored upon ssh(1) exiting. + if [[ ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then + return + fi +esac + +# Assigns the basename of the current working directory, having sanitised it +# with @Q parameter expansion. Useful for paths containing newlines and such. +# As a special case, names consisting entirely of graphemes shall not undergo +# the parameter expansion, for reasons of cleanliness. +genfun_sanitise_cwd() { + _cwd=${PWD##*/} + if [[ ! ${_cwd} ]]; then + _cwd=${PWD} + elif [[ ${_cwd} == *[![:graph:]]* ]]; then + _cwd=${_cwd@Q} + fi +} + +# Set window title with the Set Text Parameters sequence. For screen, the +# sequence defines the hardstatus (%h) and for tmux, the window_name (#W). +# For graphical terminal emulators, it is normal for the title bar be affected. +# The only terminals permitted here are those for which there is empirical +# evidence that the sequence is supported and that the UTF-8 character encoding +# is handled correctly. Quite rightly, this precludes many vintage terminals. +# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands +case ${TERM} in + alacritty |\ + foot* |\ + rxvt-unicode* |\ + screen* |\ + tmux* |\ + xterm* ) + genfun_set_win_title() { + genfun_sanitise_cwd + printf '\033]2;%s@%s - %s\007' "${USER}" "${HOSTNAME%%.*}" "${_cwd}" + } + PROMPT_COMMAND+=('genfun_set_win_title') +esac |