skip to Main Content

I messed up and deleted an extension I shouldn’t have uninstalled but like uninstalled extensions are all still in the folder and I don’t wanna manually install back everything I uninstalled so is there a way to just install everything

I tried many commands to get the extensions and install them but that only got already installed extensions code –list-extensions –show-versions > extensions4.txt
and then i tried just getting all the folder names but the format needs to be {name}@{version} for installing but the folders arent named accordingly so like idk what to do they are so many and i dont know how to (on windows)

2

Answers


  1. Chosen as BEST ANSWER

    Windows(CMD) Kinda buggy and some extensions fail to install

    go to the extensions folder for vs code

    open it

    open command prompt and cd into the extensions folder

    run this command

    dir "C:Users%USERPROFILE%.vscodeextensions" /b > extensions.txt
    

    you will get a file with all the sub folders in the folder but the names will have this format {name}-{version} and we need {name}@{version} to install things properly so we need to use this python script

    with open("C:\Users\%USERPROFILE%\.vscode\extensions\extensions.txt", "r") as f:
        filenames = f.readlines()
    
    for filename in filenames:
        filename = filename.strip()  # Remove newline character at the end of the line
        name_parts = filename.split('-')  # Split the filename by the dash character
        version_index = None
        for i, part in enumerate(name_parts):
            if part[0].isdigit():  # Check if the first character of the part is a digit
                version_index = i  # Save the index of the part that contains the version number
                break  # Stop looking for the version number
        if version_index is not None:
            name_parts[version_index] = '@' + name_parts[version_index]  # Add @ symbol before the version number
        new_name = '-'.join(name_parts).replace('@.', '.')  # Create the new filename
        new_name1 = new_name.replace("-@", "@")
        print(new_name1)
    

    copy the output in the terminal which will be {name}@{version} and save it to the same extensions.txt file in the folder

    then go back to cmd and run this command

    for /f "usebackq delims=" %i in (extensions.txt) do code --install-extension %i
    

    all extensions will start to be installed

    IMPORTANT DETAIL when you run the first command the file may have 1 or 2 files that are in the extensions folder like the extensions.json so delete those from the extensions.txt file


  2. You could do the following using jq. To install the extensions named by directories in your ${HOME}/.vscode/extenions folder, try the following:

    find "${HOME}/.vscode/extensions" -maxdepth 2 -name 'package.json' | xargs -I % jq -r '.publisher+"."+.name' -- % | xargs -I % code '--install-extension %'

    It’s a bit janky of an approach and relies on the UNIX find command (sorry). If you’re on Windows and you’re doing dev work, your probably already have Git Bash though, so you can run it from there.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search