Skip to content

Commit

Permalink
Merge pull request #2 from georglauterbach/update-bash-00-base
Browse files Browse the repository at this point in the history
Update `00-base.sh`
  • Loading branch information
georglauterbach authored Jul 3, 2024
2 parents f929ff0 + d63dda7 commit b41967a
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions data/unversioned/no_gui/data/home/.config/bash/00-base.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#! /usr/bin/env bash

# version 0.2.0
# version 0.3.0
# sourced by ${HOME}/.bashrc
# task set up functions required during setup

if ! type -t '__command_exists' &>/dev/null; then
function __is_bash_function() {
[[ $(type -t "${1:?Name of type to check is required}" || :) == 'function' ]]
}
export -f __is_bash_function

if ! __is_bash_function '__command_exists'; then
function __command_exists() {
command -v "${1:?Command name is required}" &>/dev/null
}
Expand All @@ -13,17 +18,6 @@ if ! type -t '__command_exists' &>/dev/null; then
export -f __command_exists
fi

function __is_bash_function() {
[[ $(type -t "${1:?Name of type to check is required}" || :) == 'function' ]]
}

function __hermes__declare_helpers() {
declare -f do_as_root \
__hermes__execute_real_command \
__command_exists \
__is_bash_function
}

function __hermes__execute_real_command() {
local COMMAND DIR FULL_COMMAND
COMMAND=${1:?Command name required}
Expand All @@ -37,11 +31,22 @@ function __hermes__execute_real_command() {
echo "Command '${COMMAND}' not found" >&2
return 1
}
export -f __hermes__execute_real_command

# shellcheck disable=SC2120
function __hermes__declare_helpers() {
local FUNCTIONS=('do_as_root' '__command_exists' '__is_bash_function' '__hermes__execute_real_command')
[[ ${#} -gt 0 ]] && FUNCTIONS+=("${@}")
declare -f "${FUNCTIONS[@]}"
}
export -f __hermes__declare_helpers

function do_as_root() {
local SU_COMMAND
local SU_COMMAND=${SU_COMMAND:-}

if __command_exists 'doas'; then
if [[ -n ${SU_COMMAND} ]]; then
:
elif __command_exists 'doas'; then
SU_COMMAND='doas'
elif __command_exists 'sudo'; then
SU_COMMAND='sudo'
Expand Down

0 comments on commit b41967a

Please sign in to comment.