From 08b943500eab5c02e0dfbc782bd43587e2f3034a Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 16 Jul 2026 18:09:19 +0400 Subject: [PATCH] fix prompt IFS --- bash.bashrc | 11 ++-- init.sh | 46 ++++++++++------ install.sh | 2 +- test/stub/extra/library.bash | 21 ++++++++ test/stub/script.bash | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 20 deletions(-) create mode 100755 test/stub/extra/library.bash create mode 100755 test/stub/script.bash diff --git a/bash.bashrc b/bash.bashrc index 071d195..c46853f 100644 --- a/bash.bashrc +++ b/bash.bashrc @@ -17,10 +17,13 @@ function __prompt_command { local PUSHED_NEEDED_SYMBOL='⥱' local TAG_NEEDED_SYMBOL='⤽' + local previous_IFS="$IFS" + # set xterm title echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" PS1='' + IFS=' ' if [[ -n ${container_hostname:-} ]]; then PS1+="${Gra}[LXC:${R}" @@ -111,7 +114,7 @@ function __prompt_command { fi PS1+=" $PROMPT ${R}" - + IFS="$previous_IFS" } function __vte_osc7 { @@ -221,9 +224,9 @@ alias l=ls alias cd..='cd ..' alias ..=cd.. -alias grep='grep $COLOR_OPTIONS' -alias fgrep='fgrep $COLOR_OPTIONS' -alias egrep='egrep $COLOR_OPTIONS' +alias grep='grep $COLOR_OPTIONS ' +alias fgrep='fgrep $COLOR_OPTIONS ' +alias egrep='egrep $COLOR_OPTIONS ' alias transfer_cp='rsync -a --info=progress2 --no-inc-recursive' diff --git a/init.sh b/init.sh index 563a503..254a2f2 100755 --- a/init.sh +++ b/init.sh @@ -1,23 +1,39 @@ #!/bin/bash -set -Eeuo pipefail +# CONSTANTS -[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 1 - -readonly OPT_MIAOU_DIR='/opt/miaou-bash' +MIAOU_BASH_DIR=${MIAOU_BASH_DIR:-/opt/miaou-bash} +ORIGINAL="ORIGINAL" +PREDEFINED_CONFIG_FILES=(/etc/bash.bashrc /etc/inputrc /etc/vim/vimrc) +readonly MIAOU_BASH_DIR ORIGINAL -#remove /etc/skel/.bashrc -if [ -e /etc/skel/.bashrc ]; then - rm /etc/skel/.bashrc -fi +# FUNCTIONS -readonly ORIGINAL="ORIGINAL" -declare -a arr=(/etc/bash.bashrc /etc/inputrc /etc/vim/vimrc) +function no_more_skeleton { + [[ -e /etc/skel/.bashrc ]] && rm /etc/skel/.bashrc && echo "skeleton .bashrc removed!" +} -for i in "${arr[@]}"; do +function predefine_config_files { + for i in "${PREDEFINED_CONFIG_FILES[@]}"; do if [[ -f "$i" ]] && [[ ! -f "$i.$ORIGINAL" ]]; then - mv "$i" "$i.$ORIGINAL" - basefile=$(basename "$i") - ln -s "$OPT_MIAOU_DIR/$basefile" "$i" + mv "$i" "$i.$ORIGINAL" + basefile=$(basename "$i") + ln -s "$MIAOU_BASH_DIR/$basefile" "$i" fi -done + done +} + +function bin_miaou_bash { + [[ ! -e /usr/bin/miaou-bash ]] && + ln -s "$MIAOU_BASH_DIR/bin/miaou-bash" /usr/bin/ && + echo "miaou-bash globally defined!" +} + +# MAIN + +set -TEeu -o pipefail +[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 1 + +no_more_skeleton +predefine_config_files +bin_miaou_bash diff --git a/install.sh b/install.sh index 40b882d..93e30e9 100755 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ ## CONSTANTS readonly CURDIR=$PWD -readonly REQUIRED_PKGS=(file git bc vim jq bat gum) +readonly REQUIRED_PKGS=(file git bc vim jq) readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" ## FUNCTIONS diff --git a/test/stub/extra/library.bash b/test/stub/extra/library.bash new file mode 100755 index 0000000..10430e4 --- /dev/null +++ b/test/stub/extra/library.bash @@ -0,0 +1,21 @@ +#!/usr/bin/env miaou-bash +#!/usr/bin/env bash + +function blabla { + echo IN blabla OUT + >&2 echo stderr from utility + # . lib/not_found_again.bash + # lib/not_found_again.bash + suite +} + +function suite { + command_not_found + echo $nope + exit 10 # youpi + return 7 + return + exit +} + +blabla diff --git a/test/stub/script.bash b/test/stub/script.bash new file mode 100755 index 0000000..0b726f7 --- /dev/null +++ b/test/stub/script.bash @@ -0,0 +1,102 @@ +#!/usr/bin/env miaou-bash + +# CONSTANTS + +BASEDIR=$(dirname "$0") +readonly BASEDIR + +# FUNCTIONS + +function F2 { + echo "stdout A" + # echo toto >>/tmp/toto + return + >&2 echo "This is stderr" + + blabla + $nope + exit 6 + grep titi toto + echo "stdout B" + echo "stdout C" + # command_not_found +} + +function F1 { + echo F1 + F2 +} + +function main { + F1 + F3 + echo before subshell + echo "here in subshell $(grep titi $0)" + echo NO MORE + + result=$(grep titi $0) + [[ "$result" -ne 0 ]] && echo true + # grep titi nope + >&2 echo some trace in stderr1 + "$BASEDIR/extra/library.bash" + . "$BASEDIR/lib/utility.bash" + # . not_found/not_found.bash + # echo "here in subshell $(grep titi nope)" + # ls -l nope + >&2 echo some trace in stderr2 +} + +function F3 { + echo F3 + return 0 +} + +function usage { + echo "USAGE: $0 " + echo -e "\trun case scenario which performs various bash statements and mostly fails" + echo -e "\tthese case scenarii helps testing the miaou-bash script" +} + +function do_success { + echo SUCCESS +} + +function do_unbound_variable { + a=5 + echo "a=${a}" + echo "b=${b}" +} + +function introspect_scenarii { + mapfile -t SCENARII <<<"$(compgen -A function | grep ^do_)" +} + +# MAIN +[[ $# -eq 0 ]] && >&2 echo 'arg1 expected!' && usage && exit 1 + +scenario="$1" +shift +mapfile -t scenarii <<<"$(compgen -A function | grep ^do_)" + +args=("$@") + +echo "scenarii = ${scenarii[@]}" +exit 0 + +echt "start of useless $0 $* ($# args)" +if grep titi nope 2>/dev/null; then + echo OK +else + echo not found but ok +fi +if grep titi "$BASEDIR/lib/utility.bash"; then + echo OK +else + echo not found but ok +fi +echo question?: +# read -r answer +# echo "$answer" +echo suite +main +echo end of useless