+6

A Simple CLI for Managing VSCode Workspaces

One common bad practice when using Visual Studio Code (VSCode) is installing all extensions globally, which can make VSCode run more slowly and become resource-intensive. The workspace feature helps mitigate this by allowing you to create workspace-specific settings, such as enabling extensions only for a particular workspace. This keeps your development environment lightweight and tailored to each project.

To make managing workspaces even easier, I'd like to introduce ws—a lightweight command-line interface (CLI) that allows you to quickly list and open VSCode workspaces with ease. Using the ws CLI, you can now open a VSCode workspace directly from the terminal.

Key Features

  • Quick Listing of Workspaces: The ws command instantly lists all available workspace files in the current directory, making it easy to see all your options at a glance.
  • Simple Workspace Opening: By simply providing the name of a workspace file, ws will launch it directly in VSCode.
  • Multi-platform Support: The CLI can work across different operating systems, including macOS, Linux, and Windows.

Installation

Option 1: Using Homebrew

For users who prefer using Homebrew, installing ws is as simple as running the following command:

brew install phe-lab/tap/ws

Option 2: Installing via Go

If you have a Go environment set up, you can install ws by using the following command:

go get -u -v github.com/phe-lab/ws

Both methods will install the ws CLI tool, making it readily accessible from your terminal.

Option 3: Using pre-built binaries

If you prefer not to use Homebrew or Go, you can download the appropriate binary for your operating system (e.g., Linux, macOS, or Windows) directly from the releases page.

Usage

Once installed, using ws is straightforward. Here are some common use cases:

Listing Workspaces

Simply run the ws command without any arguments to list all available VSCode workspace files:

ws

This will display all .code-workspace files found in ~/code-workspaces directory. To change the default directory, define an environment variable called VSCODE_WS_PATH:

export VSCODE_WS_PATH=~/workspaces

Opening a Workspace

To open a specific workspace, pass the filename of the workspace as an argument:

ws simple-scrollspy

In this example, the workspace file ~/code-workspaces/simple-scrollspy.code-workspace will be launched in VSCode.

Debug Mode

For debugging or additional insights into what the CLI is doing, you can enable logging by setting the --debug flag:

ws --debug

This flag provides more detailed logs that can help troubleshoot any issues.

Conclusion

The ws CLI is a handy utility designed for developers who regularly work with multiple VSCode workspaces. It simplifies the process of managing and switching between projects, allowing you to focus on writing code rather than hunting for workspace files. Whether you prefer installing via Homebrew or Go, ws offers a quick and easy solution for boosting your productivity in VSCode.

Give ws a try today and streamline your workspace management!

If you find ws useful, don’t forget to give it a ⭐️ on GitHub! Your support helps improve the tool and motivates further development.


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí