-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Support fish shell integration automatic injection #139400
Comments
Deferring to focus on polishing how shell integration works in general |
Final implementation details aside, fish's event handing will make at least some of this dead easy: # ~/.config/fish/conf.d/vscode-shellintegration.fish
function __vsc_esc # just a little helper
builtin printf "\e]633;%s\a" (string join ";" $argv)
end
function __vsc_cmd_before --on-event fish_preexec
__vsc_esc C
__vsc_esc E "$argv"
end
function __vsc_cmd_after --on-event fish_postexec
__vsc_esc D $status
end
function __vsc_update_cwd --on-event fish_prompt
__vsc_esc P "Cwd=$PWD"
end Some will be more difficult, at least to deploy auto-magically, because fish's prompts are the output of shell functions, not the contents of variables:
So to transparently preserve the user's original prompt, like the bash script does, would require modifying a shell function on-the-fly, not just a variable. Yikes. That said, I put the above code, plus the following, in my own config— # ~/.config/fish/conf.d/vscode-shellintegration.fish (cont'd.)
function __vsc_fish_prompt_before; __vsc_esc A; end
function __vsc_fish_prompt_after; __vsc_esc B; end
function __vsc_fish_rprompt_before; __vsc_esc H; end
function __vsc_fish_rprompt_after; __vsc_esc I; end
# ~/.config/fish/functions/fish_prompt.fish
function fish_prompt
__vsc_fish_prompt_before
# ...my existing code...
__vsc_fish_prompt_after
end
# ~/.config/fish/functions/fish_right_prompt.fish
function fish_right_prompt
__vsc_fish_rprompt_before
# ...my existing code...
__vsc_fish_rprompt_after
end —and I had all of VS Code's documented shell integration features working perfectly with VS Code v1.70.0 + fish 3.5.1. It's only a proof of concept, but hopefully this saves somebody a few web searches down the line, at least. :) |
@zgracem very handy info thanks! The bash script handles both PS1 and PRONPT_COMMAND, might be able to wrap the function automatically in a similar way? |
@Tyriar Well, fish doesn't have There is, alas, no event handler that runs after displaying the prompt but before accepting input (which is where you'd want FWIW, there's also no |
@zgracem ah I see, I think this stuff should still work though. We actually don't currently use some of these positions and the 633 E sequence kind of removes the need for them all together. So if there are limitations like this we can just take note for the future, like when finalizing the sequences this month. The limitations imposed on us by the Windows backend are much more frustrating to deal with than this sounds 🥲 If you want to put a PR out with just the script as a starting point (just the script) we could then give it a try and see if we can get it in as an experimental thing. I guess just manually installing until it's considered stable, plus the automatic injection was a handful for the other shells. You could also move the 633 A to just after 633 D, I'd expect that to work fine. |
I've been wanting to do this since last month, and @zgracem's comment finally motivated me to put up a fish plugin here: https://github.com/kidonng/vscode.fish
The trick I have seen in kitty's automatic shell integration is that they wait for a |
Also thanks to a PR from @babakks, the fish history file is now loaded so run recent command pulls from it when fish is active 🎉 #156058 |
@zgracem that would be fantastic 👍 |
IE my expectation was after undoing manual injection, it would work automatically. That wasn't the case. |
@roblourens since it's working for @meganrogge and I we'll close this and include it in the release notes. It would be good to get to the bottom of your issue, we can track that in another issue? We can have a call to investigate when you're free if that works. |
Sure, call any time |
Not really, sorry. Maybe the snap packaging interferes somehow? @roblourens From your shell session, are |
We investigated, it ended up being the fish version being too old. After the update it worked great! Thanks for all the help @mkhl |
This isn't working for me in 1.79.0 (non-insider), as far as I can see the fish config is there but XDG_DATA_DIRS isn't getting set. And looking at the code I found #184364 -- what happened? |
Looking at the configuration files order documentation again I believe this would happen when something we need, like The Maybe instead we could invoke fish with If I have the spoons and noone beats me to it I'll try to whip up a PR for that next week. |
One way to make sure something runs after the user's function init_vscode_shell_integration --on-event fish_prompt
# Run only once
functions --erase init_vscode_shell_integration
# Do the magic here...
end This can be placed in the appropriate vendor-config directory as simply (e.g.) |
@zgracem I tried something like that thanks to your suggestion. It's not working atm and not sure why... lmk if you see what could be wrong here https://github.com/microsoft/vscode/compare/merogge/fish-s?expand=1 |
@meganrogge I think you also need to add Lines 102 to 105 in 843cf0a
|
Removing verification-needed as this was covered by a test plan item. |
Parent issue #133084
Update: Activate the fish shell integration by following these instructions: https://code.visualstudio.com/docs/terminal/shell-integration#_manual-installation
We're keeping this open until automatic injection is looked into.
The text was updated successfully, but these errors were encountered: