#!/usr/bin/env bash # shellcheck shell=bash ALIASES_GREEN='\033[0;32m' # Green ALIASES_BLUE='\033[0;34m' # Blue ALIASES_WHITE='\033[1;37m' # White ALIASES_NC='\033[0m' # No Color echo "Remember aliases:" echo -e "${ALIASES_WHITE} et en ens ee" echo " dusort debuglog mkcd" echo -e "${ALIASES_NC}" echo "" alias backup='sudo borgmatic create --verbosity 1 --files' alias disk-usage='printf "%s\n" "disk-usage is deprecated; use dusort instead." >&2' alias cs='lxc list -c ns4b,user.comment:comment' alias pc='pcmanfm . & disown' # enable aliases for commands inside sudo # TOOD check this is safe alias sudo='sudo ' alias venv='source ./venv/bin/activate' alias e='nvim' alias er='nvim README.md' alias et='nvim TODO.md' alias en='nvim NOTES.md' alias ens='nvim NEXT_STEPS.md' alias ea='nvim .autonote.md' alias ee='nvim .' alias speak='/usr/local/src/kokora/speak' debuglog() { clear : > debug.log tail -f debug.log } alias debug.log='printf "%s\n" "debug.log is deprecated; use debuglog instead." >&2' dusort() { if [ "$#" -gt 1 ]; then printf '%s\n' 'Usage: dusort [path]' >&2 return 2 fi _dusort_path=${1:-.} if [ ! -e "$_dusort_path" ]; then printf 'dusort: path does not exist: %s\n' "$_dusort_path" >&2 unset _dusort_path return 1 fi if sudo du -h -d 2 -- "$_dusort_path" | sort -h; then unset _dusort_path return 0 fi unset _dusort_path return 1 } alias g='git status' alias gg='git add . && git commit -m "update" && git push' alias ls='LC_COLLATE=C ls --color=auto -h --group-directories-first --time-style=+"%d.%m.%Y %H:%M" -F' alias cp='cp -irv' alias mkdir='mkdir -vp' alias mv='mv -iv' alias rm='rm -dv' alias wget='wget --hsts-file="$XDG_DATA_HOME/wget-hsts"' alias grep='grep --colour=auto' alias egrep='egrep --colour=auto' alias fgrep='fgrep --colour=auto' alias bc='bc -q -l' alias ytdl='yt-dlp --write-info-json --write-description --no-playlist' alias ytdlb='yt-dlp --write-info-json --write-description --no-playlist -a' alias ytdl-mp3='yt-dlp -f bestaudio --extract-audio --audio-format mp3 --embed-thumbnail --add-metadata' # Transitional aliases for destinations now managed by ~/.ssh/config. alias mac='printf "%s\n" "mac is deprecated; use ssh mac instead." >&2' alias pi4='printf "%s\n" "pi4 is deprecated; use ssh pi4 instead." >&2' alias red='printf "%s\n" "red is deprecated; use ssh red instead." >&2' alias alice='printf "%s\n" "alice is deprecated; use ssh alice instead." >&2' alias phthalo='printf "%s\n" "phthalo is deprecated; use ssh phthalo instead." >&2' alias zirconia='printf "%s\n" "zirconia is deprecated; use ssh zirconia instead." >&2' alias zirconiarc='printf "%s\n" "zirconiarc is deprecated; use ssh zirconiarc instead." >&2' alias datapasa='printf "%s\n" "datapasa is deprecated; use ssh datapasa instead." >&2' alias ultra='printf "%s\n" "ultra is deprecated; use ssh ultra instead." >&2' alias singsay='printf "%s\n" "singsay is deprecated; use ssh singsay instead." >&2' alias kermit='printf "%s\n" "kermit is deprecated; use ssh kermit instead." >&2' alias crafty='printf "%s\n" "crafty is deprecated; use ssh crafty instead." >&2' alias lv='printf "%s\n" "lv is deprecated; use ssh lv instead." >&2' commands() { awk -F '\t' ' NF == 0 { next } NF != 3 || ($1 != "yes" && $1 != "no") || $2 == "" || $3 == "" { printf "Invalid command reminder on line %d.\n", NR > "/dev/stderr" invalid = 1 next } seen[$2]++ { printf "Duplicate command reminder for %s on line %d.\n", $2, NR > "/dev/stderr" invalid = 1 next } { count++ reminder[count] = $1 command[count] = $2 description[count] = $3 if (length($2) > command_width) command_width = length($2) if (length($3) > description_width) description_width = length($3) } END { if (invalid) exit 1 if (length("COMMAND") > command_width) command_width = length("COMMAND") if (length("DESCRIPTION") > description_width) description_width = length("DESCRIPTION") printf "%-*s %-*s %s\n", command_width, "COMMAND", description_width, "DESCRIPTION", "REMINDER" for (row = 1; row <= count; row++) { printf "%-*s %-*s %s\n", command_width, command[row], description_width, description[row], reminder[row] } } ' "${XDG_CONFIG_HOME:-$HOME/.config}/profile/commands.tsv" } _command_reminder() { awk -F '\t' -v width="${COLUMNS:-80}" ' NF == 0 { next } NF != 3 || ($1 != "yes" && $1 != "no") || $2 == "" || $3 == "" { printf "Invalid command reminder on line %d.\n", NR > "/dev/stderr" invalid = 1 next } seen[$2]++ { printf "Duplicate command reminder for %s on line %d.\n", $2, NR > "/dev/stderr" invalid = 1 next } $1 == "yes" { command[++count] = $2 } END { if (invalid) exit 1 if (width < 40) width = 80 line = " " for (row = 1; row <= count; row++) { separator = (line == " " ? "" : " ") if (length(line) + length(separator) + length(command[row]) > width) { print line line = " " command[row] } else { line = line separator command[row] } } if (line != " ") print line } ' "${XDG_CONFIG_HOME:-$HOME/.config}/profile/commands.tsv" } # lf gets confused by TERMINFO env var when running in tmux # https://github.com/gokcehan/lf/issues/138#issuecomment-464477665 if [ -n "$TERMINFO" ] ; then alias lf="TERMINFO= lf -last-dir-path=~/.cache/lf-last-dir" else alias lf="lf -last-dir-path=~/.cache/lf-last-dir" fi cdlf() { local last_dir [ -r "$HOME/.cache/lf-last-dir" ] || return 1 IFS= read -r last_dir < "$HOME/.cache/lf-last-dir" [ -n "$last_dir" ] || return 1 cd -- "$last_dir" || return } lfcd() { lf -last-dir-path="$HOME"/.cache/lf-last-dir && cdlf } hosts() { if [ ! -r "$HOME/.ssh/config.d/hosts.conf" ]; then printf '%s\n' 'SSH host configuration is unavailable.' >&2 return 1 fi awk ' tolower($1) == "host" { for (field = 2; field <= NF; field++) { if ($field !~ /[*?!]/) print $field } } ' "$HOME/.ssh/config.d/hosts.conf" } update() { echo -e "Executing \"${ALIASES_GREEN}pacman -Syu${ALIASES_NC}\" via \"${ALIASES_BLUE}archnews_wrap${ALIASES_NC}\" wrapper" sudo ~/.src/archnews/archnews_wrap -Syu || return systemctl --user start --no-block package-status-refresh.service >/dev/null 2>&1 || true } mkcd() { mkdir "$1" || return cd "$1" || return }