split bash config and modify bash prompt

This commit is contained in:
2026-02-13 04:42:39 +01:00
parent 2bd6b181f4
commit 1cdc70eb70
11 changed files with 145 additions and 142 deletions

View File

@@ -0,0 +1,2 @@
# If not running interactively, don't do anything
[[ $- != *i* ]] && return

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
# copied from https://gitweb.gentoo.org/repo/gentoo.git/tree/app-shells/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
else
# Check TERM against a whitelist covering a majority of popular
# terminal emulators and virtual console implementations known to
# support color. If no matching entry is found, try to use tput(1) to
# determine whether color is supported.
case ${TERM} in
*color* |\
*direct* |\
*ghostty |\
[Ekx]term* |\
alacritty |\
aterm |\
contour |\
dtterm |\
foot* |\
jfbterm |\
linux |\
mlterm |\
rxvt* |\
screen* |\
tmux* |\
wsvt25* ) gentoo_color=1 ;;
* ) gentoo_color=$(tput colors 2>/dev/null)
esac
fi
# For direxpand to be missing indicates that bash is lacking readline support.
prompt_exit_code() {
local -r exit_code=$?
if [[ ${exit_code} -ne 0 ]]; then
printf "%s " "${exit_code}"
fi
}
if (( gentoo_color <= 0 )) || ( ! shopt -u direxpand 2>/dev/null ); 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\] \[\e[01;31m\]$(prompt_exit_code)\[\e[01;34m\]\w \$\[\e[00m\] '
else
# Otherwise, print the username and hostname in green.
PS1='\[\e[01;32m\]\u@\h\[\e[01;34m\] \[\e[01;31m\]$(prompt_exit_code)\[\e[01;34m\]\w \$\[\e[00m\] '
fi
if (( gentoo_color > 0 )); then
# Colorize the output of diff(1), grep(1) and a few coreutils utilities.
# However, do so only where no alias/function by the given name exists.
for _ in diff dir grep ls vdir; do
if [[ $(type -t "$_") == file ]]; then
alias "$_=$_ --color=auto"
fi
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 "$(COLORTERM=1 dircolors -b -- ~/.dir_colors)"
elif [[ -f /etc/DIR_COLORS ]]; then
eval "$(COLORTERM=1 dircolors -b /etc/DIR_COLORS)"
else
eval "$(COLORTERM=1 dircolors -b)"
fi
fi
fi
unset -v gentoo_color

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
# copied from https://gitweb.gentoo.org/repo/gentoo.git/tree/app-shells/bash
# For information regarding the control sequences used, please refer to
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html.
genfun_set_win_title() {
# Advertise the fact that the presently running interactive shell will
# update the title. Doing so allows for its subprocesses to determine
# whether it is safe to set the title of their own accord. Note that 0
# refers to the value of Ps within the OSC Ps ; Pt BEL sequence.
export SHELL_SETS_TITLE=0
# Sets the window title with the Set Text Parameters control sequence.
# For screen, the sequence defines the hardstatus (%h) and for tmux, the
# pane_title (#T). For graphical terminal emulators, it is normal for
# the title bar to be affected.
genfun_set_win_title() {
local prompt
if [[ ${PROMPT_DIRTRIM} ]]; then
# Respect the value of PROMPT_DIRTRIM. If set as 0, the
# current working directory shall be shown in full.
prompt='\u@\h \w'
else
# Show the basename of the current working directory.
prompt='\u@\h \W'
fi
printf '\033]0;%s\007' "${prompt@P}"
}
genfun_set_win_title
}
unset -v SHELL_SETS_TITLE
# Determine whether the terminal can handle the Set Text Parameters sequence.
# 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.
case ${TERM} in
alacritty*|contour|foot*|tmux*|xterm-ghostty)
# The terminal emulator also supports XTWINOPS. If the PTY was
# created by sshd(8) then push the current window title to the
# stack and arrange for it to be popped upon exiting. Xterm also
# supports this but there are far too many terminal emulators
# that falsely identify as being xterm-compatible.
if [[ ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then
trap 'printf "\033[23;0t"' EXIT
printf '\033[22;0t'
fi
;;
rxvt-unicode*|st-256color|xterm*)
# If the PTY was created by sshd(8) then proceed no further.
# Alas, there exist many operating environments in which the
# title would otherwise not be restored upon ssh(1) exiting.
# Those wanting for the title to be set regardless may adjust
# ~/.bashrc or create a bashrc.d drop-in to set PROMPT_COMMAND.
# For example, PROMPT_COMMAND=(genfun_set_win_title).
if [[ ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then
return
fi
;;
screen*)
# If the PTY was created by sshd(8) and screen(1) was launched
# prior to the SSH session beginning, as opposed to afterwards,
# proceed no further. It is another case in which there would be
# no guarantee of the title being restored upon ssh(1) exiting.
if [[ ! ${WINDOW} && ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then
return
fi
;;
*)
return
esac
# Arrange for the title to be updated each time the primary prompt is displayed.
PROMPT_COMMAND+=('genfun_set_win_title')

View File

@@ -0,0 +1,5 @@
# emacs specific stuff
# shellcheck source=/dev/null
[[ -n "${EAT_SHELL_INTEGRATION_DIR}" ]] && \
source "${EAT_SHELL_INTEGRATION_DIR}/bash"

View File

@@ -0,0 +1,27 @@
# Set environment variables
if command -v nvim &> /dev/null; then
export EDITOR="nvim"
else
export EDITOR="vim"
fi
# export EDITOR="ec"
export VISUAL="${EDITOR}"
export SUDO_EDITOR="${EDITOR}"
export VIRSH_DEFAULT_CONNECT_URI="qemu:///system"
export BROWSER="chromium"
export PAGER="less -R -F"
export BAT_PAGER="${PAGER}"
export MANPAGER="less -R --use-color -Dd+r -Du+b"
[[ -f "/usr/share/cowsay/cows" ]] && export COWPATH="/usr/share/cowsay/cows"
export CHROOT="${HOME}/arch_chroot"
export AUR_REPO="whiteman808"
export AURDEST="${HOME}/.cache/paru/clone"
export AUR_PAGER="ranger"
export GPGKEY="4A45503BBE575E3D4DAF28E27264AFFDC98D52BB"
# gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)"
export SSH_AUTH_SOCK
fi

View File

@@ -0,0 +1,6 @@
alias diff="diff --color=auto"
alias grep="grep --color=auto"
alias ip="ip -color=auto"
alias ls="ls --color=auto"
export MANROFFOPT="-P -c"
export LESS="-R --use-color -Dd+r\$Du+b\$"

View File

@@ -0,0 +1,74 @@
# better ls
if type "eza" > /dev/null; then
alias ll='eza -bghHlS'
else
alias ll='exa -bghHlS'
fi
# bat (debian)
if type "batcat" >/dev/null 2>&1; then
alias bat='batcat'
fi
# HSTR configuration - add this to ~/.bashrc
alias hh=hstr # hh to be alias for hstr
export HSTR_CONFIG=hicolor # get more colors
shopt -s histappend # append new history items to .bash_history
export HISTCONTROL=ignorespace # leading space hides commands from history
export HISTFILESIZE=10000 # increase history file size (default is 500)
export HISTSIZE=${HISTFILESIZE} # increase history size (default is 500)
# ensure synchronization between bash memory and history file
export PROMPT_COMMAND=( "history -a; history -n;" "${PROMPT_COMMAND[@]}" )
function hstrnotiocsti {
{ READLINE_LINE="$( { </dev/tty hstr -- "${READLINE_LINE}"; } 2>&1 1>&3 3>&- )"; } 3>&1;
READLINE_POINT=${#READLINE_LINE}
}
# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
if [[ $- =~ .*i.* ]]; then bind -x '"\C-r": "hstrnotiocsti"'; fi
export HSTR_TIOCSTI=n
# lf
lfwrapper() {
command lf "$@"
# cleanup
awk '$1 == "archivemount" { print $2 }' /etc/mtab | while read -r mntdir; do
sanitized_input="$(printf "${mntdir}")" # /etc/mtab uses octal representation of spaces (possible other symbols too), printf would convert octal representation, so that it can be used in the umount & rmdir commands.
umount "${sanitized_input}"
rmdir "${sanitized_input}"
done
}
lfcd() {
dir="$(lfwrapper -print-last-dir "$@")"
while ! cd "${dir}" 2>/dev/null; do
dir="$(dirname -- "${dir}")"
done
}
alias lf=lfcd
# ranger
ranger_cd() {
temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")"
ranger --choosedir="${temp_file}" -- "${@:-${PWD}}"
if chosen_dir="$(cat -- "${temp_file}")" && [ -n "${chosen_dir}" ] && [ "${chosen_dir}" != "${PWD}" ]; then
cd -- "${chosen_dir}" || exit 1
fi
rm -f -- "${temp_file}"
}
alias ranger=ranger_cd
# mc
# shellcheck source=/dev/null
[[ -f "/usr/libexec/mc/mc.sh" ]] && source "/usr/libexec/mc/mc.sh"
[[ -f "/usr/lib/mc/mc.sh" ]] && source "/usr/lib/mc/mc.sh"
# inside tmux, we don't know if Sway got restarted
if [[ -v TMUX ]]; then
swaymsg() {
SWAYSOCK=${XDG_RUNTIME_DIR}/sway-ipc.${UID}.$(pgrep -x sway).sock
export SWAYSOCK
command swaymsg "$@"
}
fi

View File

@@ -0,0 +1,18 @@
# useful commands
alias ncmpcpp='ncmpcpp -b ~/.config/ncmpcpp/bindings'
alias tb='nc termbin.com 9999'
alias mux='tmuxinator'
alias tm='tmuxinator start misc'
alias tq='tmuxinator start quake'
alias sudo='sudo '
alias rsync_copy='rsync -aAXUHvh --partial-dir=.rsync-partial --progress'
alias rsync_copy_ssh='rsync_copy -e ssh'
alias rsync_backup='rsync_copy --numeric-ids --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}'
alias rsync_backup_ssh='rsync_backup -e ssh'
alias rsync_restore='rsync_copy --numeric-ids --delete --exclude="lost+found"'
alias rsync_restore_ssh='rsync_restore -e ssh'
alias glog='git log --oneline'
alias emerge_world='emerge --ask --verbose --deep --newuse --update @world'
alias sync_repo='rsync_copy_ssh --delete ~/arch_paczuchy/* vps.paraboletancza.org:/srv/http/arch.paraboletancza.org'
alias aur_sync='aur sync --sign --chroot'
alias aur_build='aur build --sign --chroot'

View File

@@ -0,0 +1,4 @@
take() {
mkdir -p "$1"
cd "$1" || exit 1
}

View File

@@ -0,0 +1 @@
bind '"\C-o":"ranger\n"'