Browse Source

no more stderr

main
pvincent 3 weeks ago
parent
commit
3abbfd976a
  1. 3
      bin/miaou-bash
  2. 7
      etc/bash.bashrc
  3. 4
      etc/profile.d/20-miaou-bash.sh
  4. 5
      install.sh
  5. 13
      lib/initiate.bash
  6. 13
      lib/self-upgrade.bash
  7. 14
      test/miaou-bash.test.bash
  8. 1
      test/stub/ansi_error.bash
  9. 2
      tools/pkg_add

3
bin/miaou-bash

@ -641,6 +641,7 @@ function parse_options {
builtin exit
;;
--initiate)
#TODO: remove, self_upgrade does it anyway
initiate
builtin exit
;;
@ -694,7 +695,7 @@ else
[[ -t 2 ]] && MAIN_FD_STDERR=false || MAIN_FD_STDERR=true
exec 4>/dev/tty
fi
exec 3>/dev/stderr 2>"$MIAOU_BASH_ERROR"
exec 3>&2 2>"$MIAOU_BASH_ERROR"
miaou_debug "<main file=$BASH_ARGV0 pid=${BASHPID}/>"
fi

7
etc/bash.bashrc

@ -152,8 +152,8 @@ function __vte_urlencode {
### MAIN
###------
MIAOU_BASH_DIR=/opt/miaou-bash
export MIAOU_BASH_DIR
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
## Add path for TOOLBOX if any
[[ -d "/TOOLBOX" ]] && PATH=$PATH:/TOOLBOX || true
@ -161,9 +161,6 @@ export MIAOU_BASH_DIR
# Add path to any tools folder in /opt/miaou-*
for i in {/opt,$HOME}/miaou-*/tools; do [[ -d "$i" ]] && PATH=$PATH:$i; done || true
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
HOSTNAME=$(hostname -f)
# don't put duplicate lines or lines starting with space in the history.

4
etc/profile.d/20-miaou-bash.sh

@ -0,0 +1,4 @@
MIAOU_BASH_DIR=/opt/miaou-bash
export MIAOU_BASH_DIR
PATH=$PATH:$MIAOU_BASH_DIR/bin

5
install.sh

@ -2,7 +2,6 @@
## CONSTANTS
MIAOU_BASH_DIR=/opt/miaou-bash
MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz"
## FUNCTIONS
@ -27,7 +26,11 @@ deployment_type_adjective="${1:-installed}"
[[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1
! assert_supported_distro && echo 'unsupported distro: debian-like OR arch-like expected' && exit 2
if [[ ! -v MIAOU_BASH_DIR ]]; then
MIAOU_BASH_DIR=/opt/miaou-bash
export MIAOU_BASH_DIR
fi
if [[ -d "$MIAOU_BASH_DIR" && -L /etc/inputrc && "$(readlink /etc/inputrc)" == "$MIAOU_BASH_DIR"/etc/inputrc ]]; then
. "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR/lib/self-upgrade.bash"
else

13
lib/initiate.bash

@ -68,8 +68,16 @@ EOF
fi
}
function is_arch_like {
[[ "$DISTRO_LIKE" == 'arch' ]]
}
function is_debian_like {
[[ "$DISTRO_LIKE" == 'debian' ]]
}
function link_config_files {
[[ "$DISTRO_LIKE" == 'arch' ]] && arch_vimrc
is_arch_like && arch_vimrc
link_etc vimrc.core vim
link_etc vimrc.miaou vim
@ -81,6 +89,7 @@ function link_config_files {
else
link_etc vimrc.local vim
fi
link_etc 20-miaou-bash.sh profile.d
link_etc bash.bashrc
link_etc inputrc # last command required to detect successful installation
}
@ -157,7 +166,7 @@ function ghostty_global_config {
source "$MIAOU_BASH_DIR/lib/functions.bash"
assert_root
usr_bin_miaou_bash
DISTRO_LIKE=$(fetch_distro_like)
install_required_packages
rm_bashrc_skeleton

13
lib/self-upgrade.bash

@ -2,21 +2,19 @@
# CONSTANTS
[[ ! -v MAIN_TAR_GZ_URL ]] &&
readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz"
# FUNCTIONS
function self_upgrade {
mv "$MIAOU_BASH_DIR" "$MIAOU_BASH_DIR".before_upgrade
if "$MIAOU_BASH_DIR".before_upgrade/install.sh upgraded; then
rm -rf "$MIAOU_BASH_DIR".before_upgrade
local backup="$MIAOU_BASH_DIR".before_upgrade
mv "$MIAOU_BASH_DIR" "$backup"
if "$backup"/install.sh upgraded; then
rm -rf "$backup"
echo -n "version: "
. "$MIAOU_BASH_DIR"/bin/miaou-bash --version
else
echo "ERROR: trouble during self-upgrade: revert back"
rm -rf "$MIAOU_BASH_DIR"
mv "$MIAOU_BASH_DIR".before_upgrade "$MIAOU_BASH_DIR"
mv "$backup" "$MIAOU_BASH_DIR"
fi
}
@ -29,6 +27,7 @@ assert_root
current=$(miaou-bash --version)
latest=$("$MIAOU_BASH_DIR/tools/wget_semver" artcode miaou/miaou-bash)
if [[ "$current" == "$latest" ]]; then
. "$MIAOU_BASH_DIR"/bin/miaou-bash --initiate
echo "up-to-date version: $current"
else
self_upgrade

14
test/miaou-bash.test.bash

@ -10,6 +10,17 @@ readonly TMP_DIRECTORY TMP_OUT TMP_ERR TMP_MIAOU
# functions
function assert_stderr {
((test_count++))
if [[ -w /dev/stderr ]]; then
echo -n .
return
fi
echo -n F
failures+=("test -w /dev/stderr")
return 1
}
function assert {
((test_count++))
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1"
@ -113,7 +124,6 @@ function fail_miaou_count {
local regex count="$2"
cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1"
# mapfile -t stderr <<<"$(miaou-bash ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)"
if ! $cmd >/dev/null 2>/dev/null 3>"$TMP_MIAOU"; then
mapfile -t miaou <"$TMP_MIAOU"
if [[ "${#miaou[@]}" == "$count" ]]; then
@ -138,6 +148,8 @@ mkdir -p "$TMP_DIRECTORY"
TIMEFORMAT=$'\nelapsed: %Rs'
time {
assert_stderr
assert success
assert exit_0
assert return_conditional

1
test/stub/ansi_error.bash

@ -53,7 +53,6 @@ function show_error {
>&2 printf '\r'
>&2 ansi_block_error "$failure_type" "$failure_payload" "$code"
>&2 ansi_traces stack_sources stack_lines stack_functions
# [[ -p /dev/stdout ]] && kill -TERM $$
}
function echo_return {

2
tools/pkg_add

@ -2,8 +2,6 @@
# CONSTANTS
[[ ! -v MIAOU_BASH_DIR ]] && readonly MIAOU_BASH_DIR=/opt/miaou-bash && export MIAOU_BASH_DIR
# functions
function usage {

Loading…
Cancel
Save