fsh/core/aliases.src
Tessa L. H. Lovelace d482b30842 Functionality refactor, fix reloading a bit.
Add some whitespace for readability, fix a potentially problematic jargon usage.

Clarify copywrite slightly.

Add check for self variable, message on new terminals if not.

Eliminate/prune magic path config chunk, probably broke other bits slightly.
2020-05-17 11:37:42 -07:00

266 lines
8.2 KiB
Plaintext
Executable File

# @todo backwards-compile this file, install/uninstall processing
#
# special thanks to @Mattman of StackOverFlow for the original xtrace function.
# see https://stackoverflow.com/a/50141326 (or https://archive.today/lUqsD)
#
# Regretfully, programming is complex, so please read the warning labels.
#
# This time around, it's an attempt to cut back on the levels of
# Heavy Wizardry (http://www.catb.org/jargon/html/H/heavy-wizardry.html) in use.
### Bash environment setup stuffs ###
# disable size-based history file trimming.
export HISTSIZE=
export HISTFILESIZE= # <-- same as above, just a different variable.
# Share commands with sibling shells
shopt -s histappend # <-- append to the history file sooner than later.
export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
# alias expander, among other things
function xtrace {
local eval_cmd
printf -v eval_cmd '%q' "${@}"
{ set -x
eval "${eval_cmd}"
} 2>&1 | grep '^++'
return "${PIPESTATUS[0]}"
}
### enable f.sh stuffs ###
#
# This bit is really important.
#
## tl;dr ##
# search for **and understand** alias usage before changing things.
#
## long version ##
#
# Modifying this aliases file has deep repercussions in the user experience,
# *hence* the minor wall o' text
#
# Installing, reinstalling, and purging are essential program basics.
#
# If you can't manage to manage yourself well,
# how can you manage other programs any better?
#
## === ### Meta ### === ##
# (currently:)
# There's two modes:
# --> 'lite', which does a symlink, indended for end users
# +and+
# --> 'sudo', which assumes you have sudo apt privileges, and that you're
# running/attempting to run/managing a raspberry pi mini-mesh.
#
# This is the foundation of the [darkPi project](https://darkpi.com/), and contains
# rather a lot of hobbiest-level research and densely layered operartional meta-logic.
# Please understand the fences before you tear them down.
#
## === ### === ##
#
# When possible, shorten the control feedback loop.
#
# These scripts aspire to be examples of beautiful programming,
# examples of system engineering of the functionally artistic sort,
# mindful of [mel's kōan](http://www.catb.org/jargon/html/story-of-mel.html)[*](https://archive.today/f46RR) and the marathon.
#
# write for the code that could be ideal
# automate the minimum viable path
#
# do things for more than one reason.
#
## === ##
#
# ~ @copy;/© ????-2022 @jakimfett, all rights reserved.
#
# = #
#
#
# Installing this script will (eventually) be automated.
#
# For now, it requires injection of two lines into your ~/.bash_aliases file.
if [ -z "${FSH_ALIASES}" ]; then
# This will only show up if the aliases file is sourced directly,
# and can be avoided by prepending "(export) FSH_ALIASES='path/to/aliases.src'"
# to the source command.
#
# Otherwise, the following message has relatively clear instructions...
echo "FSH_ALIASES variable not found, add this to your '~/.bash_aliases' file:"
echo "export FSH_ALIASES=\"$(realpath ${BASH_SOURCE})\" "
echo ". \"${FSH_ALIASES}\" "
echo
# @todo - option to auto-inject variable?
FSH_ALIASES="$(realpath ${BASH_SOURCE})"
fi
# reload early, reload often.
# short for 'fully reload aliases'
alias fra='. "${FSH_ALIASES}" && sleep "0.1" && echo "aliases reloaded."'
# Give the non-machines a readable default time format.
alias when='date +"%Y_%m_%d%t%t%t%H.%M.%S (%Z/GMT%z)%n%A, %d %B%t%t%tDay %j"'
# make accessible?
# @todo - check PATH variable for writeable locations and pick the most accessible one
alias fMkDirs='mkdir -p "${FSRC}" "${BINPATH}"'
alias fLnk='ln -s -f "${FSRC}"/f.sh "${FBIN}" || echo failed linking src/bin;ln -s -f "{FSRC}"/core/aliases.src ~/.bash_aliases'
alias fInstall="fMkDirs || echo failed to mkdirs; fLnk || echo failed to link"
# Know if things are configured properly
#alias fStat='cat ~/.bash_aliases;ls -lah ~/ ~/bin | egrep "alias|fsh"'
alias fgst='cd "${FSRC};gst'
# work-in-progress autodownloader, stuck in git dependency loop.
# @todo - dynamically select installation from user-editable PATH location(s)
#alias installf`sh='mkdir -p ~/bin/src; cd ~/bin/src; git clone http://git.functions.sh'
#alias getFsh='mkdir -p ~/project;cd ~/project;git clone https://git.functions.sh/'
# for now, just plug in the expected golden path and try it in the shell.
# @todo - add check for ~/.bash_aliases is a symbolic link to this file, remove?
#alias fLogPurge='rm -f ~/project/fsh/tmp/*.log'
#alias fPurge='rm -f ~/bin/f && echo "please manually prune & verify .bash_aliases file status."'
# autoinstaller & functions check
# @todo refactor and verify user feedback is accurate
# @todo - refactor to eliminate magic paths
if [ ! -f "$(realpath ~/bin/f)" ]; then
# fallback command registration prototype
alias f='~/project/fsh/f.sh'
# automatically attempt install if flag is present.
if [ -f '~/.fsh.autoinstall' ];then
# perform functions.sh installation
fInstall
# the rest of this is just user-signaling and error handling.
if [ ! -f "$(realpath ~/bin/f)" ]; then
# install failed, inform our would-be user
echo "functions.sh autoinstall failed: $(date)" # | tee -a <some_logfile.txt />
else
rm '~/.fsh.autoinstall' && touch '~/.fsh.installed'
# At this point, the script should be available as 'f' in the shell, and
# a file in the homedir confirms editable storage area.
if [ ! -f '~/.fsh.installed' ] | [ ! -f "$(realpath ~/bin/f)" ]; then
echo "something went wrong, time to debug."
echo
echo "failmuffins"
exit 13
else
echo "functions.sh installed, starting in 5..."
sleep 1
echo "...4..."
sleep 1
echo "...3..."
sleep 1
echo "...2..."
sleep 1
echo "...1..."
sleep 1
echo "...0..."
eval '~/bin/f' &
disown
exit 0
fi
fi
else
# sweep away the clutter
clear
# show the user when they are
when
echo
# communicate status
echo "fsh shim in place,"
echo "(execute 'fInstall' for full toolkit.)"
echo
fi
fi
## QoL shortcuts ##
# keep your shortcuts close, your aliases, closer
alias sd='shutdown -hP now'
alias nano="nano --nowrap --tabsize 2"
alias gg='sudo su --login'
alias pathadd='export PATH="$(realpath `pwd`):${PATH}"'
alias micloop='pactl load-module module-loopback'
alias micunloop='pactl unload-module module-loopback'
alias kd='killall Discord;killall Discord;killall Discord;killall discord;'
# Open a tileable, disconnectable window session.
# Uses seconds since the unix epoc as the workspace differentiation postfix.
# command fails if ~/session directory fails to exist, @todo check and remediate
alias twm='dtach -A ~/session/default -r winch dvtm'
# additional tiled workspaces queue needed, @todo
alias twm2='dtach -A ~/session/default.$(date +"%s") -r winch dvtm'
# Multitasking is an essential part of a broken workflow. # <-- philosophy
# Do one thing at a time via multiple viewports.
# The terminal windows are portals to different parts of the machine.
### Useful SSH-adjacent aliases ###
# patchwork'd from https://unix.stackexchange.com/a/349821
alias ssh-showkey='ssh-keygen -lf <(ssh-keyscan localhost 2>/dev/null)'
# Debian sysadmin alias(es)
alias update="sudo apt update; sudo apt install -f -y; sudo apt autoremove -y"
alias uprepair="update; sudo apt install --fix-broken; sudo apt install --fix-missing"
alias upgrade="update; sudo apt dist-upgrade -y;uprepair"
alias shutgrade="upgrade; sudo shutdown -hP now"
alias regrade="upgrade; sudo reboot now"
## making git less obtuse ##
# status printout
alias gst='clear;echo;echo;echo "repository urls:";git remote -v;echo;git status;echo;ls -ah;echo;'
# @todo - enumerate bash aliases before/after load, publish diff as alises.provided?
# get developin' quickly.
alias ff='cd ~/src/fsh && rba && gst'
alias fff='ff && f -c'
# fetch all the things
alias gup='gst; echo;echo; git fetch origin; git fetch upstream; git fetch local'
# because qwerty is problematic - https://skeptics.stackexchange.com/a/5154|https://archive.today/I5Z6Z
alias got='git'
# courtesy of https://social.wxcafe.net/@wxcafe/103620041773395685
alias exut='exit'
alias lsd='ls'
# colorized ls
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
if [ -z ${LS_OPTIONS+set} ]; then
alias ll='ls $LS_OPTIONS -lah'
else
alias ll='ls -lah'
fi