From bc3b6c4a7f151d7acca89625efdf78e2cfb18f95 Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Thu, 18 Jan 2024 00:31:03 +0100 Subject: [PATCH] bash: update prompt --- home/.bashrc | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/home/.bashrc b/home/.bashrc index 261d2a0e..dee584fc 100644 --- a/home/.bashrc +++ b/home/.bashrc @@ -48,7 +48,7 @@ case $(tty) in alias lt='EZA_GRID_ROWS=26 eza -w 0 --group --long --grid --group-directories-first --sort=mod -t=mod --time-style=long-iso' echo pts ;; esac - + alias emergelog='sudo cat /var/log/emerge.log | grep "started\|completed\|exiting"' alias k='kks edit' @@ -61,10 +61,89 @@ alias ks='kks-select' # past this point for scp and rcp, and it's important to refrain from # outputting anything in those cases. if [[ $- != *i* ]] ; then - # Shell is non-interactive. Be done now! - return + # Shell is non-interactive. Be done now! + return fi +# No double entries in the shell history. +export HISTCONTROL="$HISTCONTROL erasedups:ignoreboth" + +# Do not overwrite files when redirecting output by default. +set -o noclobber + +# Wrap the following commands for interactive use to avoid accidental file overwrites. +rm() { command rm -i "${@}"; } +cp() { command cp -i "${@}"; } +mv() { command mv -i "${@}"; } + +# get current branch in git repo +function parse_git_branch() { + BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') + if [ ! "${BRANCH}" == "" ] + then + STAT=$(parse_git_dirty) + echo "─[${BRANCH}${STAT}]" + else + echo "" + fi +} + +# get current status of git repo +function parse_git_dirty { + status=$(git status 2>&1 | tee) + if [ "$LANG" == "de_DE.utf8" ]; then + dirty=$(echo -n "${status}" 2> /dev/null | grep "geändert:" &> /dev/null; echo "$?") + untracked=$(echo -n "${status}" 2> /dev/null | grep "Unversionierte Dateien:" &> /dev/null; echo "$?") + ahead=$(echo -n "${status}" 2> /dev/null | grep "Ihr Branch ist" &> /dev/null; echo "$?") + newfile=$(echo -n "${status}" 2> /dev/null | grep "neue Datei:" &> /dev/null; echo "$?") + renamed=$(echo -n "${status}" 2> /dev/null | grep "umbenannt:" &> /dev/null; echo "$?") + deleted=$(echo -n "${status}" 2> /dev/null | grep "gelöscht:" &> /dev/null; echo "$?") + else + dirty=$(echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?") + untracked=$(echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?") + ahead=$(echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?") + newfile=$(echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?") + renamed=$(echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?") + deleted=$(echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?") + fi + bits='' + if [ "${renamed}" == "0" ]; then + bits=">${bits}" + fi + if [ "${ahead}" == "0" ]; then + bits="*${bits}" + fi + if [ "${newfile}" == "0" ]; then + bits="+${bits}" + fi + if [ "${untracked}" == "0" ]; then + bits="?${bits}" + fi + if [ "${deleted}" == "0" ]; then + bits="x${bits}" + fi + if [ "${dirty}" == "0" ]; then + bits="!${bits}" + fi + if [ ! "${bits}" == "" ]; then + echo " ${bits}" + else + echo "" + fi +} + +export PS1="┬─[\[\e[33m\]\u\[\e[m\]@\[\e[34m\]\h\[\e[m\]:\w]─[\[\e[37m\]\t\[\e[m\]]\`parse_git_branch\`\n╰─\[\e[31m\]\\$\[\e[m\] " + +# enable moving between directories without cd +shopt -s autocd +# enable spelling correction +shopt -s dirspell +# enable case-insensitivity +shopt -s nocaseglob +# expand filename patterns without match to a null string +shopt -s nullglob + # Put your fun stuff here. # #[ -x /bin/fish ] && SHELL=/bin/fish exec fish +fastfetch -- 2.51.2