Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 00-base.sh #2

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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