How to add Fleet IDE for windows context menu "Open folder with..."

86 views Asked by At

Im trying to add fleet IDE to my context menu for opening a folder, Ive tried writing a registry entry with bat and powershell and python and had no luck.

this shows up in Regedit but doesnt run the app

@echo off
setlocal enabledelayedexpansion

:: Function to check if the script is running as administrator
:check_admin
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo Running without administrative privileges. Reopening with elevated privileges...
    set "script_path=%~0"
    set "params=%*"
    set "batch_cmd=^
        set params=!params:*%~0=!
        set params=!params:~1!
        call "%~0" !params! %*
        exit /b
    "
    powershell Start-Process -Verb RunAs -FilePath "cmd.exe" -ArgumentList "/c %batch_cmd%"
    exit /b
)
exit /b

:: Rest of your script here

:main
:: Your existing script logic goes here

:: Call the check_admin function at the beginning
call :check_admin

:: Continue with the main script logic
echo "This script is running with administrative privileges."



:: Define paths and menu text
set "menu_text=Open with Fleet"
set "app_path=C:\Users\dower\AppData\Local\Programs\Fleet\Fleet.exe"
set "icon_path=C:\Users\dower\AppData\Local\Programs\Fleet\Fleet.ico"

:: Function to add a new context menu entry for folders
:add_context_menu
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\%menu_text%" /ve /d "%menu_text%" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\%menu_text%\command" /ve /d "\"%app_path%\" --dir \"%%1\"" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\%menu_text%\Icon" /ve /d "%app_path%,0" /f
exit /b

:: Function to remove the existing context menu entry
:remove_context_menu
reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\%menu_text%" /f
exit /b

:: Main script
:: Check if the existing entry needs to be removed
for /f "tokens=* delims=" %%a in ('reg query "HKEY_CLASSES_ROOT\Directory\Background\shell" ^| find /i "%menu_text%"') do (
    set "existing_entry=%%a"
)
if defined existing_entry (
    call :remove_context_menu
)

:: Add a new context menu entry
call :add_context_menu
echo Successfully added '%menu_text%' context menu entry for folders.

If I could kindly get a pointer for bat or other language for best achieving this

2

There are 2 answers

1
Sasha Alexander On

https://github.com/samfisherirl/Fleet-IDE-context-menu-Open-Folder-With

    import os
    import sys
    import winreg
    import ctypes
    import time

    def is_admin():
        try:
            return ctypes.windll.shell32.IsUserAnAdmin()
        except:
            return False

    def run_as_admin():
        ctypes.windll.shell32.ShellExecuteW(
            None, "runas", sys.executable, " ".join(sys.argv), None, 1
        )

    # Define paths and menu text
    menu_text = "Open with Fleet"
    appdata_local_path = os.path.join(os.getenv('LOCALAPPDATA'), 'Programs')

    # Specify the rest of the path to your executable
    executable_path = 'Fleet\Fleet.exe'

    # Combine the paths
    app_path = os.path.join(appdata_local_path, executable_path)

    def add_context_menu(location):
        """Adds a new context menu entry for folders."""

        # Open registry key
        key_path = f"Directory\\{location}\\Open with Fleet"
        key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, key_path)
        subkey = winreg.CreateKey(key, "command")

        # Set default values
        winreg.SetValueEx(key, 'Icon', 0, winreg.REG_SZ, f"\"{app_path}\",0")
        winreg.SetValueEx(key, None, 0, winreg.REG_SZ, menu_text)
        winreg.SetValueEx(subkey, None, 0, winreg.REG_SZ, f"\"{app_path}\" --dir \"%V\"")

        # Close registry keys
        winreg.CloseKey(subkey)
        winreg.CloseKey(key)

    def remove_context_menu(location):
        """Removes the existing context menu entry."""
        key_path = f"Directory\\{location}\\Open with Fleet"

        try:
            # Delete the registry key and its subkeys
            winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_path)
        except FileNotFoundError:
            print(f"Registry key not found: {key_path}")
        except Exception as e:
            print(f"Error removing context menu entry: {e}")

    # Check if running as admin
    if not is_admin():
        # Re-run the script as admin
        run_as_admin()
        sys.exit()

    # Remove existing entries
    remove_context_menu("Background\\shell")
    remove_context_menu("shell")

    # Add new context menu entry
    add_context_menu("Background\\shell")
    add_context_menu("shell")

    print(f"Successfully added '{menu_text}' context menu entry for folders.")
    time.sleep(3)
0
FancyFinger On

I know this is not what you are looking for. But there is another way to open the working folder with fleet using Powershell.

  1. Open powershell in the working directory from address bar by typing powershell or cmd , or right click and open terminal.
  2. write fleet . [fleet dot]

This will open working directory inside fleet.