]> Freerunner's - dotfiles.git/commitdiff
bash: update prompt
authorAndre Ramnitz <tux.rising@gmail.com>
Wed, 17 Jan 2024 23:31:03 +0000 (00:31 +0100)
committerAndre Ramnitz <tux.rising@gmail.com>
Sun, 18 Aug 2024 16:18:53 +0000 (18:18 +0200)
home/.bashrc

index 261d2a0ecb8fc7852087ed77980bc3b7cf037910..dee584fc05705f7a7b824e62e8592aa199676400 100644 (file)
@@ -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