Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jump_to_prompt feature is defeated by switching shells #255

Closed
andrewrk opened this issue Aug 8, 2023 · 15 comments
Closed

jump_to_prompt feature is defeated by switching shells #255

andrewrk opened this issue Aug 8, 2023 · 15 comments

Comments

@andrewrk
Copy link
Collaborator

andrewrk commented Aug 8, 2023

Here's an example terminal session:

andy@ark ~> cd dev/zig
andy@ark ~/d/zig (master)> nix-shell ~/env/zig-no-llvm.nix

[nix-shell:~/dev/zig]$ cd build-release/

[nix-shell:~/dev/zig/build-release]$ git pul^C

[nix-shell:~/dev/zig/build-release]$ p
p: command not found

[nix-shell:~/dev/zig/build-release]$ gp
remote: Enumerating objects: 89, done.
remote: Counting objects: 100% (88/88), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 89 (delta 37), reused 72 (delta 31), pack-reused 1
Unpacking objects: 100% (89/89), 573.16 KiB | 2.28 MiB/s, done.
From github.com:ziglang/zig
   f3fbdf2b4..ac95cfe44  master     -> origin/master
Updating f3fbdf2b4..ac95cfe44
Fast-forward
 lib/docs/commonmark.js                                      |  15 +
 lib/docs/index.html                                         | 220 ++++---
 lib/docs/main.js                                            | 829 +++++++++++++++++++-------
 lib/std/child_process.zig                                   |   2 -
 lib/std/coff.zig                                            |   3 -
 lib/std/debug.zig                                           |   2 -
 lib/std/dwarf.zig                                           |   1 -
 lib/std/dynamic_library.zig                                 |   2 -
 lib/std/elf.zig                                             |   3 -
 lib/std/fifo.zig                                            |   3 +-
 lib/std/hash_map.zig                                        |   3 +-
 lib/std/heap.zig                                            |   1 -
 lib/std/os.zig                                              |   3 -
 lib/std/std.zig                                             |  79 +++
 src/codegen/c.zig                                           |   8 +-
 src/codegen/llvm.zig                                        | 216 +++----
 src/codegen/llvm/Builder.zig                                | 199 +++++++
 src/codegen/llvm/bindings.zig                               |  57 ++
 src/value.zig                                               |   1 -
 src/zig_llvm.cpp                                            | 100 ++++
 src/zig_llvm.h                                              |  23 +
 test/behavior/bugs/6305.zig                                 |  10 +
 test/behavior/cast.zig                                      |  23 +
 .../compile_errors/comptime_dereference_slice_of_struct.zig |  13 +
 24 files changed, 1365 insertions(+), 451 deletions(-)
 create mode 100644 test/behavior/bugs/6305.zig
 create mode 100644 test/cases/compile_errors/comptime_dereference_slice_of_struct.zig

[nix-shell:~/dev/zig/build-release]$ touch ../CMakeLists.txt && time ninja install && time stage3/bin/zig build -p stage4 -Dno-lib -Denable-llvm
[0/1] Re-running CMake...
-- Configuring zig version 0.12.0-dev.21+ac95cfe44
-- Configuring done
-- Generating done
-- Build files have been written to: /home/andy/dev/zig/build-release
[8/9] Install the project...
-- Install configuration: "Release"

real   13m31.446s
user   14m11.838s
sys    0m5.866s

real   1m36.669s
user   1m36.890s
sys    0m3.863s

[nix-shell:~/dev/zig/build-release]$

This is my most common workflow; I prefer fish but I use nix-shell a lot so I'm unfortunately hanging out in bash all day.

Anyway if I do jump_to_prompt:-1 here, it goes all the way up to the last fish prompt (line 2), rather than the last actual command prompt (in bash).

@mitchellh
Copy link
Contributor

Yes, this is expected. Ghostty does quite a lot of hoop jumping (same as Kitty) to setup shell integration and it doesn't persist into sub-shells (same as Kitty) unless you manually setup the shell integration there through dotfiles. Is there another terminal this does work with? Or are you used to just using the search-backwards functionality that Ghostty doesn't yet provide?

@andrewrk
Copy link
Collaborator Author

andrewrk commented Aug 8, 2023

The workflow that ghostty is competing with for me personally is described in #227 which is pretty awful, but actually better than what ghostty offers currently. Neither shift+page up/down to scroll works in ghostty, nor does it have a "find previous text" feature.

I don't use kitty other than to run bork.

I feel like this is one of those things where if you are a new user, it blows your mind how shitty the user experience is, but as you dig into it and become an expert on implementing a terminal and have to grapple with all the legacy garbage that the previous generation handed you, you lose that perspective and the limitation starts to become acceptable to you.

IMO the beginner perspective is valuable here. If I had to do the same workaround in ghostty as I do in xfce4-terminal, I would be sad about that.

edit: note that this also affects ssh sessions, regardless of which shell is being used remotely.

@mitchellh
Copy link
Contributor

Ah, after re-reading #227 I've opened #259. I think I can knock that out really quickly, that seems like obviously a good thing. I misunderstood or missed that completely on first read. And like I said, the "find previous text" is #189 and in-progress.

@mitchellh
Copy link
Contributor

I'm otherwise unsure if this issue itself is actionable. I think I described in Discord what the fundamental issues are regarding jump to prompt and requiring shell integration. Ghostty just can't detect that you're launching into another shell. Thoughts?

@andrewrk
Copy link
Collaborator Author

andrewrk commented Aug 9, 2023

ghostty is the parent process, so it can technically do anything, including editing the executable code of any child process, including bash, or replacing a process with its own puppet one, or even just setting LD_LIBRARY_PATH and thereby injecting code into some bash functions. There is also social pressure that could be put on third party projects. I think the question is, what lengths are you willing to go to? I think it would be fair to call this issue out of scope but it's definitely doable if you decide it's important enough. Aren't many of the fancy features planned going to depend on knowing where one prompt begins and another ends? Are nix users just shit out of luck with this terminal because of some esoteric complication having to do with the way shells work?

@mitchellh
Copy link
Contributor

mitchellh commented Aug 17, 2023

Alright, I think I have a not-automatic-yet half-step that also isn't that bad. It only requires manual setup once and then all your nix shells will work. I've ported the Kitty bash shell integration: https://github.com/mitchellh/ghostty/blob/main/src/shell-integration/bash/ghostty.bash

All you have to do is add this to your bashrc or bash_profile file. THIS MUST BE ADDED TO THE BOTTOM! It has to be the last thing that runs.

if [ -n "$GHOSTTY_RESOURCES_DIR" ]; then
    builtin source "${GHOSTTY_RESOURCES_DIR}/shell-integration/bash/ghostty.bash"
fi

You do NOT need to manually define GHOSTTY_RESOURCES_DIR. Following the automatic setup PRs earlier, Ghostty sets this for its launched process automatically. The if statement is there to make sure you only run the Ghostty setup if you're actually running in Ghostty, so it doesn't conflict with other terminal emulators.

Now all your nix-shell and so on will work (as long as you do not use nix-shell --pure).

@andrewrk
Copy link
Collaborator Author

I put that snippet at the top of my ~/.bashrc, updated ghostty to fe1e879, and restarted all instances of ghostty. When I activate the jump_to_prompt action, I see the same behavior as before: it jumps between the fish command prompts, but ignores the nix-shell bash prompts.

@mitchellh
Copy link
Contributor

Hm, maybe the bash integration is sending the marks. I'll take a look. I admittedly didn't test jump to prompt, I only tested that cwd reporting, title changes, and cursor changes were working.

@mitchellh
Copy link
Contributor

mitchellh commented Aug 18, 2023

Just tested it and it works for me but is kind of broken in nix-shell for reasons unknown (it just jumps to prompts a few lines off). This is definitely some shell prompt (PS0/1) issue but bash is so dense... 😠 Outside of nix-shell its accurate. My guess is that nix-shell is running some setup code first before our integration can run... or just really messing up the PS variables.

@andrewrk
Copy link
Collaborator Author

I am unable to reproduce the jump_to_prompt feature working with bash (nix-shell no longer in the equation). What can I do to troubleshoot?

@mitchellh
Copy link
Contributor

I'm going to try to simplify the bash integration because I just ported Kitty's and don't understand it at all. And I'm being punished for that. I think I need to really dig in and think about this for a sec.

@mitchellh
Copy link
Contributor

mitchellh commented Aug 18, 2023

Okay, I've dramatically simplified the bash script and actually understand wtf is going on. It works much better for me in nix-shell. Can you give it a shot? https://github.com/mitchellh/ghostty/blob/main/src/shell-integration/bash/ghostty.bash

Ironically, this now needs to be included last. lol. Same snippet. (Edited previous comment to also note the snippet needs to be at the bottom)

@andrewrk
Copy link
Collaborator Author

lmfao

@andrewrk
Copy link
Collaborator Author

It works! And wow, this is a game changer. Thank you so much!

@mitchellh
Copy link
Contributor

🫡

I'm going to close this issue for now. I'd still love to investigate fancier ways to automate this but I think there is a decent answer here for most shells, and this issue also forced me to write some garbage bash which will help people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants