From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18822 invoked from network); 28 Nov 2021 10:00:31 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Nov 2021 10:00:31 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1638093631; b=oYSqCZK0/G+CtxukNN8k/uyvvW77vRLD/L1RoepaPeFlWIBUObC1f/vLgt4+n0jZ1QeY1d4K8k 6BKFk2x+DfvWt0Sl8EY3t91wF+gsruWxUM6HWhp3x8Y5QCkfn4pKfa0N1TAWKJssuiEjKV1pF+ Od1w1Wyj/IyGgD1S664LRZwZmz0IGIrJcGIbpIIv3iFdk2UAUCJKNcR4vgX4zyFWkOwOaHKszj F+24lEOqQKEfI24MwZ94cXbc/B5vPidUF14yrKKX6OQ9TMWt4kPKY/7brbiFST4UsexdBNYAl5 ZsjwkNd3AXrWE6fiW/nOKs1D6/+36kC2XV/zQMMAmeytfQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-qt1-f174.google.com) smtp.remote-ip=209.85.160.174; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1638093631; bh=hJ3Hem5jmsFVhDbbGzqDseojCcvAkvJtixXCOIWREgE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=P38r+k2aLSGettIfKigcVbFVCZkl8dULBqadEE/AOTQ+ay66R3lJ95OJzKX2jaqA6Ev8sSOUM+ yO+u0aBE4foYVXAldt2MgMEAefyUcGzd/P7q0fpI1NtF8OZNJ3uaM/noWIAm4UKkH9Npi529NI qQnl+zOlblQOvyb+OGLwzojpti44ODwHyREBUbATtjbEtuxyavm4z+2jnaYfs6bpfyom3vRKmA JizUpwtXnk0pvCteE8S/fB2awPx9o3G8jJzKWC3FwCxHWK3qJ/hNr87yVLjRbhcuy3T522J7EF daSI3auvU+9N0buOqPoQpAQnbwSzMVdg/706Hq/P54KRww==; 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:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=AEltfX8ko0Yl2pl5AvfsUsL4rHEzYgRN6p4gvKEufU4=; b=etWYoD6xpeBC+ymG27c3TUYcLe rCl0Ye2cDaWGmUfUX+4lQVeN0HhtAx0HxY561snNyahIq/DgGKMDvRvHGBG7efpVD7TOuphMKZ6CC frY0Tmk0TPyZQd7XuNIl5PKgFBCUnjg7rAhI+ky0hnwYtUa9KYSHPqctVT85i9vQ0GOU/gEqPti4r CoOnoKnKv5WuT9jWrU9fbnWzjekMq2TSvhW2sRqG+83DMVPwoHV7oDoYQORSbyOxasFvDh5T8VS5r YGJwcDZCF+YNMRiFlFSEPNpMZdenvDo7mD4fkovy6qhMcM7XC9OWW3mR/u4Meghbj2pWHPLI6Paz1 ZTsHayKg==; Received: from authenticated user by zero.zsh.org with local id 1mrGz0-0001Hi-T1; Sun, 28 Nov 2021 10:00:30 +0000 Authentication-Results: zsh.org; iprev=pass (mail-qt1-f174.google.com) smtp.remote-ip=209.85.160.174; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-qt1-f174.google.com ([209.85.160.174]:36820) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mrGyh-0000yR-6D; Sun, 28 Nov 2021 10:00:12 +0000 Received: by mail-qt1-f174.google.com with SMTP id t11so13381284qtw.3 for ; Sun, 28 Nov 2021 02:00:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=AEltfX8ko0Yl2pl5AvfsUsL4rHEzYgRN6p4gvKEufU4=; b=lAJMq3P2qCqqNTHKMl2g/0l7bX4whNtootuAv+X7AO6AYOq0Mc39NkZ9avB4bDhe7b t7QVlP6oJhhAAeT0Kv+hgy/P7q1aYnmW8UrBe1Vd8BCspsrEWKtI1QNYm8FYWTKLc82b QLRy+zhGFL3InOiLZj1i6P5epwuqySNpqf5CnBhaGcJR0vCuRxVNky8cZ/7a2KxEAGzf XU+zaghU4uZ2egyccx/TbNOl9agd22S35kAgksrD8YyfBcjgdXyNgszCAzPoDrDOz0vt hSFrOEc1tXa0ai2/f5ppVQ+nr4dz7YfWRaT2pUxOYyHrcv9TtdY1rZc9eGhvomyPzNgp cmNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=AEltfX8ko0Yl2pl5AvfsUsL4rHEzYgRN6p4gvKEufU4=; b=THf/LNPPxClgTG89K9EqC/w8tUmWPpcK2kwxI0SJClRXxBnolG+ualKPIlbVrYbiEm yVNykQ46d9WQzOk4AAGzYJ5nNsu5MzeYOTwMjJSOQ1sgAtN2zrq5w4kHgAING2Fu9oJ1 ldfEk6L/7rg+uIn/9JD2FOUUoT3BqbqxkBFrkvR7VU1X8MnW48llMU6E7IeOZxY4szuz 4LbcFQElNC9lING1Ayj7tNQ8+yF/lN+NwTxL8YJLwatFMSMBDbD/a65mXUUcQh7G5ELh 9hVsn0tdrLXUrYVgprQ471llRGxMYQc7BeIVigTZuEbjHePXbL0YaBX/kbnqA+/2MLZ1 Mb5A== X-Gm-Message-State: AOAM532XYHySV6Jo7vhGjM7wRP77BjJOr5zWfZAzmxl1IgrhkcOMmTWD eFKIDxijumlX2wf9VSCQl0/5OvjxoN6SmlkiqLQu/DyQ/uY= X-Google-Smtp-Source: ABdhPJxyxrgRvDE76kOzXbHAoZufO0/nHPvmjiANbsujNt4Em+ISCtw8/p+5+SwJLLvzkjd4yrDJ8YiibfWP/6l+x/k= X-Received: by 2002:ac8:44bc:: with SMTP id a28mr35672719qto.149.1638093609573; Sun, 28 Nov 2021 02:00:09 -0800 (PST) MIME-Version: 1.0 From: Roman Perepelitsa Date: Sun, 28 Nov 2021 10:59:58 +0100 Message-ID: Subject: Prompt expansion on signals To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 49608 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Consider the following user configuration: setopt prompt_subst my_var='%#' PS1='$my_var ' For this to work correctly, prompt_subst must be set when prompt is expanded. However, this requirement can be violated when prompt is expanded in a signal handler. One example where this happens is upon the completion of a background job. % sleep 1 & [1] 3566 % [1] + done sleep 1 % In this example all went well -- the job completed while zle was idle, so prompt got expanded with correct options. If the background job completes while zle is running a function, prompt gets expanded with the current options of the function. % zle-line-init() { emulate -LR zsh; while (($#jobstates)) : } % zle -N zle-line-init % sleep 1 & [1] 3592 % [1] + done sleep 1 $my_var Note "$my_var" as the last prompt instead of the expected "%". The same issue arises when the terminal is resized. Here prompt gets expanded on SIGWINCH with whatever options are in effect. % typeset -p LINES typeset -i10 LINES=46 % zle-line-init() { emulate -LR zsh; while ((LINES > 24)) =true } $my_var typeset -p LINES typeset -i10 LINES=22 Here I redefined zle-line-init while my terminal was 46 lines tall and then I resized it to 22 lines (more specifically, I split it). Note "$my_var" in prompt. Also note =true in the loop. It's needed because zsh postpones the processing of SIGWINCH until the next fork or until zle becomes idle. Here's an alternative way to trigger the same code without resizing the terminal: % zle-line-init() { emulate -LR zsh; LINES=0 } $my_var This approach is the easiest to test with. It appears that one is at risk of prompt expansion with incorrect options if both of the following conditions are met: 1. Using zle widgets that change options. Using zsh-syntax-highlighting (just to name a popular plugin) qualifies. 2. Using background jobs without nonotify or resizing the terminal. Many (most?) zsh users are affected. Prompt expansion can be affected by options other than prompt_*. For example: setopt prompt_subst ksh_arrays my_var=('%#') PS1='${my_var[0]} ' Expanding this prompt under `emulate -L zsh` (without -R) will produce incorrect results. Expanding prompt with incorrect options can be a minor nuisance (like in the examples above) or a major issue (when prompt is expanded with prompt_subst when it's not intended). Is there a solution for this problem that I'm missing? Are there workarounds? How could it be fixed? Roman.