Annotation of pkgsrc/mk/scripts/echo-msg, revision 1.1
1.1 ! kim 1: #!/bin/sh
! 2: # $NetBSD$
! 3: #
! 4: # Print a pkgsrc status message and show phase messages as the terminal
! 5: # title. With SMART_MESSAGES defined, phase messages carry the make target
! 6: # and the stack of packages being built (see _PKGSRC_IN in bsd.pkg.mk):
! 7: #
! 8: # ===> target [pkg dep ...] ===> message
! 9: #
! 10: # When the title can be set, the stack becomes the title and only
! 11: # "===> message" is printed. Otherwise the message is printed unchanged.
! 12: #
! 13: # To use it, add to /etc/mk.conf:
! 14: #
! 15: # ECHO_MSG= ${PKGSRCDIR}/mk/scripts/echo-msg
! 16: # SMART_MESSAGES= yes
! 17: #
! 18: # Copyright (c) 2026 The NetBSD Foundation, Inc.
! 19: # All rights reserved.
! 20: #
! 21: # This code is derived from software contributed to The NetBSD Foundation
! 22: # by Kimmo Suominen.
! 23: #
! 24: # Redistribution and use in source and binary forms, with or without
! 25: # modification, are permitted provided that the following conditions
! 26: # are met:
! 27: # 1. Redistributions of source code must retain the above copyright
! 28: # notice, this list of conditions and the following disclaimer.
! 29: # 2. Redistributions in binary form must reproduce the above copyright
! 30: # notice, this list of conditions and the following disclaimer in the
! 31: # documentation and/or other materials provided with the distribution.
! 32: #
! 33: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 34: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 35: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 36: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
! 37: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 38: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 39: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 40: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 41: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 42: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 43: # POSSIBILITY OF SUCH DAMAGE.
! 44:
! 45: set -u
! 46:
! 47: PATH=/bin:/usr/bin
! 48: export PATH
! 49:
! 50: PROG="${0##*/}"
! 51:
! 52: usage()
! 53: {
! 54: cat <<-USAGE
! 55: Usage: ${PROG} [message ...]
! 56:
! 57: Print the message like echo(1). When standard output is a
! 58: terminal, also show phase ("===>") messages as the tmux pane
! 59: or terminal title. With SMART_MESSAGES, the title shows the
! 60: stack of packages being built, and the target and stack are
! 61: left out of the printed message. Other messages leave the
! 62: title alone.
! 63:
! 64: Options:
! 65: -h Show this help
! 66: USAGE
! 67: }
! 68:
! 69: # Print the title escape for this terminal; fail if it has none.
! 70: set_title()
! 71: {
! 72: case "${TERM-}" in
! 73: tmux*|xterm*)
! 74: printf '\033]0;%s\007' "${1}"
! 75: ;;
! 76: screen*)
! 77: if [ -n "${TMUX-}" ]
! 78: then
! 79: printf '\033]0;%s\007' "${1}"
! 80: else
! 81: printf '\033k%s\033\\' "${1}"
! 82: fi
! 83: ;;
! 84: *)
! 85: return 1
! 86: ;;
! 87: esac
! 88: }
! 89:
! 90: case "${1-}" in
! 91: -h) usage; exit 0;;
! 92: esac
! 93:
! 94: msg="${*}"
! 95:
! 96: if [ -t 1 ]
! 97: then
! 98: case "${msg}" in
! 99: "===> "*" ["*"] ===>"*)
! 100: title="${msg#*"["}"
! 101: title="${title%%"]"*}"
! 102: if [ -n "${title}" ] && set_title "${title}"
! 103: then
! 104: msg="${msg#*"] "}"
! 105: fi
! 106: ;;
! 107: "===>"*)
! 108: title="${msg#"${msg%%[!=> ]*}"}"
! 109: if [ -n "${title}" ]
! 110: then
! 111: set_title "${title}" || :
! 112: fi
! 113: ;;
! 114: esac
! 115: fi
! 116:
! 117: printf '%s\n' "${msg}"
! 118: exit 0
CVSweb <webmaster@jp.NetBSD.org>