How can I keep using my WSL terminal after running `code .`?

0
5
Asked By MellowPine47 On

I'm following The Odin Project to learn web development and use Ubuntu through WSL. When I run `code .` to open Visual Studio Code, the terminal stays occupied instead of returning to the shell prompt, so I can't type another command until I close VS Code. Is there a way to open the editor without blocking the terminal?

2 Answers

Answered By CloudyMarble8 On

You can run `code . &` to start VS Code in the background and immediately get your shell prompt back. If you also want it to keep running after the terminal closes, use `code . & disown`. The `&` backgrounds the process, while `disown` removes it from the shell's job list.

MellowPine47 -

Thanks for explaining what those commands do. That makes a lot more sense now.

Answered By VividCactus23 On

VS Code has a built-in option for this: run `code --background .`. To make the normal `code` command behave this way, you can add an alias to your `.bashrc`: `alias code='code --background'`. Commands launched from a terminal normally keep the shell occupied until they exit, which is why VS Code blocks the prompt. The `--background` option tells VS Code to handle this itself. You can also use `-n` when you want to open a new window.

MellowPine47 -

I'll try the `--background` option. How do people usually learn these terminal options—mostly by using the terminal regularly and checking command documentation?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.