git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/.bash/vars.bash
diff options
context:
space:
mode:
Diffstat (limited to '.bash/vars.bash')
-rw-r--r--.bash/vars.bash2
1 files changed, 2 insertions, 0 deletions
diff --git a/.bash/vars.bash b/.bash/vars.bash
index 8517fdc..ae5de14 100644
--- a/.bash/vars.bash
+++ b/.bash/vars.bash
@@ -118,3 +118,5 @@ if [ -r "vars.bash.local" ];then
source vars.bash.local
fi
export SSHENVFILE="${HOME}/.ssh/sshenv"
+export BAT_THEME="OneHalfDark"
+export BAT_STYLE="changes,header,grid,numbers,snip"
href='#n94'>94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
#!/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"
	case "$OSNAME" in
		'sunos') ;;
		*)
			alias grep="grep --color=auto"
			alias egrep="egrep --color=auto"
		;;
	esac
fi
# shellcheck disable=SC2139
if [ -n "$EDITOR" ]; then
	alias editor="$EDITOR"
elif [ -n "$VISUAL" ]; then
	alias editor="$VISUAL"
elif [ -x "/usr/bin/vim" ]; then
	alias editor="/usr/bin/vim"
elif [ -x "/usr/bin/vi" ]; then
	alias editor="/usr/bin/vi"
else
	alias editor="/usr/bin/edit"
fi
alias lst="ls -l --time-style=full-iso"
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'
alias tbc='tbclock -e -H2 -M7 -S3'
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 scrls='ls -l "${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 isocreate='rm -vf /tmp/image.iso && mkisofs -v -r -J -translation-table -hide-joliet-trans-tbl -iso-level 4 -o /tmp/image.iso'
#alias isoburn='sudo cdrecord -v -speed=10 dev=/dev/sr0 -data'
alias isoburn='sudo cdrecord -v dev=/dev/sr0 -data'
# voice messages e.g. for whatsapp (on libpurple). use "voicemsg OUTPUT.ogg"
alias voicemsg='ffmpeg -f pulse -i default -ac 1 -ar 16000 -c:a libopus -y'
if command -v colordiff > /dev/null;then alias diff="colordiff";fi
# aliases like this are relevant if you use multiple passwordstore stores, e.g.
# your common store is a department-wide one but you still need to store personal credentials
alias ppass='PASSWORD_STORE_DIR=~/.password-store pass'
alias ifs='printf "%q\\n" "$IFS "'
# ----- 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'
alias sshg="ssh-with-gpg"
function add-sshagent-init {
	declare -a ADDKEYS
	for KEY in "${SSHKEYS[@]}"; do
		FFPRINT="$(ssh-keygen -Esha256 -lf "$KEY")" || return 1
		if ! ssh-add -l 2>/dev/null | grep "$FFPRINT" >/dev/null; then
			ADDKEYS+=( "$KEY" )
		fi
	done
	ssh-add -q "${ADDKEYS[@]}"
}
alias sshmaster='ssh -O'
# ----- FS ----- #
xstat() {
	for target in "${@}";do
		# shellcheck disable=SC2012
		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
}
# ----- DECORATIVE STUFF ----- #
function coleval {
	mycols="$COLUMNS"
	if [ -z "$COLUMNS" ]; then mycols="$(tput cols 2>/dev/null)"; fi
	if [ -z "$COLUMNS" ]; then mycols=20; fi
	printf '%b' "$mycols"
}
function hsep {
	mycols="$(coleval)"
	nocalc=0
	declare mychar
	while [ "$#" -gt 0 ]; do
		case "$1" in
			'-i') nocalc=1; shift ;;
			*) mychar="$1"; shift ;;
		esac
	done
	[ -z "$mychar" ] && return 1
	[ "$(printf '%b' "$mychar" | wc --chars)" -ne 1 ] && return 2
	if [ "$nocalc" -ne 1 ]; then
		# if we encounter a one-char three-byte character, we may have hit a Unicode
		# symbol that indeed is a little wider. Use bashes mathematical division- it rounds
		# down, but this is what we want as we cannot split a character into parts :-)
		# The result might be significantly narrower than the terminal's width, but for
		# now we don't have any better math.
		[ "$(printf '%b' "$mychar" | wc --bytes)" -eq 3 ] && mycols="$(( 4 * mycols / 9 ))"
	fi
	for (( i=0;i<mycols;++i )); do
		printf '%b' "$mychar"
	done
	printf '\n'
}
function hdash { hsep '-'; }
function hddash { hsep '='; }
#alias hline='hsep -i "─"'
function hline { hsep -i '─'; }
function hdline { hsep -i '═'; }
function hfline { hsep -i '━'; }
# ----- PACKAGE MANAGERS ----- #
if [ -x "/usr/bin/paru" ];then
	alias pkgclean="paru --noconfirm -Sc"
elif [ -x "/usr/bin/pikaur" ];then
	alias pkgclean="pikaur --noconfirm -Sc"
elif [ -x "/usr/bin/pacman" ];then
	alias pkgclean="/usr/bin/sudo /usr/bin/pacman --noconfirm -Sc"
elif [ -x "/usr/bin/apt" ];then
	alias pkgclean="/usr/bin/sudo /usr/bin/apt clean"
elif [ -x "/usr/bin/dnf" ];then
	alias pkgclean="/usr/bin/sudo /usr/bin/dnf clean packages"
elif [ -x "/usr/bin/zypper" ];then
	alias pkgclean="/usr/bin/sudo /usr/bin/zypper clean"
fi
# ----- RPM ----- #
alias rpm-listkeys="rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} | %{summary}\n'"
# ----- 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'
alias default-desktop-apps="editor ~/.config/mimeapps.list"
# ----- 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
# ----- PUPPET + RUBY ----- #
# ...yeah, I'm mostly doing ruby stuff for Puppet, erm I mean
# OpenVox (now that Perforce have turned the Puppet world to a burning heap of garbage)
alias bake="bundle exec rake"
# ----- SOFTWARE MGMT ----- #
# We may want to avoid having old $things[] running on our machine. While package managers
#   should be the absolute priority, there may be things like Ruby gems, Python packages,
#   Rust crates which we may need especially on anything other than an Arch machine.
# Define a function that runs all updates.
# This does not care about isolated venv/bundle/whatnot directories, it maintains
#   the installations in the standard user home folders explicitly.
# DANGER: this may lead to breaking changes in one language while the others still perform
#   fine.
function update-user-extensions {
	mystrt='\033[38;2;23;147;209m'
	mywarn='\033[38;5;178m'
	mydone='\033[38;5;71m'
	myrset='\033[0m'
	# Ruby / user's gems
	if [ -x '/usr/bin/gem' ]; then
		printf '%bRuby (through gem)%b\n' "$mystrt" "$myrset"
		# We expect a file ~/.config/usergems with one gem per line.
		# Found no way yet to determine --user-installed gems, let alone
		#   those explicitly installed (vs. dependency-only).
		if [ -r "${HOME}/.config/usergems" ]; then
			while read -r gem; do
				gem update "$gem" --user-install || exit 110
			done < <(cat "${HOME}/.config/usergems")
		else
			printf '%b%b not found, not updating gems.%b\n' "$mywarn" "${HOME}/.config/usergems" "$myrset" >&2
		fi
		printf '%bdone.%b\n' "$mydone" "$myrset"
	else
		printf '%b/usr/bin/gem not found, not updating Ruby user installations.%b\n' "$mywarn" "$myrset"
	fi
	# pipx for Python
	if [ -x '/usr/bin/pipx' ]; then
		printf '%bPython (through pipx)%b\n' "$mystrt" "$myrset"
		pipx list --short || exit 111
		pipx upgrade-all || exit 112
		printf '%bdone.%b\n' "$mydone" "$myrset"
	else
		printf '%b/usr/bin/pipx not found, not updating Python user installations.%b\n' "$mywarn" "$myrset"
	fi
	# Rust / user's crates
	if [ -x '/usr/bin/cargo' ]; then
		printf '%bRust (through cargo)%b\n' "$mystrt" "$myrset"
		# For this to work, a user must have run 'cargo install cargo-update' at least once.
		cargo install-update --all || exit 113
		printf '%bdone.%b\n' "$mydone" "$myrset"
	else
		printf '%b/usr/bin/cargo not found, not updating Rust user installations.%b\n' "$mywarn" "$myrset"
	fi
}
# Display developer environment base versions.
function list-env-versions {
	hline
	printf 'Versions:\n'
	(
		printf 'Bash;%b\n' "$BASH_VERSION"
		if [ -r '/opt/puppetlabs/puppet/VERSION' ]; then
			printf 'Puppet;%b\n' "$(cat /opt/puppetlabs/puppet/VERSION)"
		fi
		ruver="$(ruby -e 'print(RUBY_VERSION)' 2>/dev/null)"
		rsver="$(/usr/bin/ruby -e 'print(RUBY_VERSION)' 2>/dev/null)"
		if [ "$ruver" != "$rsver" ]; then
			printf 'Ruby;%b (System: %b)\n' "$ruver" "$rsver"
		else
			printf 'Ruby;%b\n' "$rsver"
		fi
		# This is a mere string but in this case this is exactly what we want
		puver="$(python -c 'from platform import python_version;print(python_version())' 2>/dev/null)"
		psver="$(/usr/bin/python -c 'from platform import python_version;print(python_version())' 2>/dev/null)"
		if [ -n "$puver" ] || [ -n "$psver" ]; then
			if [ "$puver" != "$psver" ]; then
				printf 'Python;%b (System: %b)\n' "$puver" "$psver"
			else
				printf 'Python;%b\n' "$psver"
			fi
		fi
		huver="$(ghci --version 2>/dev/null | awk '{print $NF}')"
		hsver="$(/usr/bin/ghci --version 2>/dev/null | awk '{print $NF}')"
		cuver="$(cabal --version 2>/dev/null | awk '{print $NF}')"
		csver="$(/usr/bin/cabal --version 2>/dev/null | awk '{print $NF}')"
		stver="$(stack --version 2>/dev/null | head -n1)"
		if [ -n "$stver" ]; then
			shver="$(stack ghc -- --version 2>/dev/null | awk '{print $NF}')"
		fi
		printf 'Haskell\n'
		if [ -n "$huver" ] || [ -n "$hsver" ]; then
			if [ "$huver" != "$hsver" ]; then
				printf ';GHCI:\t%b (System: %b)\n' "$huver" "$hsver"
			else
				printf ';GHCI:\t%b\n' "$psver"
			fi
		fi
		if [ -n "$cuver" ] || [ -n "$csver" ]; then
			if [ "$cuver" != "$csver" ]; then
				printf ';Cabal:\t%b (System: %b)\n' "$cuver" "$csver"
			else
				printf ';Cabal:\t%b\n' "$psver"
			fi
		fi
		if [ -n "$stver" ]; then
			printf ';Stack:\t%b, GHC: %b\n' "$stver" "$shver"
		fi
	) | column -ts';' | sed 's/^/\t/'
	hline
}
# ----- OTHER STUFF ----- #
for cmmd in batcat bat; do
	if command -v "$cmmd" > /dev/null; then
		# shellcheck disable=SC2139
		alias cat="${cmmd} --tabs 4 --wrap never --paging never --style 'plain,rule'"
		# shellcheck disable=SC2139
		alias less="${cmmd} --tabs 4 --wrap never --paging always --style 'plain,rule'"
		alias plain-cat='/usr/bin/cat'
		alias plc='/usr/bin/cat'
		alias plain-less='/usr/bin/less'
		alias pll='/usr/bin/less'
		export MANPAGER="sh -c 'col -bx | ${cmmd} -l man -p'"
		export MANROFFOPT="-c"
		break
	fi
done
if command -v 'thefuck' > /dev/null; then
	alias wtf='thefuck $(fc -nl -1)'
fi
alias ip='ip --color=auto'
alias kl='klist -facnA'
alias l='exa -hg'
alias ll='exa -hgl --git'
# Flake8. Nice linter, but...
# They kneeled to USER STUPIDITY when it comes to configuration. Wut?
# https://flake8.pycqa.org/en/latest/release-notes/4.0.0.html#backwards-incompatible-changes
# --> https://github.com/pycqa/flake8/pull/1404
# Users were confused, so ~/.config/flake8 is not supported anymore. lelkek.
alias flake8='flake8 --config ${HOME}/.config/flake8'