#!/usr/bin/env sh
# @(#)🏠📂 HOMEDIR	sh/with-default-path.sh	2026-04-05T19:49:50Z
# SPDX-FileCopyrightText: 2026 Lady <https://www.ladys.computer/about/#lady>
# SPDX-License-Identifier: MPL-2.0

## ⁌ With Default Path
##
## ∎ Copyright © 2026 Lady [@ Ladys Computer].
##
## ⋮ This Source Code Form is subject to the terms of the Mozilla
##   Public License, version 2.0.
## If a copy of the M·P·L was not distributed with this file, You can
##   obtain one at {🔗<https://mozilla.org/MPL/2.0/>}.

## § Description
##
## Some programs break with the `git´ customizations provided by this
##   repository, so it is important to reset the `PATH´ before calling
##   them.
## Symlinking such program names to this script provides the necessary
##   `PATH´ override.

set -o 'errexit'

## § Configuration
##
## The following variables provide hooks to override the commands used
##   by this script.

: "${cmd_BASENAME:=basename}"

## The program name defaults to the basename of the script as it is
##   called.
## This allows one to simply create a symlink of the appropriate name
##   to this script rather than needing to configure anything
##   explicitly.

defaultprogramname="$(
  "${cmd_BASENAME}" -- "$0"
)"
defaultprogram="$(
  command -pv "${defaultprogramname}"
)"
: "${cmd_PROGRAM:=${defaultprogram}}"

## § Implementation
##
## The implementation simply sets the `PATH´ appropriately (using the
##   builtin version of `getconf´) and then calls the program name.
## `${HOMEDIR}/.local/bin´ is added to the `PATH´ to provide a single
##   point of extensibility for user‐level modifications; it is
##   important that this not be used to override default
##   implementations in cases where continued access to the latter is
##   important.

PATH='${HOMEDIR}/.local/bin:'"$(
  command -p getconf PATH
)" "${cmd_PROGRAM}" "$@"
