Dyota's blog

Ergonomics: open all project files

One-touch magic

When projects have a lot of files that need to be open at the same time, I find it hard to remember exactly what all of them are. I may need several Excel files, a web browser with Power BI on it, or maybe Power Apps, and then I need a folder open in VS Code, and maybe a few File Explorer windows open... sometimes it feels like my brain is doing a cold engine start in fifth gear.

I don't know why I've never thought about this before this week, but I decided to make a function that opens up everything I need for a project. Maybe it has something to do with my discovery of Out-ConsoleGridView. It's here anyway.

What it does

The function is simply called open.

  1. In the terminal, I call open
  2. It shows me (through Out-ConsoleGridView) a selection of all of the projects I can open
  3. I select one
  4. It goes through and opens up all of the windows I have specified for that project, all at once. (What it doesn't do is lay them out nicely on the screen, but... that can come later)

How it works

Every project has a config file, which is structure like so:

{
    "project": "#template",
    "opens": {
        "websites": [
            {
                "profile": "",
                "url": ""
            }
        ],
        "folders": [],
        "start": [],
        "npp": [],
        "codeFolders": [],
        "ads": []
    }
}

Some notes:

Here is the PowerShell function that does it:

function open (
    [switch] $edit
){
    # this is the path to open.json, which is an array of configs. 
    # the array is one element per project

    $path = ""
    
    if ($edit) {
        code $path
    } else {
        $register = cat $path | convertfrom-json
        
        # choose a project to open
        $project = $register.project | 
            sort | 
            Out-ConsoleGridView -OutputMode Single

        if ($project -eq $null) {
            break;
        } else {
            # list all of the opens
            $opens = ($register | ? { $_.project -eq $project }).opens
            
            # set up path for executables
            $chrome = 'C:\Program Files\Google\Chrome\Application\chrome.exe'
            
            # open up all of the different types
            $opens.folders | % { cd $_; e . }
            $opens.websites | % {
                $p = $_.profile
                $url = $_.url
                s $chrome -ArgumentList "--profile-directory=`"$p`"", $url
             }
            if ($null -ne $opens.codeFolders) { $opens.codeFolders | % { code $_} }
            if ($null -ne $opens.npp) { $opens.npp | % { notepad++.exe $_ } }
            if ($null -ne $opens.start) { $opens.start | % { s $_ } }
            if ($null -ne $opens.ads) { $opens.ads | % { azuredatastudio.cmd $_ } }
            
        }
    }
}

#ergonomics #powershell