Skip to content

aaronmedina-dev/vscode-openworkspace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

[VS-OW] VSCode OpenWorkspace v1.0

Aaron Medina | GitHub | Linkedin

VSCode Workspace Selector

For developers who prefer to have Visual Studio Code focused on a single project at a time, this tool can be incredibly useful. It ensures that only files related to your current work are visible, avoiding distractions from unrelated projects. As you add new projects to the configured workspaces in the configuration file, the tool dynamically includes them as options, streamlining your workflow.

While there are extensions available for Visual Studio Code that provide robust project management features, this script offers a unique approach. By dynamically loading workspace configurations from a configuration file and listing all subdirectories in the configured workspaces, it ensures that only files related to your current work are visible. This minimizes distractions and keeps your focus on the task at hand.

Image

Features

  • Dynamically loads workspaces from a configuration file.
  • Lists all subdirectories in the configured workspaces, sorted by oldest-newest.
  • Provides a simple terminal-based selection interface.
  • Opens the selected folder in Visual Studio Code.

Prerequisites

  • Bash/Zsh: Ensure you have a Bash/Zsh shell environment available.
  • Visual Studio Code: Make sure VS Code is installed and available in your system's PATH.
  • Configuration File: A configuration file named vscode_openworkspaces.conf must be placed in the same directory as the script.

Configuration File Format

The configuration file should be in a JSON-like format. Each key-value pair represents a workspace name and its corresponding directory path.

{
  "Workspace Name": "~/path/to/workspace",
  "Another Workspace Name": "~/another/path"
}
  • Replace ~/path/to/workspace1 and ~/path/to/workspace2 with the absolute or relative paths to your workspace directories.
  • Use the tilde (~) to denote the home directory.

Usage

  1. Clone or copy the script to a directory of your choice.
  2. Ensure the script is executable:
    chmod +x vs-openworkspace.sh
  3. Add workspace/s to vscode_openworkspaces.conf
  4. Run the script from the terminal:
    ./vs-openworkspace.sh
  5. Follow the on-screen prompts to select a folder from the available options.
  6. The selected folder will be opened in Visual Studio Code.

Example Workflow

  1. The script will load the workspace configuration file and display the available folders:

    Select a folder from Workspace1 (/path/to/workspace1):
    [1] Project1
    [2] Project2
    
    Select a folder from Workspace2 (/path/to/workspace2):
    [3] ProjectA
    [4] ProjectB
    
  2. Enter the number corresponding to the folder you wish to open. For example, entering 2 will open Project2 in VS Code.

  3. The script validates your input and opens the selected folder:

    Opening folder: /path/to/workspace1/Project2 from workspace Workspace1
    

Error Handling

  • If the configuration file is missing or malformed, the script will terminate with an error message.
  • If no folders are found in the configured workspaces, the script will notify you and exit.
  • Invalid input during folder selection will prompt an appropriate error message and exit the script.

Customization

  • Colors: The script uses ANSI color codes to enhance readability. You can modify the color codes by changing the variables defined in the script (RED, GREEN, BLUE, etc.).
  • Workspace Configuration: Update vscode_openworkspaces.conf to add or modify workspaces.

Recommendation

Make this script easier to use:

  1. Make the script executable

  2. Create a wrapper function in your shell configuration file (~/.bashrc or ~/.zshrc) to call the script easily

  3. Use the script anywhere by typiing the command you used in your wrapper.

Troubleshooting

  • VS Code Command Not Found: Ensure code is available in your system PATH. Refer to VS Code documentation for instructions.
  • Directory Permissions: Verify that the script has read permissions for the workspace directories.

License

This script is distributed under the MIT License. Feel free to use, modify, and distribute it as needed.

About

VSCode Workspace Selector

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages