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

0
2
Asked By MellowCedar47 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 command keeps control of the terminal, so I don't get the shell prompt back until I close VS Code. Is there a way to launch it without blocking the terminal?

2 Answers

Answered By QuietMaple31 On

VS Code has its own option for this: `code --background`. You can make that the default by adding `alias code='code --background'` to your `.bashrc`. You can also use `code -n` when you want the command to open a new window. In general, commands keep the terminal occupied while they're running, so long-running programs either need a background operator like `&` or a command-line option that handles background execution.

MellowCedar47 -

Thanks! I'll try the alias. How do people usually learn these terminal options—mostly by using the terminal regularly and checking command documentation when something behaves unexpectedly?

Answered By PixelHarbor8 On

Run `code . &` to start VS Code in the background and immediately return to the shell prompt. 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.

CobaltWren52 -

That makes sense—the ampersand lets the shell and VS Code run separately, while `disown` prevents the terminal from taking responsibility for the editor after it closes.

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.