code: def _gen_ac_command(directive_filter, regex_filter, incomplete):
      """Returns either a shell directive or a list of matching commands.
  
      If the active shell supports directives, returns the encoded
      directive containing `directive_filter`. If `directive_filter` is
      unspecified, returns the encoded command directive. This mode
      relies on the Guild completion script to resolve the list of
      commands (e.g. by using `compgen`, etc.)
  
      If the active shell does not support directives (i.e. we have not
      implemented them for that shell) uses `/bin/sh` to list commands
      available on `PATH`. This is a platform-specific approach that
      relies on `/bin/sh`. When `/bin/sh` is used to find executables,
      `regex_filter` if specified is used to filter
      results. `regex_filter` is not used when the actve shell supports
      directives. If `regex_filter` is not specified, the list of
      commands not further filtered beyond commands starting with
      `incomplete`.
  
      Use of `/bin/sh` requires the additional commands in `/bin/`:
      `try`, `grep`, `sort`, and `uniq`.
      """
      import re
      import subprocess
  
      if active_shell_supports_directives():
          if directive_filter:
              return [f"!!command:{directive_filter}"]
          return ["!!command"]
  
      cmd = [
          "/bin/sh",
          "-c",
          (
              "/bin/ls $(echo $PATH | /usr/bin/tr ':' ' ') "
              "| /usr/bin/grep -v '/' "
              "| /usr/bin/grep . "
              "| /usr/bin/sort "
              "| /usr/bin/uniq"
          ),
      ]
      out = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
      cmds = [line.strip() for line in out.decode().split("\n")]
      if regex_filter:
          filter_re = re.compile(regex_filter)
          cmds = [cmd for cmd in cmds if cmd and filter_re.match(cmd)]
      return _values_for_incomplete(incomplete, cmds)
  
imports: import os
label_desc: Use image node_id 23 for calling a global function with example usage: _gen_ac_command(directive_filter, regex_filter, incomplete) and returns: _values_for_incomplete, list, list