2022-08-09 18:33:35 -07:00
|
|
|
#!/bin/sh
|
|
|
|
# Blakely's basic shell configuration file
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2022-08-09 18:33:35 -07:00
|
|
|
# This file doesn't need a shebang at the top, but it has one
|
|
|
|
# so shellcheck knows this file has to be compatible with POSIX sh
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
|
2022-08-09 18:33:35 -07:00
|
|
|
### Pre-setup >>>
|
|
|
|
# shellcheck disable=SC1090
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
# 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
|
2022-08-21 20:57:19 -07:00
|
|
|
${5:-.} "$1"
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
else
|
|
|
|
if test -n "${2+foo}"; then
|
2022-08-09 18:33:35 -07:00
|
|
|
printf "%s\n" "$2" >&2
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
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
|
2022-08-09 18:33:35 -07:00
|
|
|
printf '\e[5 q'
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
|
|
|
|
### <<<
|
|
|
|
### 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 >>>
|
2022-08-09 18:33:35 -07:00
|
|
|
# Organization: functions should be put in their own files, located in
|
|
|
|
# $SHELL_CONFIG_DIR/functions. If they can be converted into a script, they
|
|
|
|
# should be.
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
#
|
|
|
|
# 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
|
2022-08-09 18:33:35 -07:00
|
|
|
# just like you would if you were writing it here. Make sure to describe what
|
|
|
|
# the function does at the top, and say what dependencies it has (if any).
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
|
2022-08-09 18:33:35 -07:00
|
|
|
# Function to load all functions that are stored in files
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
fnupdate() {
|
|
|
|
for FN in "$SHELL_CONFIG_DIR"/functions/*;do
|
2022-08-09 18:33:35 -07:00
|
|
|
. "$FN"
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
done
|
|
|
|
}
|
|
|
|
${SKIP_FUNCTIONS:-false} || fnupdate
|
|
|
|
|
|
|
|
# <<<
|
|
|
|
### Options >>>
|
|
|
|
set -o vi
|
2022-08-09 18:33:35 -07:00
|
|
|
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
# <<<
|
2022-08-09 18:33:35 -07:00
|
|
|
|
|
|
|
# <<<
|
|
|
|
### Load the local shrc >>>
|
|
|
|
${SKIP_LOCAL_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/local/shrc" \
|
|
|
|
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
# <<<
|
|
|
|
### 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"
|
2022-08-09 18:33:35 -07:00
|
|
|
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
### <<<
|
2024-09-16 11:52:50 -07:00
|
|
|
### "Plugins" >>>
|
|
|
|
${SKIP_SH_PLUGINS:-false} || careful_source "$SHELL_CONFIG_DIR/plugins"
|
|
|
|
|
|
|
|
# <<<
|
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.
2022-04-08 13:36:29 -07:00
|
|
|
|
2022-08-09 18:33:35 -07:00
|
|
|
# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3:ts=3
|