How do I map a terminal command to a function key?
I am using karabiner-elements to do exactly this on a Dell monitor, you can bind keypresses to shell commands:

{
"title": "F5 to dim, F6 to bright",
"rules": [
    {
        "manipulators": [
            {
              "description": "dim",
              "type": "basic",
              "from": {
                "key_code": "f5"
              },
              "to": [
                {
                    "shell_command": "/usr/local/bin/ddcctl -d 1 -b 1"
                }
              ]
            },
            {
                "description": "bright",
                "type": "basic",
                "from": {
                  "key_code": "f6"
                },
                "to": [
                  {
                      "shell_command": "/usr/local/bin/ddcctl -d 1 -b 100"
                  }
                ]
              }
          ]
    }
]


}

(I have ddctl installed, which lets you control the brightness by passing it a percentage value - https://github.com/kfix/ddcctl )

You can check the docs for writing your Complex Modifications like this one: https://pqrs.org/osx/karabiner/json.html