diff --git a/src/functions/header.sh b/src/functions/header.sh index d1f1e9c..8182e87 100644 --- a/src/functions/header.sh +++ b/src/functions/header.sh @@ -1,6 +1,21 @@ wx-header(){ - wx-start + if [[ $2 == "h1" ]] + then + echo "==============================" + wx-repeat " " $((30/2-${#1}/2)) + echo -n "$wxBold" + echo -n "$1" + echo -n "$wxNormal" + echo "" + echo "==============================" + fi - echo ">> $1 <<" - echo "------------------------------" + if [[ $2 == "h2" || -z $2 ]] + then + wx-start + wx-repeat " " $((30/2-6/2-${#1}/2)) + echo -n ">> $1 <<" + echo "" + echo "------------------------------" + fi } diff --git a/src/functions/repeat.sh b/src/functions/repeat.sh new file mode 100644 index 0000000..45a6b85 --- /dev/null +++ b/src/functions/repeat.sh @@ -0,0 +1,5 @@ +wx-repeat() { + local str=$1 n=$2 spaces + printf -v spaces "%*s" $n " " + printf "%s" "${spaces// /$str}" +} diff --git a/src/functions/start.sh b/src/functions/start.sh index 6cc107a..17e21d7 100644 --- a/src/functions/start.sh +++ b/src/functions/start.sh @@ -2,11 +2,7 @@ wx-start(){ echo "" echo "" echo "" - echo "==============================" - echo -n "$wxBold" - echo " Warén CLI " - echo -n "$wxNormal" - echo "==============================" + wx-header "Warén CLI" h1 mkdir -p $HOME/.config/warengroup &> /dev/null diff --git a/wx b/wx index 53b7e21..3d0f63d 100755 --- a/wx +++ b/wx @@ -20,10 +20,31 @@ wxNormal=$(tput sgr0) declare -Ax config wx-header(){ - wx-start + if [[ $2 == "h1" ]] + then + echo "==============================" + wx-repeat " " $((30/2-${#1}/2)) + echo -n "$wxBold" + echo -n "$1" + echo -n "$wxNormal" + echo "" + echo "==============================" + fi - echo ">> $1 <<" - echo "------------------------------" + if [[ $2 == "h2" || -z $2 ]] + then + wx-start + wx-repeat " " $((30/2-6/2-${#1}/2)) + echo -n ">> $1 <<" + echo "" + echo "------------------------------" + fi +} + +wx-repeat() { + local str=$1 n=$2 spaces + printf -v spaces "%*s" $n " " + printf "%s" "${spaces// /$str}" } wx-restricted(){ @@ -41,11 +62,7 @@ wx-start(){ echo "" echo "" echo "" - echo "==============================" - echo -n "$wxBold" - echo " Warén CLI " - echo -n "$wxNormal" - echo "==============================" + wx-header "Warén CLI" h1 mkdir -p $HOME/.config/warengroup &> /dev/null