From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 15756269F3 for ; Tue, 14 May 2024 08:49:09 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1715669349; b=jfAN4pxQLPLu1Dm5fE+DJCdyR351G3lYMYUgwsuHs2yv8muvY8WRfx4GAVm4N23Rm599GEPAcm xRgrpSeunw4t92DRkjNvPGD90thEqKku1ZrBiMCJUNz4sxR2nDNNPgB94TXdxLVY45ORVDtfWr iBQAhnrrNNwcv8ScR3EnnWuDaBx+PBLE9YnjQPT2gYPWxYutt+jiD5ZouQ9ObQ2IDsIC5z10wR dVU4qUEkmYX2BqMc2zx0X8w95QilbdJx/pHDVBt57/KTss4wkJW8YH4DIIfpOJXZxtv3Ejn0Hu ux6CoFScRI+6HP2PE3a6yBVZypbG/YDBwMNIiUCjq6TYGA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1715669349; bh=BPyEUo604ySv8qk7naMPeOkme5rZ+Y5n7yG6F+mMxXg=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature; b=jDX9oubidiTA9Vv76XMH1uQ/yLi1uQW1wIhLx9K6Q4fv7deKWESGeoyatRVTvUZ4x7WXRk24TQ kOSXIm3StGRC+C4ErsfV2azh9jOVyPgw36/Z6YaCnQfLlqfTwQO8rbAYgNEqMWMWAuobswAYCo TqpbXlrPd1jNxZnTWymSccvbDDgoVEcn5dXNYoC2q0YRX+tui1zkewLxH0DMx/FnYG1QUNbzPO kdweRSVL7CQKSh1F1aHOFRry7RlpqCvz3O3HvGUnJKfwcpn6rH83OuWveQwK9EQKPioigmW4AS y1dI4TPQfP8hq0iV9DBHZkR3QE4UWEalkriB2A3QsqpZzg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=hYZD3eI/bKcFqAEQKhHgPzqQuVtGD+9tH610KqEV5u4=; b=VxBZPlbzXTcAcbaI/dvl6z6C+v bhLIcVn8qwqPqlftV7Py0+pCn45qHoFzjuI1jqUd60v0wrFqJF8ZivxPXNq8E32rESCWn0MpNfMVC Svp+RmD4Ldo/0hmJfN2NHHC6x7zjVGhUBqSFL4qZd15U/sI3mbREfHqtt3io5T+C2bIQU99+fUFna rzNR8BhyL/7mgMRxzMfCsn1FIMPCotDECdzdV+idkCkFMOgIcyIKlvQDPUYXdxHCARbEwCcodAunc 9miO/4Zd7VA2ihuT/udS6AfSFybvFhSyh9TEd6PtkYmko+htOw4VLcQAjE+C4U5D9y7PoSnV7uoru 478/a5JA==; Received: by zero.zsh.org with local id 1s6lyG-000CAy-5C; Tue, 14 May 2024 06:49:08 +0000 Authentication-Results: zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none Received: from relay9-d.mail.gandi.net ([217.70.183.199]:51469) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1s6lxN-000BUD-TT; Tue, 14 May 2024 06:48:14 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id DACA3FF807; Tue, 14 May 2024 06:48:11 +0000 (UTC) Date: Tue, 14 May 2024 07:48:11 +0100 From: Stephane Chazelas To: Roman Perepelitsa Cc: Mikael Magnusson , Kannan Varadhan , Zsh Users Subject: Re: colorizing printfs Message-ID: <20240514064811.7yhviseibxjj34nq@chazelas.org> Mail-Followup-To: Roman Perepelitsa , Mikael Magnusson , Kannan Varadhan , Zsh Users References: <8d1d947e-75af-4a9a-b726-dabe9858b2b0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-GND-Sasl: stephane@chazelas.org X-Seq: 29933 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 2024-05-11 16:37:03 +0200, Roman Perepelitsa: > On Sat, May 11, 2024 at 4:27 PM Mikael Magnusson wrote: > > > > On Sat, May 11, 2024 at 2:54 AM Kannan Varadhan wrote: > > > > > > > > > ~⦒printf '%s.%s.%s\n' "${(%):-%F{blue}%B}" "test" "${(%):-%b}${(%):-%f}" > > > %B}.test. > > > > You probably have a badly made / cargo culted precmd() function > > active. > > That output is actually expected. The right curly must be escaped. > > printf '%s.%s.%s\n' "${(%):-%F{blue\}%B}" "test" "${(%):-%b}${(%):-%f}" [...] Thanks, I've fixed https://unix.stackexchange.com/questions/408867/how-to-colorize-some-of-the-output-of-a-shell-script/408871#408871 (which was at the start of the discussion) accordingly. > Or, when printing $var: > > print -rP '%F{blue}%B'${var//\%/%%}'%b%f' [...] It should be noted (as I now have in my answer above) that that assumes the promptbang and promptsubst options are disabled and promptpercent is enabled, with possible dramatic effect if not (like when $var contains $(reboot) and promptsubst is enabled). -- Stephane