git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/.bash
diff options
context:
space:
mode:
Diffstat (limited to '.bash')
-rw-r--r--.bash/aliases.bash154
-rw-r--r--.bash/exec.bash10
-rw-r--r--.bash/prompt.bash129
-rw-r--r--.bash/vars.bash73
4 files changed, 366 insertions, 0 deletions
diff --git a/.bash/aliases.bash b/.bash/aliases.bash
new file mode 100644
index 0000000..de3d616
--- /dev/null
+++ b/.bash/aliases.bash
@@ -0,0 +1,154 @@
+#!/usr/bin/env bash
+# vim:syntax=sh
+
+# This file actually has aliases _and_ functions.
+
+if [ "$TERM" != "dumb" ];then
+ eval "$(dircolors -b)"
+ alias ls="ls --color=auto"
+ alias grep="grep --color=auto"
+ alias egrep="egrep --color=auto"
+fi
+alias cls=' echo -ne "\033c"'
+alias pip-update="sudo pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip install -U"
+alias matrix='cmatrix -sbu6 -C cyan'
+command -v colordiff >/dev/null 2>&1&&alias diff="colordiff"
+command -v colormake >/dev/null 2>&1&&alias make="colormake"
+alias perllint="perl -Mstrict -Mdiagnostics -cw"
+alias scredit='gimp "${SCRSHDIR}/$(ls -rt1 $SCRSHDIR/|tail -n1)"'
+alias scrview='pqiv -i "${SCRSHDIR}/$(ls -rt1 $SCRSHDIR/|tail -n1)"'
+alias fuck='sudo $(history -p \!\!)'
+alias x509-out='openssl x509 -text -certopt no_version,no_pubkey,no_sigdump,no_aux,no_header -noout -in'
+alias psgrep='ps -fp "$(pgrep -d, -x ssh-agent)"'
+# ----- CHOO CHOO ----- #
+if command -v sl >/dev/null;then
+ alias sl='sl -e'
+ alias LS='LS -e'
+fi
+# ----- LIBVIRT ----- #
+alias vl="virsh list --all --title"
+alias vnl="virsh net-list --all"
+# shellcheck disable=SC2154
+alias vifl='for i in $(virsh list --name --all);do echo $i;virsh domiflist $i;done'
+# shellcheck disable=SC2154
+alias vifl='for i in $(virsh list --name --all);do echo $i;virsh domiflist $i;done'
+alias v='vnl;vl;vifl'
+# ----- BYOBU/TMUX ----- #
+alias ba='byobu has -t "$BSNAME" >/dev/null 2>&1 &&byobu list-sessions&&sleep 1&&byobu attach-session -t "$BSNAME"||printf "No session called %b!\\n" "$BSNAME"'
+alias bl="byobu list-sessions"
+alias bo="byobu list-sessions \; list-windows"
+alias tc='tmux save-buffer -|xclip -i&&echo "tmux buffer copied"'
+# ----- NETWORK ----- #
+alias openports='ss --all --numeric --processes --ipv4 --ipv6'
+alias myip4='curl -k "https://diagnostic.opendns.com/myip"'
+alias myip6='curl -6 "https://icanhazip.com"'
+# ----- MEDIA ----- #
+alias dvdb='dvdbackup -i /dev/dvd1 -M'
+alias dvdburn='brasero'
+alias dosbox='export SDL_VIDEO_X11_DGAMOUSE=0;dosbox;unset SDL_VIDEO_X11_DGAMOUSE'
+alias mdf2iso="iat"
+alias bin2iso="iat"
+alias replaygain='mp3gain -s i'
+alias jackdrc="/usr/bin/jackd -T -u -dalsa -r48000 -p1024 -n2 -D -Chw:CODEC &>/dev/null &"
+alias html2png="cutycapt"
+# ----- WM ----- #
+alias startgnome="sxs gnome"
+alias startkde="sxs kde"
+alias starte16="sxs e16"
+alias startxmonad="sxs xmonad"
+# ----- SSH ----- #
+alias saa="source ~/.ssh/sshenv;ssh-add >/dev/null 2>&1;ssh-add -l"
+alias sshr='ssh -o StrictHostKeyChecking=no'
+alias sshk='ssh -o PasswordAuthentication=yes -o PreferredAuthentications=keyboard-interactive,password -o PubkeyAuthentication=no'
+# ----- FS ----- #
+xstat() {
+ for target in "${@}";do
+ inode=$(ls -di "${target}"|cut -d ' ' -f 1)
+ fs=$(df "${target}"|tail -n 1|awk '{print $1}')
+ crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null | grep -oP 'crtime.*--\s*\K.*')
+ printf "%s\t%s\n" "${crtime}" "${target}"
+ done
+}
+# ----- GRAFANA ----- #
+if command -v grafana-cli >/dev/null;then
+ alias gfpi='sudo grafana-cli plugins install'
+ alias gfpl='sudo grafana-cli plugins list'
+ alias gfplr='sudo grafana-cli plugins list-remote'
+ alias gfrs="sudo systemctl restart grafana-server.service;systemctl is-active grafana-server.service;sudo ss -pantl|grep :3000"
+fi
+alias gfs="systemctl is-active grafana-server.service&&sudo ss -pantl|grep :3000"
+# ----- ZE PASSWORDS ----- #
+if [ -r "/etc/os-release" ];then
+ osid="$(grep ^ID /etc/os-release|awk -F= '{print $2}'|tail -n1)"
+ case "$osid" in
+ fedora|centos|rhel*)
+ alias mkpsk="makepasswd -c '1234567890abcdef' -l 64"
+ alias mkpw="makepasswd -c 'qwertzuiopasdfghjkyxcvbnmQWERTZUPASDFGHJKLYXCVBNM23456789#!_' -l 24"
+ ;;
+ *suse*)
+ alias mkpsk="mimimi :("
+ alias mkpw="mimimi :("
+ ;;
+ *)
+ alias mkpsk="makepasswd --string='1234567890abcdef' --chars='64'"
+ alias mkpw="makepasswd --string='qwertzuiopasdfghjkyxcvbnmQWERTZUPASDFGHJKLYXCVBNM23456789#!_' --chars='24'"
+ ;;
+ esac
+ unset osid
+fi
+# ----- GPG -----#
+alias gpg='gpg --expert'
+gpg-expmaster() {
+ FRETVAL=0
+ HELPTXT="Exports all secrets to master file\nUSAGE:\t${FUNCNAME[0]} outputfile key-id"
+ [ -z "$1" ]&&echo -e "$HELPTXT"&&FRETVAL=$((FRETVAL+1))||\
+ [ -z "$2" ]&&echo -e "$HELPTXT"&&FRETVAL=$((FRETVAL+1))||\
+ gpg2 --armour --output "$1" --export-secret-key "$2"||FRETVAL=$((FRETVAL+1))
+ return "$FRETVAL"
+}
+gpg-exppaper() {
+ FRETVAL=0
+ HELPTXT="Exports all secrets to paper\nUSAGE:\t${FUNCNAME[0]} key-id"
+ [ -z "$1" ]&&echo -e "$HELPTXT"&&FRETVAL=$((FRETVAL+1))||\
+ gpg2 --export-secret-key "$1"|paperkey|lpr||FRETVAL=$((FRETVAL+1))
+ return "$FRETVAL"
+}
+gpg-removekey() {
+ FRETVAL=0
+ HELPTXT="Removes a key ID from keystore\nUSAGE:\t${FUNCNAME[0]} key-id"
+ [ -z "$1" ]&&echo -e "$HELPTXT"&&FRETVAL=$((FRETVAL+1))||\
+ gpg-connect-agent "DELETE_KEY $1" /bye||FRETVAL=$((FRETVAL+1))
+ return "$FRETVAL"
+}
+# ----- CERTIFICATES ----- #
+alias certmgr='certutil -d sql:${HOME:?}/.pki/nssdb'
+alias certlist="certmgr -L"
+alias certshow="certmgr -L -n"
+# ----- APPLICATION CONTROL ----- #
+alias browser-set='xdg-settings set default-web-browser'
+alias browser-get='xdg-settings get default-web-browser'
+# ----- CONTAINERS ----- #
+if command -v podman >/dev/null;then
+ alias pcl="podman container list"
+ alias pclj="podman container list --format json"
+ alias pnl="podman network ls"
+ alias ppl="podman pod list"
+ alias pplj="podman pod list --format json"
+ alias pvl="podman volume list"
+ alias pvlj="podman volume list --format json"
+ alias pci="podman container inspect"
+ alias pni="podman network inspect"
+ alias ppi="podman pod inspect"
+ alias pvi="podman volume inspect"
+ alias pcr="podman container rm"
+ alias pnr="podman network rm"
+ alias ppr="podman pod rm"
+ alias pvr="podman volume rm"
+ alias pcs="podman container start"
+ alias pnc="podman network connect"
+ alias pps="podman pod start"
+ # d=destroy, kvm's term for "stop vigorously" :-)
+ alias pcd="podman container stop"
+ alias pnd="podman network disconnect"
+ alias ppd="podman pod stop"
+fi
diff --git a/.bash/exec.bash b/.bash/exec.bash
new file mode 100644
index 0000000..cabf2d8
--- /dev/null
+++ b/.bash/exec.bash
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+# vim:syntax=sh
+# check the window size after each command and, if necessary,
+# update the values of LINES and COLUMNS.
+shopt -s checkwinsize
+set bell-style visible
+
+# because on some hosts the login path is fucked, unset in .local
+# if it causes irritation:
+cd ~ || cd || exit 151
diff --git a/.bash/prompt.bash b/.bash/prompt.bash
new file mode 100644
index 0000000..a78f2ed
--- /dev/null
+++ b/.bash/prompt.bash
@@ -0,0 +1,129 @@
+#!/usr/bin/env bash
+# vim:syntax=sh:ts=4
+
+# ----- PROMPT COLOURS ----- #
+fgcolor () {
+ #echo "\\[\\033[38;5;"$1"m\\]"
+ echo "\033[38;5;${1}m"
+}
+bgcolor () {
+ #echo "\\[\\033[48;5;"$1"m\\]"
+ echo "\033[48;5;${1}m"
+}
+# This is Solaris bash compatible, so we cannot use + here for "at least once) but instead use the
+# stupid old asterisk (*). Well, here hetting "no digits" practically won't hurt.
+MYUID="$(id|sed 's/.*uid=\([0-9]*\).*/\1/g')";export MYUID
+# ...because "empty" will hit the "any" condition in the end :)
+case "$MYUID" in
+ 0)
+ case "$OSNAME" in
+ debian) FGC1="fgcolor 88";FGC2="fgcolor 25";FGC3="fgcolor 38";;
+ arch) FGC1="fgcolor 88";FGC2="fgcolor 24";FGC3="fgcolor 240";;
+ redhat|fedora) FGC1="fgcolor 160";FGC2="fgcolor 88";FGC3="fgcolor 203";;
+ # with the advent of Rocky, we'll match the time to SUSE's blue and the hostname to
+ # the colour of Geeko:
+ #*suse|aix) FGC1="fgcolor 88";FGC2="fgcolor 22";FGC3="fgcolor 41";;
+ *sles*) FGC1="fgcolor 88";FGC2="fgcolor 22";FGC3="fgcolor 83";;
+ *suse|aix) FGC1="fgcolor 88";FGC2="fgcolor 30";FGC3="fgcolor 83";;
+ *centos*) FGC1="fgcolor 88";FGC2="fgcolor 25";FGC3="fgcolor 208";;
+ *solaris) FGC1="fgcolor 88";FGC2="fgcolor 31";FGC3="fgcolor 124";;
+ ubuntu) FGC1="fgcolor 88";FGC2="fgcolor 130";FGC3="fgcolor 215";;
+ rasp*) FGC1="fgcolor 88";FGC2="fgcolor 253";FGC3="fgcolor 126";;
+ rocky) FGC1="fgcolor 88";FGC2="fgcolor 22";FGC3="fgcolor 41";;
+ *) FGC1="fgcolor 88";FGC2="fgcolor 240";FGC3="fgcolor 244";;
+ esac
+ ;;
+ *)
+ case "$OSNAME" in
+ debian) FGC1="fgcolor 25";FGC2="fgcolor 253";FGC3="fgcolor 38";;
+ arch) FGC1="fgcolor 24";FGC2="fgcolor 253";FGC3="fgcolor 239";;
+ redhat|fedora) FGC1="fgcolor 88";FGC2="fgcolor 253";FGC3="fgcolor 203";;
+ #*suse|aix) FGC1="fgcolor 22";FGC2="fgcolor 253";FGC3="fgcolor 41";;
+ *sles*) FGC1="fgcolor 22";FGC2="fgcolor 253";FGC3="fgcolor 83";;
+ *suse|aix) FGC1="fgcolor 30";FGC2="fgcolor 253";FGC3="fgcolor 83";;
+ *centos*) FGC1="fgcolor 25";FGC2="fgcolor 253";FGC3="fgcolor 208";;
+ *solaris) FGC1="fgcolor 31";FGC2="fgcolor 253";FGC3="fgcolor 124";;
+ ubuntu) FGC1="fgcolor 130";FGC2="fgcolor 253";FGC3="fgcolor 215";;
+ rasp*) FGC1="fgcolor 53";FGC2="fgcolor 253";FGC3="fgcolor 126";;
+ rocky) FGC1="fgcolor 22";FGC2="fgcolor 253";FGC3="fgcolor 41";;
+ *) FGC1="fgcolor 240";FGC2="fgcolor 253";FGC3="fgcolor 244";;
+ esac
+ ;;
+esac
+# make it possible to draw user-defined colours
+# shellcheck disable=SC1090
+[ -r "${BBD}/prompt.bash.local" ] && source "${BBD}/prompt.bash.local"
+
+# ----- USER SEP. AND HOSTNAME ----- #
+UHSEP="@"
+[ -n "$TMUX_PANE" ]&&UHSEP="[T]"
+[ -n "$BYOBU_WINDOW_NAME" ]&&UHSEP="[B]"
+[ "$(hostname -s)" == "monitoring" ]&&PHN="$(hostname -f)"||PHN="$(hostname -s)"
+
+# ----- ASSEMBLE THE PROMPT COMMAND ADDITION ----- #
+__prompt_command() {
+ local EXIT="$?"
+ if [ "$EXIT" -lt 10 ];then
+ local EXIT2="00$EXIT"
+ elif [ "$EXIT" -lt 100 ];then
+ local EXIT2="0$EXIT"
+ else
+ local EXIT2="$EXIT"
+ fi
+ case "$MYUID" in
+ 0)
+ PS1="\\# \[$(tput bold)\]\[$($FGC1)\]\\u\[$($FGC2)\]@$PHN \[$($FGC3)\]\\w \[$(tput sgr0)\]"
+ ;;
+ *)
+ PS1="\\# \[$(tput bold)\]\[$($FGC1)\]\t \[$($FGC2)\]\\u$UHSEP\[$($FGC3)\]$PHN \\w \[$(tput sgr0)\]"
+ ;;
+ esac
+ if command -v __git_ps1 >/dev/null 2>&1;then PS1+="$(__git_ps1 "%s ")";fi
+ if [ "$EXIT" -eq 0 ];then
+ PS1+="\[\033[0;32m\]# "
+ elif [ "$EXIT" -eq 255 ]||[ "$EXIT" -eq 127 ];then
+ PS1+="\[\033[0;33m\]$EXIT2 # "
+ elif [ "$EXIT" -eq 130 ];then
+ PS1+="\[\033[0;35m\]$EXIT2 # "
+ else
+ PS1+="\[\033[0;31m\]$EXIT2 # "
+ fi
+ PS1+="\[\033[0m\]"
+}
+
+# ----- ADD __prompt_command() TO $PROMPT_COMMAND ----- #
+if ! printf "%b" "$PROMPT_COMMAND" | grep '__prompt_command' >/dev/null;then
+ case "$TERM" in
+ # adding in "screen" because tmux
+ xterm|xterm-color|xterm-256color|rxvt*|screen-256color|screen)
+ if [ -n "$PROMPT_COMMAND" ];then
+ export PROMPT_COMMAND="__prompt_command;${PROMPT_COMMAND}"
+ else
+ export PROMPT_COMMAND="__prompt_command"
+ fi
+ ;;
+ *)
+ if [ -n "$PROMPT_COMMAND" ];then
+ export PROMPT_COMMAND="__prompt_command;${PROMPT_COMMAND}"
+ else
+ export PROMPT_COMMAND="__prompt_command"
+ fi
+ ;;
+ esac
+fi
+# ----- ADD SSH ENV FILE TO PROMPT_COMMAND ----- #
+if [ -r "$SSHENVFILE" ];then
+ if ! printf "%b" "$PROMPT_COMMAND" | grep "source $SSHENVFILE" >/dev/null;then
+ # we don't need to check whether PROMPT_COMMAND is set as after the paragraph
+ # above, something will be definitely set.
+ PROMPT_COMMAND="${PROMPT_COMMAND};source $SSHENVFILE"
+ fi
+fi
+# ----- HISTORY SUBMISSION IN $PROMPT_COMMAND ----- #
+if ! printf "%b" "$PROMPT_COMMAND"|grep 'history -a' >/dev/null;then
+ if [ -n "$PROMPT_COMMAND" ];then
+ export PROMPT_COMMAND="$PROMPT_COMMAND;history -a;history -c;history -r"
+ else
+ export PROMPT_COMMAND="history -a;history -c;history -r"
+ fi
+fi
diff --git a/.bash/vars.bash b/.bash/vars.bash
new file mode 100644
index 0000000..dddc831
--- /dev/null
+++ b/.bash/vars.bash
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+# vim:syntax=sh
+
+# default Byobu session name
+export BSNAME="CHANGEME"
+# default screenshot target. Feel free to override in .local.
+export SCRSHDIR="${HOME}/Pictures"
+# variable for SSH environment file
+export SSHENVFILE="${HOME}/.ssh/sshenv"
+
+# ----- SHELL ----- #
+for pa in "/usr/local/bin" "${HOME}/bin";do
+ if ! printf "%b" "$PATH"|grep -P "^${pa}:|:${pa}:" >/dev/null;then
+ export PATH="${pa}:${PATH}"
+ fi
+done
+# $OSNAME
+if [ -r "/etc/os-release" ];then
+ OSNAME="$(grep ^ID /etc/os-release|awk -F= '{print $NF}'|head -n1)"
+elif [ -r "/etc/redhat-release" ];then
+ grep -P "^Red[\ ]?[Hh]at" /etc/redhat-release >/dev/null 2>&1 && OSNAME="redhat"
+ grep -P "^[Ff]edora" /etc/redhat-release >/dev/null 2>&1 && OSNAME="fedora"
+ grep -P "^[Cc]ent[Oo][Ss]" /etc/redhat-release >/dev/null 2>&1 && OSNAME="centos"
+ [ -z "$OSNAME" ]&&OSNAME="obsolete"
+elif [ -r "/etc/SuSE-release" ];then
+ OSNAME="oldsuse"
+elif [ -r "/etc/release" ];then
+ head -n1 /etc/release 2> /dev/null|grep -i solaris > /dev/null && OSNAME="solaris"
+ [ -z "$OSNAME" ]&&OSNAME="obsolete"
+else
+ [ "$(oslevel -s >/dev/null 2>&1|wc -l)" -gt 0 ]&&OSNAME="aix"
+ [ -z "$OSNAME" ]&&OSNAME="obsolete"
+fi
+declare -x GPG_TTY
+GPG_TTY="$(tty)"
+export e='2.718281828459045'
+if command -v bc >/dev/null;then
+ declare -x pi
+ pi="$(echo "scale=64; 4*a(1)" | bc -l)"
+fi
+
+# ----- GIT ----- #
+# git on the command line
+export GIT_PS1_SHOWDIRTYSTATE=1
+export GIT_PS1_SHOWSTASHSTATE=1
+export GIT_PS1_SHOWUNTRACKEDFILES=1
+
+# ----- LESS FOR EVERYTHING ----- #
+if command -v less >/dev/null;then
+ # coloured mapages
+ export LESS_TERMCAP_mb=$'\E[01;31m'
+ export LESS_TERMCAP_md=$'\E[01;31m'
+ export LESS_TERMCAP_me=$'\E[0m'
+ export LESS_TERMCAP_se=$'\E[0m'
+ export LESS_TERMCAP_so=$'\E[01;44;33m'
+ export LESS_TERMCAP_ue=$'\E[0m'
+ export LESS_TERMCAP_us=$'\E[01;32m'
+ # make less more friendly for non-text input files, see lesspipe(1)
+ [ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
+ export SYSTEMD_PAGER="less"
+ export LESSANSIENDCHARS="m"
+ export LESSANSIMIDCHARS="0123456789:;[?!\"'#%()*+ "
+fi
+# ----- MISC ----- #
+# nopaste
+export NOPASTE_SERVICES='pastebin nopaste'
+export NOPASTE_NICK='CHANGEME'
+# libvirt
+export LIBVIRT_DEFAULT_URI="qemu:///system"
+# set variable identifying the chroot you work in (used in the prompt below)
+if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
+ debian_chroot=$(cat /etc/debian_chroot)
+fi