sindresorhus / pure

Pretty, minimal and fast ZSH prompt
MIT License
13.21k stars 976 forks source link

Pure breaking ZSH sessions on login - `Saving session...` #664

Open ziadoz opened 12 months ago

ziadoz commented 12 months ago

General information

System report (output of prompt_pure_system_report):

- Zsh: zsh 5.8.1 (x86_64-apple-darwin21.0) (/bin/zsh)
- Operating system: macOS 12.7.1 (21G920)
- Terminal program: Apple_Terminal (445)
- Tmux: no
- Git: git version 2.37.1 (Apple Git-137.1)
- Pure state:
    - username: `''`
    - prompt: `❯`
    - version: `1.22.0`
- zsh-async version: `1.8.6`
- PROMPT: `typeset -g PROMPT=$'%F{${prompt_pure_colors[path]}}%~%f
%{
%}%(12V.%F{$prompt_pure_colors[virtualenv]}%12v%f .)%(?.%F{$prompt_pure_colors[prompt:success]}.%F{$prompt_pure_colors[prompt:error]})${prompt_pure_state[prompt]}%f '`
- Colors: `typeset -g -A prompt_pure_colors=( [execution_time]=yellow [git:action]=yellow [git:arrow]=cyan [git:branch]=242 [git:branch:cached]=red [git:dirty]=218 [git:stash]=cyan [host]=242 [path]=blue [prompt:continuation]=242 [prompt:error]=red [prompt:success]=magenta [suspended_jobs]=red [user]=242 [user:root]=default [virtualenv]=242 )`
- TERM: `export TERM=xterm-256color`
- Virtualenv: `export VIRTUAL_ENV_DISABLE_PROMPT=12`
- Conda: `export CONDA_CHANGEPS1=no`
- Detected frameworks: None

Other information

I have:

Problem description

Using the exec $SHELL -l command breaks ZSH's session files.

I've stripped my .zshrc down to only Homebrew and Pure. With Pure enabled the session file contains the text Saving session..., which causes a command not found: Saving error. If I comment out Pure this text does not leak into the session file and no errors occur.

Reproduction steps

  1. Install HomeBrew:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Pure:

    brew install pure
  3. Copy stripped back .zshrc below into ~/.

  4. Run login command:

    
    ❯ exec $SHELL -l

/Users/ziadoz/.zsh_sessions/F79A28F2-7FA9-40F8-83BA-728DD499E367.session:2: command not found: Saving


5. Inspect session file:

❯ cat /Users/ziadoz/.zsh_sessions/F79A28F2-7FA9-40F8-83BA-728DD499E367.session

Saving session...echo Restored session: "$(/bin/date -r 1701213053)"


Notice the text `Saving session...` has leaked into the session file. 

This text comes from `shell_session_save()` in `/etc/zshrc_Apple_Terminal`, but it only leaks into the session file when Pure is enabled. When Pure is commented out the session file does not contain this text and is restored without errors.

### My `.zshrc`:

<!--
Please provide a minimal `.zshrc` that reproduces the issue.
Try to remove everything that that does not affect the issue, the fewer lines, the better.

Example:

```shell

-->

eval "$(/usr/local/bin/brew shellenv)"

fpath+=("$(brew --prefix)/share/zsh/site-functions")
autoload -U promptinit; promptinit
prompt pure
zstyle :prompt:pure:git:stash show yes
ziadoz commented 8 months ago

Just a heads up that I'm still seeing this issue in macOS Sonoma 14.4 using the latest version of Pure (installed via Git instead of HomeBrew):

/Users/ziadoz/.zsh_sessions/B7F935A6-873B-479F-AE4D-3FE2C61B4BA2.session:2: command not found: Saving
mafredri commented 8 months ago

@ziadoz I'm not able to reproduce, have you checked your .zprofile, .zshenv, etc. as well? And that there aren't any changes in your global Zsh files (e.g. under /etc)?

ziadoz commented 8 months ago

@mafredri It's tricky to reproduce as it doesn't always happen since I switched to macOS Sonoma.

I've stripped my ~/.zshrc down to this:

fpath+=($HOME/.zsh/pure)
autoload -U promptinit; promptinit
prompt pure    
zstyle :prompt:pure:git:stash show yes

Then I open Terminal, run exec $SHELL -l, then CMD+Q quit Terminal, then reopen Terminal and repeat. Eventually when I open the shell I see the error:

❯ 
/Users/ziadoz/.zsh_sessions/B7F935A6-873B-479F-AE4D-3FE2C61B4BA2.session:2: command not found: Saving

~
❯ 

I'm not able to reproduce, have you checked your .zprofile, .zshenv, etc. as well? And that there aren't any changes in your global Zsh files (e.g. under /etc)?

I'm on a fresh install of macOS Sonoma, so nothing in /etc should have been changed.

My dotfiles configuration is here if that's any help: https://github.com/ziadoz/dotfiles/tree/master/zsh

ziadoz commented 7 months ago

I started my laptop up after having had it shut down for a few days, and Terminal started with this message, which I haven't seen before:

Last login: Wed Apr 17 08:12:33 on ttys000
/bin/date: option requires an argument -- r
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
            [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]
/Users/ziadoz/.zsh_sessions/B6417CEC-CB8A-4FBB-A3D1-3D04BCE380FA.session:2: command not found: Saving

❯ cat /Users/ziadoz/.zsh_sessions/B6417CEC-CB8A-4FBB-A3D1-3D04BCE380FA.session
echo Restored session: "$(/bin/date -r 1713337954)"