Skip to content

Commit

Permalink
Allow exportable global options in the context of sourced units
Browse files Browse the repository at this point in the history
Processed started from sourced units will now properly inherit the exported
value of XSH_DIR, XSH_CONFIG_DIR and XSH_RUNCOM_PREFIX, if any. The
previous use of `local` was shadowing the global value and preventing it
from being inherited by sub processes.
  • Loading branch information
sgleizes committed Nov 27, 2020
1 parent b5bd824 commit 8d561a0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions xsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ XSH_VERSION='0.1.0'
XSHELL="${ZSH_NAME:-${0##*/}}"
XSHELL="${XSHELL#-}" # remove leading '-' for login shells

# Set default values for exportable global options.
# This should not be set at the local xsh scope as it would shadow the exported
# global value, if any. This would prevent processes started from xsh units to
# properly inherit the global value.
XSH_DIR="${XSH_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/xsh}"
XSH_CONFIG_DIR="${XSH_CONFIG_DIR:-$XSH_DIR}"
XSH_RUNCOM_PREFIX="${XSH_RUNCOM_PREFIX:-@}"

# A simple framework for shell configuration management.
#
# Usage: xsh [options...] <command> [args...]
Expand Down Expand Up @@ -60,10 +68,7 @@ XSHELL="${XSHELL#-}" # remove leading '-' for login shells
# XSH_VERBOSE Enable logging the loaded units. If XSH_BENCHMARK is also set,
# the loading time for each unit is printed.
xsh() {
# Restrict changes to global options to local scope.
local XSH_DIR="${XSH_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/xsh}"
local XSH_CONFIG_DIR="${XSH_CONFIG_DIR:-$XSH_DIR}"
local XSH_RUNCOM_PREFIX="${XSH_RUNCOM_PREFIX:-@}"
# Restrict changes of unexportable global options to local scope.
local XSH_SHELLS="${XSH_SHELLS:-$XSHELL}"
local XSH_BENCHMARK="${XSH_BENCHMARK}"
local XSH_VERBOSE="${XSH_VERBOSE}"
Expand Down

0 comments on commit 8d561a0

Please sign in to comment.