BIG UPDATE: shell: add profile, move calc and mkcd to files, move
shell-independent config (aliases, functions, env vars, options) to .config/shell/shrc, make bashrc and zshrc use the same shrc, add TTY detection for changing caps lock to escape in a TTY, add option for skipping plugin loading, and maybe a few other things If this goes well, I'll be tempted to call this version 1.0. Things have been very stable for the last few months. Although, since it's the first really big change in a while, that might make it version 2.0? Should dotfiles have big version numbers at all? Probably not.
This commit is contained in:
parent
4241c6ef05
commit
f5e15cacde
6 changed files with 209 additions and 94 deletions
87
.config/shell/shrc
Normal file
87
.config/shell/shrc
Normal file
|
@ -0,0 +1,87 @@
|
|||
# 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"
|
||||
### <<<
|
||||
|
||||
# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3:ts=3
|
Loading…
Add table
Add a link
Reference in a new issue