code: def _write_completion_script_to_user_config(shell, script):
      path = os.path.join(
          config.user_config_home(), f"{shell}_completion"
      )
      cli.out(
          f"Writing completion script to {util.format_dir(path)}",
          err=True,
      )
      util.ensure_dir(os.path.dirname(path))
      with open(path, "w") as f:
          f.write(script)
          f.write("\n")
      return path
  
imports: import glob
  import logging
  import os
  import shutil
  import sys
  import guild
  from guild import cli
  from guild import config
  from guild import util
label_desc: Use image node_id 5 for calling a global function with example usage: _write_completion_script_to_user_config(shell, script) and returns: path