2022-02-03

This commit is contained in:
Louis Seubert 2022-02-03 19:33:04 +01:00
parent f86b8496ec
commit db393215ce
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
55 changed files with 1907 additions and 0 deletions

View file

@ -0,0 +1,54 @@
for edit in nvim vim nano vi; do
EDITOR="$(command -v ${edit})" && break
done
VISUAL="${EDITOR}"
# path-munge [OPTIONS] path
# -b add path as prefix to existing path
# -a add path as suffix to existing path (default)
function path-munge() {
local mode='suffix'
local OPTIND=1 OPTFLG=''
while getopts "ba" OPTFLG "$@"; do
case "${OPTFLG}" in
b) mode='prefix' ;;
a) mode='suffix' ;;
:) ;;
*) ;;
esac
done
shift "$((OPTIND - 1))"
if [[ :${PATH}: != *:$1:* ]]; then
case "${mode}" in
prefix) PATH="$1${PATH:+":"}${PATH}" ;;
suffix) PATH="${PATH}${PATH:+":"}$1" ;;
esac
fi
}
# shellcheck disable=SC2120
function has-superuser-priviliges() {
[[ "$(/usr/bin/groups)" == *"${1:-"wheel"}"* || "$(/usr/bin/id -u)" == "0" ]]
}
# reset bin lookup path
PATH=''
if has-superuser-priviliges; then
path-munge /usr/local/sbin
path-munge /usr/sbin
fi
path-munge /usr/local/bin
path-munge /usr/bin
# user binaries will always be first
path-munge -b ~/.local/bin
export EDITOR VISUAL PATH
unset -f has-superuser-priviliges

View file

@ -0,0 +1,33 @@
# -*- mode: bash -*-
# append to the history file, don't overwrite it
shopt -s histappend
# save multi-line commands as one command
shopt -s cmdhist
# use readline on history
shopt -s histreedit
# load history line onto readline buffer for editing
shopt -s histverify
# use standard ISO 8601 timestamp
# %F equivalent to %Y-%m-%d
# %T equivalent to %H:%M:%S (24-hours format)
TIME_LONG='%F %T'
TIME_DEFAULT="${TIME_LONG}"
HISTCONTROL="erasedups:ignoredups:ignorespace"
HISTSIZE=500000
HISTFILESIZE="${HISTSIZE}"
HISTFILE="${HOME}/.local/state/bash/history"
HISTTIMEFORMAT="${TIME_DEFAULT} "
export HISTFILE HISTSIZE HISTFILESIZE HISTCONTROL HISTTIMEFORMAT
# enable incremental history search with up/down arrows
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[C": forward-char'
bind '"\e[D": backward-char'

View file

@ -0,0 +1,61 @@
# shellcheck shell=bash
PSBIN="${HOME}/.local/share/bash"
prompt() {
local status="$?" file
PS1="${PSFIX}"
PSSCM="$(source "${PSBIN}/prompt/prompt-scm.sh" 2>/dev/null )"
PSPIP="$(source "${PSBIN}/prompt/prompt-pip.sh" 2>/dev/null )"
# done refreshing, starting to assemble it.
PS1="${PS1}\\[\\e[0m\\]${PSSCM%% }${PSSCM:+" "}"
PS1="${PS1}\\[\\e[0m\\]${PSPIP%% }${PSPIP:+" "}"
# change prompt if last execution was not successful
if [[ "${status}" -gt 0 ]]; then
PS1="${PS1}\\[\\e[0;31m\\]\\$"
else
PS1="${PS1}\\[\\e[0;32m\\]\\$"
fi
# back to default
PS1="${PS1}\\[\\e[0m\\] "
}
# Use window titles only in known X terminals.
case ${TERM} in
xterm*|rxvt*|Eterm|aterm|kterm|gnome|screen)
PSTITLE='\[\e]0;\u@\h:\w\a\]'
;;
*)
PSTITLE=''
;;
esac
: "${PSUSERCOLOR:="1;33"}" # yellow by default
: "${PSHOSTCOLOR:="1;33"}" # yellow by default
typeset -A PSHOSTCOLORS
PSHOSTCOLORS[louis@desktop-louis]="38;5;164@1;30"
if [[ -n ${PSHOSTCOLORS[${USER}@${HOSTNAME}]} ]]; then
PSUSERCOLOR="${PSHOSTCOLORS["${USER}@${HOSTNAME}"]%@*}"
PSHOSTCOLOR="${PSHOSTCOLORS["${USER}@${HOSTNAME}"]##*@}"
fi
if [[ ${EUID} -eq 0 ]]; then
PSUSERCOLOR="38;5;160"
fi
# window title if the terminal can interpret this
PSFIX="${PSTITLE}"
# user, with color according to preference
PSFIX="${PSFIX}\\[\\e[${PSUSERCOLOR}m\\]\\u\\[\\e[0m\\]"
# @
PSFIX="${PSFIX}\\[\\e[0m\\]@"
# host, with color according to preference
PSFIX="${PSFIX}\\[\\e[${PSHOSTCOLOR}m\\]\\h\\[\\e[0m\\]"
# current working directory.
PSFIX="${PSFIX}\\[\\e[38;5;111m\\] \\W "
PROMPT_DIRTRIM=1
PROMPT_COMMAND+=('prompt')

View file

@ -0,0 +1 @@
basename "${VIRTUAL_ENV:-}" 2>/dev/null

View file

@ -0,0 +1,40 @@
#!/bin/bash
{ type -p git && git rev-parse --git-dir; } >/dev/null 2>&1 || exit $?
# see https://git-scm.com/docs/git-status for more information
# these are status information from the local git index
CAH=0 CBH=0
D=0 A=0 M=0 R=0 U=0 I=0
while read -r format state values; do
case ${format} in
\#)
case ${state} in
branch.oid) COMMIT="${values}" ;;
branch.head) BRANCH="${values}" ;;
branch.upstream) UPSTREAM="${values}" ;;
branch.ab) read -r CAH CBD <<<"${values}" ;;
esac
;;
1) (( ${state:0:1}++ )) ;;
2) (( ${state:0:1}++ )) ;;
\?) (( U++ )) ;;
\!) (( I++ )) ;;
esac
done < <(git status --porcelain=2 --branch)
[[ ${CAH} -gt 0 ]] && echo -n "\\[\\e[0;32m\\]<\\[\\e[0m\\]${CAH} ";
[[ ${CBH} -gt 0 ]] && echo -n "\\[\\e[0;31m\\]>\\[\\e[0m\\]${CBH} ";
[[ ${M} -gt 0 ]] && _BRANCH="\\[\\e[0;31m\\]" || _BRANCH="\\[\\e[0;32m\\]"
if [[ "${BRANCH}" == "(detached)" ]]; then
BRANCH="{${COMMIT:0:8}}"
else
BRANCH="(${BRANCH})"
fi
echo -n "${_BRANCH}${BRANCH}\\[\\e[0m\\] "
[[ ${A} -gt 0 ]] && echo -n "\\[\\e[0;32m\\]+\\[\\e[0m\\]${A} ";
[[ ${D} -gt 0 ]] && echo -n "\\[\\e[0;31m\\]-\\[\\e[0m\\]${D} ";
[[ ${M} -gt 0 ]] && echo -n "\\[\\e[0;35m\\]~\\[\\e[0m\\]${M} ";
[[ ${U} -gt 0 ]] && echo -n "\\[\\e[0;33m\\]?\\[\\e[0m\\]${U} ";

View file

@ -0,0 +1,31 @@
# -*- mode: bash -*-
# update window size after every command
shopt -s checkwinsize
# prepend cd to directory names automatically
shopt -s autocd
shopt -s dirspell
shopt -s cdspell
# READLINE
# perform file completion in a case
# insensitive fashion
bind "set completion-ignore-case on"
# treat hyphens and underscores as equivalent
bind "set completion-map-case on"
# display matches for ambiguous patterns
# at first tab press
bind "set show-all-if-ambiguous on"
# immediately add a trailing slash when
# autocompleting symlinks to directories
bind "set mark-symlinked-directories on"
# vi mode configurations
bind "set vi-ins-mode-string \1\e[6 q\2\1ins\2"
bind "set vi-cmd-mode-string \1\e[2 q\2\1cmd\2"
bind "set show-mode-in-prompt on"
# ➜

View file

@ -0,0 +1,105 @@
# shellcheck shell=bash
#region common functions for working with directories
# ---------------------------------------------
# shortcuts for moving around
# ---------------------------------------------
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
# ---------------------------------------------
# shortcuts for creating and removing folders
# ---------------------------------------------
alias md='mkdir -p'
alias rd='rmdir'
# ---------------------------------------------
# more shortcuts for listing files
# ---------------------------------------------
alias ls='ls --color=auto'
alias la='ls --color=auto -Alh' # show hidden files
alias ll='ls --color=auto -lh' # sort by size human readable
alias lr='ls --color=auto -lR' # recursive ls
alias lt='ls --color=auto -ltr' # sort by date
# ---------------------------------------------
# shortcuts for showing human-readable fs info
# ---------------------------------------------
# short and human-readable file listing
alias dud='du -d 1 -h'
# short and human-readable directory listing
alias duf='du -sh *'
#endregion
#region common functions for working with file permissions
# ---------------------------------------------
# ---------------------------------------------
alias perm='stat --printf "%a %n \n "' # perm: show permission of target in number
# ---------------------------------------------
# ---------------------------------------------
alias 000='chmod 000' # ---------- (user: -, group: -, other: -)
alias 640='chmod 640' # -rw-r----- (user: rw, group: r, other: -)
alias 644='chmod 644' # -rw-r--r-- (user: rw, group: r, other: -)
alias 755='chmod 755' # -rwxr-xr-x (user: rwx, group: rx, other: x)
alias 775='chmod 775' # -rwxrwxr-x (user: rwx, group: rwx, other: rx)
# ---------------------------------------------
# ---------------------------------------------
alias ux='chmod u+x' # ---x------ (user: --x, group: -, other: -)
alias mx='chmod a+x' # ---x--x--x (user: --x, group: --x, other: --x)
#endregion
#region common preferred default implementation
# 'wget' with resume download
alias wget='wget -c --no-hsts'
# just use color, please
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'
#endregion
# path: echo all executable paths
alias path='echo -e ${PATH//:/\\n}'
# cs: clear terminal display
alias cs='clear'
# ed: editd file in default editor
alias ed='${EDITOR}'
# se: editd file in default editor with sudo rigths
alias se='sudoedit'
# src: reload .bashrc file
alias src='source ~/.bashrc'
# qfind: quickly search for file
alias qfind='find . -name '
# ip just color my ip command
alias ip='ip -c'
# Mirror stdout to stderr, useful for seeing data going through a pipe
alias peek='tee >(cat 1>&2)'
function open() { command xdg-open "${@:-"${PWD}"}" >/dev/null 2>&1; }
function code() { command codium "${@:-"${PWD}"}" >/dev/null 2>&1; }
function mcd() { mkdir -p "$1" && cd "$1" || return; }
# Execute a command in a specific directory
function xin() ( cd "${1}" && shift && "${@}"; )