From 36015b8d4c2ec9af4bcbeafaf5b4606eb6c9612a Mon Sep 17 00:00:00 2001 From: PowerUser64 Date: Tue, 9 Aug 2022 18:33:35 -0700 Subject: [PATCH] shell: update shrc to be POSIX sh compatible --- .config/shell/shrc | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/.config/shell/shrc b/.config/shell/shrc index 5b76385..3022331 100644 --- a/.config/shell/shrc +++ b/.config/shell/shrc @@ -1,12 +1,15 @@ -# Blakely's basic shell setup file +#!/bin/sh +# Blakely's basic shell configuration 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 +# 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 +### Pre-setup >>> +# shellcheck disable=SC1090 # Helper function to source files. # Usage: # careful_source "file" \ @@ -19,7 +22,7 @@ careful_source() { ${5:-source} "$1" else if test -n "${2+foo}"; then - echo -e "$2" >&2 + printf "%s\n" "$2" >&2 echo "Line number: $3" >&2 fi fi @@ -33,7 +36,7 @@ error() { } # change cursor to a beam by default -echo -ne '\e[5 q' +printf '\e[5 q' ### <<< ### Generic shell configuration >>> @@ -58,18 +61,19 @@ ${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. +# 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. # # 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. +# 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). -# load all functions that are stored in files +# Function to load all functions that are stored in files fnupdate() { for FN in "$SHELL_CONFIG_DIR"/functions/*;do - source "$FN" + . "$FN" done } ${SKIP_FUNCTIONS:-false} || fnupdate @@ -77,13 +81,20 @@ ${SKIP_FUNCTIONS:-false} || fnupdate # <<< ### Options >>> set -o vi + # <<< + +# <<< +### Load the local shrc >>> +${SKIP_LOCAL_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/local/shrc" \ + # <<< ### 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 +# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3:ts=3