diff options
Diffstat (limited to '.bash/aliases.bash')
| -rw-r--r-- | .bash/aliases.bash | 210 |
1 files changed, 203 insertions, 7 deletions
diff --git a/.bash/aliases.bash b/.bash/aliases.bash index 86334b7..42e1639 100644 --- a/.bash/aliases.bash +++ b/.bash/aliases.bash @@ -6,18 +6,37 @@ if [ "$TERM" != "dumb" ];then eval "$(dircolors -b)" alias ls="ls --color=auto" - alias grep="grep --color=auto" - alias egrep="egrep --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" +#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' @@ -73,7 +92,7 @@ alias sshk='ssh -o PasswordAuthentication=yes -o PreferredAuthentications=keyboa alias sshg="ssh-with-gpg" function add-sshagent-init { for KEY in "${SSHKEYS[@]}";do - FFPRINT="$(ssh-keygen -Esha256 -lf "$KEY")" + FFPRINT="$(ssh-keygen -Esha256 -lf "$KEY")" || return 1 if ! ssh-add -l 2>/dev/null | grep "$FFPRINT" >/dev/null; then ssh-add -q "$KEY" fi @@ -90,11 +109,51 @@ xstat() { 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' +} +alias hdash='hsep "-"' +alias hddash='hsep "="' +#alias hline='hsep -i "─"' +alias hline='hsep -i "─"' +alias hdline='hsep -i "═"' +alias hfline='hsep -i "━"' # ----- PACKAGE MANAGERS ----- # -if [ -x "/usr/bin/pikaur" ];then - alias pkgclean="pikaur --no-confirm -Sc" +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 --no-confirm -Sc" + 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 @@ -102,6 +161,8 @@ elif [ -x "/usr/bin/dnf" ];then 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' @@ -160,6 +221,7 @@ 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" @@ -185,3 +247,137 @@ if command -v podman >/dev/null;then 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 +# 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' |
