From 1cdc70eb70cd83ac49de401ece4d8acc8cd71e5e Mon Sep 17 00:00:00 2001 From: whiteman808 Date: Fri, 13 Feb 2026 04:42:39 +0100 Subject: [PATCH] split bash config and modify bash prompt --- profiles/base/.bash/conf.d/00-base.bash | 2 + .../conf.d/01-gentoo-prompt.bash} | 2 +- .../conf.d/02-gentoo-wintitle.bash} | 0 profiles/base/.bash/conf.d/03-emacs.bash | 5 + profiles/base/.bash/conf.d/04-env.bash | 27 ++++ .../base/.bash/conf.d/05-color-output.bash | 6 + .../.bash/conf.d/06-tool-integrations.bash | 74 +++++++++ profiles/base/.bash/conf.d/07-aliases.bash | 18 +++ profiles/base/.bash/conf.d/08-functions.bash | 4 + .../base/.bash/conf.d/09-keybindings.bash | 1 + profiles/base/.bashrc | 148 +----------------- 11 files changed, 145 insertions(+), 142 deletions(-) create mode 100644 profiles/base/.bash/conf.d/00-base.bash rename profiles/base/{.bashrc.d/10-gentoo-color-r2.bash => .bash/conf.d/01-gentoo-prompt.bash} (96%) rename profiles/base/{.bashrc.d/10-gentoo-title-r3.bash => .bash/conf.d/02-gentoo-wintitle.bash} (100%) create mode 100644 profiles/base/.bash/conf.d/03-emacs.bash create mode 100644 profiles/base/.bash/conf.d/04-env.bash create mode 100644 profiles/base/.bash/conf.d/05-color-output.bash create mode 100644 profiles/base/.bash/conf.d/06-tool-integrations.bash create mode 100644 profiles/base/.bash/conf.d/07-aliases.bash create mode 100644 profiles/base/.bash/conf.d/08-functions.bash create mode 100644 profiles/base/.bash/conf.d/09-keybindings.bash diff --git a/profiles/base/.bash/conf.d/00-base.bash b/profiles/base/.bash/conf.d/00-base.bash new file mode 100644 index 0000000..d2672dc --- /dev/null +++ b/profiles/base/.bash/conf.d/00-base.bash @@ -0,0 +1,2 @@ +# If not running interactively, don't do anything +[[ $- != *i* ]] && return diff --git a/profiles/base/.bashrc.d/10-gentoo-color-r2.bash b/profiles/base/.bash/conf.d/01-gentoo-prompt.bash similarity index 96% rename from profiles/base/.bashrc.d/10-gentoo-color-r2.bash rename to profiles/base/.bash/conf.d/01-gentoo-prompt.bash index 578ed0a..d5a5d55 100644 --- a/profiles/base/.bashrc.d/10-gentoo-color-r2.bash +++ b/profiles/base/.bash/conf.d/01-gentoo-prompt.bash @@ -47,7 +47,7 @@ if (( gentoo_color <= 0 )) || ( ! shopt -u direxpand 2>/dev/null ); then 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\] ' + 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\] ' diff --git a/profiles/base/.bashrc.d/10-gentoo-title-r3.bash b/profiles/base/.bash/conf.d/02-gentoo-wintitle.bash similarity index 100% rename from profiles/base/.bashrc.d/10-gentoo-title-r3.bash rename to profiles/base/.bash/conf.d/02-gentoo-wintitle.bash diff --git a/profiles/base/.bash/conf.d/03-emacs.bash b/profiles/base/.bash/conf.d/03-emacs.bash new file mode 100644 index 0000000..b0bb7cc --- /dev/null +++ b/profiles/base/.bash/conf.d/03-emacs.bash @@ -0,0 +1,5 @@ +# emacs specific stuff + +# shellcheck source=/dev/null +[[ -n "${EAT_SHELL_INTEGRATION_DIR}" ]] && \ + source "${EAT_SHELL_INTEGRATION_DIR}/bash" diff --git a/profiles/base/.bash/conf.d/04-env.bash b/profiles/base/.bash/conf.d/04-env.bash new file mode 100644 index 0000000..f497931 --- /dev/null +++ b/profiles/base/.bash/conf.d/04-env.bash @@ -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 diff --git a/profiles/base/.bash/conf.d/05-color-output.bash b/profiles/base/.bash/conf.d/05-color-output.bash new file mode 100644 index 0000000..24fabeb --- /dev/null +++ b/profiles/base/.bash/conf.d/05-color-output.bash @@ -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\$" diff --git a/profiles/base/.bash/conf.d/06-tool-integrations.bash b/profiles/base/.bash/conf.d/06-tool-integrations.bash new file mode 100644 index 0000000..50bdd17 --- /dev/null +++ b/profiles/base/.bash/conf.d/06-tool-integrations.bash @@ -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="$( { &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 diff --git a/profiles/base/.bash/conf.d/07-aliases.bash b/profiles/base/.bash/conf.d/07-aliases.bash new file mode 100644 index 0000000..c2286df --- /dev/null +++ b/profiles/base/.bash/conf.d/07-aliases.bash @@ -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' diff --git a/profiles/base/.bash/conf.d/08-functions.bash b/profiles/base/.bash/conf.d/08-functions.bash new file mode 100644 index 0000000..f0524c4 --- /dev/null +++ b/profiles/base/.bash/conf.d/08-functions.bash @@ -0,0 +1,4 @@ +take() { + mkdir -p "$1" + cd "$1" || exit 1 +} diff --git a/profiles/base/.bash/conf.d/09-keybindings.bash b/profiles/base/.bash/conf.d/09-keybindings.bash new file mode 100644 index 0000000..a46ccd4 --- /dev/null +++ b/profiles/base/.bash/conf.d/09-keybindings.bash @@ -0,0 +1 @@ +bind '"\C-o":"ranger\n"' diff --git a/profiles/base/.bashrc b/profiles/base/.bashrc index 65911e7..221ed4c 100644 --- a/profiles/base/.bashrc +++ b/profiles/base/.bashrc @@ -2,147 +2,13 @@ # ~/.bashrc # -# If not running interactively, don't do anything -[[ $- != *i* ]] && return +# load bash configuration +readonly CONF_DIR="${HOME}/.bash/conf.d" -# scripts from gentoo - -# shellcheck source=.bashrc.d/10-gentoo-color-r2.bash -source "${HOME}/.bashrc.d/10-gentoo-color-r2.bash" # prompt -# shellcheck source=.bashrc.d/10-gentoo-title-r3.bash -source "${HOME}/.bashrc.d/10-gentoo-title-r3.bash" - -# custom 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" - -# color output -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\$" - -# 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="$( { &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 - -# 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' - -take() { - mkdir -p "$1" - cd "$1" || exit 1 -} - -# 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}" +if [[ -d "${CONF_DIR}" ]]; then + for conf_file in "${CONF_DIR}"/*.bash; do + [[ -r "${conf_file}" ]] || continue + # shellcheck source=/dev/null + source "${conf_file}" 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 -bind '"\C-o":"ranger\n"' - -# 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" - -# 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 - -# 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