grezzo/grezzo.sh

41 lines
938 B
Bash
Executable File

#! /bin/bash --
[ ! -z "${GREZZO_MAIN}" ] && return; GREZZO_MAIN=0
function this_script_path() {
unset CDPATH
echo "$(cd "$(dirname "$(readlink -f -- "${BASH_SOURCE[1]}")")" > /dev/null && pwd -P)"
}
function feat_bashrc_before_needed() {
local bashrc="$HOME/.bashrc"
local include_line='. "$HOME/.bashrc.before"'
if [ ! -f "$bashrc" ]; then
printf 'HOME="%s"\n%s\n' "$HOME" "$include_line" > "$bashrc"
return
fi
if grep -Fqs "$include_line" "$bashrc" || grep -Fqs "$HOME/.bashrc.before" "$bashrc"; then
return
fi
{
printf 'HOME="%s"\n%s\n' "$HOME" "$include_line"
cat "$bashrc"
} > "$bashrc.tmp"
mv "$bashrc.tmp" "$bashrc"
}
function feat_missing() {
! command -v "$1" >/dev/null 2>&1
}
function feat_needed() {
FEAT="$1"
if feat_missing "$FEAT"; then
if type "feat_add_$FEAT" >/dev/null 2>&1; then
eval "feat_add_$FEAT"
else
echo "Missing function: feat_add_$FEAT" >&2
return 1
fi
fi
}