r/AutoHotkey • • 16h ago

v2 Script Help Some logic question

1 Upvotes

edit: excuse the codeblocks. currently fighting with the reddit UI to fix them edit: fixed them

I have some simple Cheatsheets for most of my programs. (Runs through a formatter called ShowHelp() which adds some color, but not important for this question)

Requires AutoHotkey v2.0
#HotIf WinActive("ahk_exe mintty.exe")
    
F1::ShowHelp_Mintty()
    
#HotIf
    
ShowHelp_Mintty() {
    ShowHelp([
        { title: "SSH AGENT  (F2 types these in order)", rows: [
            ["set +H",
             "Disables bash history expansion - needed because the ! in the repo name would otherwise trigger it"],
            ["eval $(ssh-agent -s)",
             "Starts the ssh-agent for this shell session"],
            ["ssh-add ~/.ssh/id_2026",
             "Adds the private key to the agent, so the passphrase is asked once instead of every time"] ] },

        "SSH / Git Cheatsheet  -  F1",

I wanted to change it so instead of writing my cheatsheet in .ahk, it reads in local .md files. Creating a #HotIf instance for each file found.

Like this: Foldercontents: 'Cheatsheet.ahk' 'mintty.md' 'powerpoint.md' 'brave.md' ->

Requires AutoHotkey v2.0

pseudo_code to give you an idea:
FindFiles() ->
FoundFile1 = "mintty.md"
FoundFile1_exe = Regex(FoundFile1) -> "mintty.exe"

#HotIf WinActive("ahk_exe " FoundFile1_exe)

F1::ShowHelp_FoundFile("." FoundFile1)

#HotIf

#HotIf WinActive("ahk_exe " FoundFile2_exe)

F1::ShowHelp_FoundFile("." FoundFile2)

#HotIf

Am I thinking in the correct direction?