summaryrefslogtreecommitdiffstats
path: root/packaging/macos/jhb/usr/src/bash_d/echo.sh
blob: d160db0c4ba6f95063538a63b104685380f09a3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# SPDX-FileCopyrightText: 2021 René de Hesselle <dehesselle@web.de>
#
# SPDX-License-Identifier: GPL-2.0-or-later

### description ################################################################

# Provide colorful convenience functions for echo.

### shellcheck #################################################################

# shellcheck shell=bash # no shebang as this file is intended to be sourced

### includes ###################################################################

bash_d_include ansi

### variables ##################################################################

# Nothing here.

### functions ##################################################################

function echo_message__
{
  local funcname=$1   # empty if outside function
  local filename=$2
  local type=$3
  local color=$4
  local args=${*:5}

  if [ -z "$funcname" ] || [ "$funcname" = "source" ]; then
    funcname=$(basename "$filename")
  fi

  if ansi_is_usable; then
    echo -e "${color}$type:$ANSI_FG_RESET $args ${ANSI_FG_BLACK_BRIGHT}[$funcname]$ANSI_FG_RESET"
  else
    echo "$type: $args [$funcname]"
  fi
}

### aliases ####################################################################

alias echo_d='>&2 echo_message__ "$FUNCNAME" "${BASH_SOURCE[0]}" "debug" "$ANSI_FG_BLUE_BOLD"'
alias echo_e='>&2 echo_message__ "$FUNCNAME" "${BASH_SOURCE[0]}" "error" "$ANSI_FG_RED_BRIGHT"'
alias echo_i='>&2 echo_message__ "$FUNCNAME" "${BASH_SOURCE[0]}" "info" "$ANSI_FG_BLUE_BRIGHT"'
alias echo_o='>&2 echo_message__ "$FUNCNAME" "${BASH_SOURCE[0]}" "ok" "$ANSI_FG_GREEN_BRIGHT"'
alias echo_w='>&2 echo_message__ "$FUNCNAME" "${BASH_SOURCE[0]}" "warning" "$ANSI_FG_YELLOW_BRIGHT"'

### main #######################################################################

# Nothing here.