dotfiles/.config/shell/shrc

89 lines
2.9 KiB
Bash

# Blakely's basic shell setup file
# This file is compatible with basic `sh`, and can
# be sourced in all `sh`-compatible shells to get
# the basic parts of the local `sh` configuration.
### Pre-setup >>>
# shellcheck disable=SC1090,SC2296,SC1091,SC2154,SC2015
# Helper function to source files.
# Usage:
# careful_source "file" \
# [optional: "Error message"] \
# [optional: $LINENO] (use this if you have an error message) \
# [optional: test to run] (-f, -x, -e) \
# [optional: operation (source, exec, command or nothing)] \
careful_source() {
if test "${4:--f}" "$1"; then
${5:-source} "$1"
else
if test -n "${2+foo}"; then
echo -e "$2" >&2
echo "Line number: $3" >&2
fi
fi
}
# for sending error messages from functions and whatnot
error() {
ERROR_CODE="$?"
>&2 echo "(zshrc) An error occurred on line number ${1}"
return $ERROR_CODE
}
# change cursor to a beam by default
echo -ne '\e[5 q'
### <<<
### Generic shell configuration >>>
### Environment variables >>>
# This has to go here because otherwise we don't know where the config files are :|
export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}"
# source the environment variable file
${SKIP_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/env" \
"Error: could not locate env file. Things could be messed up. Check that \$SHELL_CONFIG_DIR/env exists." $LINENO
${SKIP_LOCAL_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/local/env" \
# <<<
### Aliases >>>
# Source the alias file
${SKIP_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/aliases" \
"Error: could not locate alias file. You may not have any aliases. Check that \$SHELL_CONFIG_DIR points to the right place." $LINENO
${SKIP_LOCAL_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/local/aliases"
# <<<
### Functions >>>
# Organization: functions that are really short should be put here, otherwise
# they should be put in a file located in $SHELL_CONFIG_DIR/functions. If they
# can be converted into a script, they should be.
#
# To make a "function in a file" that fits with my personal spec, simply make a
# file, name it what the function is called, and put the function inside of it
# just like you would if you were writing it here.
# load all functions that are stored in files
fnupdate() {
for FN in "$SHELL_CONFIG_DIR"/functions/*;do
source "$FN"
done
}
${SKIP_FUNCTIONS:-false} || fnupdate
# <<<
### Options >>>
set -o vi
# <<<
# <<<
### Apply breaking changes with the update script >>>
${SKIP_UPDATES:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
"Error: failed to run update script" $LINENO -x "command"
### <<<
# terminal colorscheme
careful_source "$SHELL_CONFIG_DIR/colors.sh"
# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3:ts=3