return completion config for the named shell.
190103
def shell_config_for(shell, vexrc, environ):
    
    here = os.path.dirname(os.path.abspath(__file__))
    path = os.path.join(here, 'shell_configs', shell)
    try:
        with open(path, 'rb') as inp:
            data = inp.read()
    except FileNotFoundError as error:
        if error.errno != 2:
            raise
        return b''
    ve_base = vexrc.get_ve_base(environ).encode('ascii')
    if ve_base and not scary_path(ve_base) and os.path.exists(ve_base):
        data = data.replace(b'$WORKON_HOME', ve_base)
    return data
1083566
def find(name):
    """"""

    if op.exists(name):
        return name

    path = op.dirname(__file__) or '.'

    paths = [path] + config['include_path']

    for path in paths:
        filename = op.abspath(op.join(path, name))
        if op.exists(filename):
            return filename

        for d in os.listdir(path):
            fullpath = op.abspath(op.join(path, d))
            if op.isdir(fullpath):
                filename = op.abspath(op.join(fullpath, name))
                if op.exists(filename):
                    return filename

    return None
107021
def setup_completion(shell):
    """"""

    # Handle special case of importing pyreadline on Windows
    # See: http://stackoverflow.com/questions/6024952/readline-functionality-on-windows-with-python-2-7
    import glob
    try:
        import readline
    except ImportError:
        import pyreadline as readline

    def _complete(text, state):
        buf = readline.get_line_buffer()
        if buf.startswith('help ') or " " not in buf:
            return [x for x in shell.valid_identifiers() if x.startswith(text)][state]

        return (glob.glob(os.path.expanduser(text)+'*')+[None])[state]

    readline.set_completer_delims(' \t\n;')
    # Handle Mac OS X special libedit based readline
    # See: http://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-10-7-lion
    if readline.__doc__ is not None and 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")

    readline.set_completer(_complete)
569852
def _get_process_mapping():
    
    for impl in (proc, ps):
        try:
            mapping = impl.get_process_mapping()
        except EnvironmentError:
            continue
        return mapping
    raise ShellDetectionFailure('compatible proc fs or ps utility is required')
85051
def get(cls):
    """"""
    return {
      SourceRootConfig,
      Reporting,
      Reproducer,
      RunTracker,
      Changed,
      BinaryUtil.Factory,
      Subprocess.Factory
    }
1114805
def get_shell(pid=None, max_depth=6):
    
    pid = str(pid or os.getpid())
    mapping = _get_process_mapping()
    for proc_cmd in _iter_process_command(mapping, pid, max_depth):
        if proc_cmd.startswith('-'):    # Login shell! Let's use this.
            return _get_login_shell(proc_cmd)
        name = os.path.basename(proc_cmd).lower()
        if name in SHELL_NAMES:     # The inner-most (non-login) shell.
            return (name, proc_cmd)
    return None
907487
def _get_config_name():
  ''''''
  p = subprocess.Popen('git config --get user.name', shell=True,
                       stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  output = p.stdout.readlines()
  return _stripslashes(output[0])
527963
def complete_shells(line, text, predicate=lambda i: True):
    """"""
    res = [i.display_name + ' ' for i in dispatchers.all_instances() if
           i.display_name.startswith(text) and
           predicate(i) and
           ' ' + i.display_name + ' ' not in line]
    return res
54050
def complete(self):
        """"""
        if self._possible is None:
            self._possible = []
            for possible in self.names:
                c = Completion(self.context, self.names[possible], len(self.context.symbol))
                self._possible.append(c)

        return self._possible
1271
def config(filename):
    
    Config = collections.namedtuple('Config', [
        'git',
        'lock_file',
        'version',
        'name',
        'src',
        'dst',
        'files',
        'post_commands',
    ])

    return [Config(**d) for d in _get_config_generator(filename)]
187338
def get_shell(pid=None, max_depth=6):
    
    if not pid:
        pid = os.getpid()
    processes = dict(_iter_process())

    def check_parent(pid, lvl=0):
        ppid = processes[pid].get('parent_pid')
        shell_name = _get_executable(processes.get(ppid))
        if shell_name in SHELL_NAMES:
            return (shell_name, processes[ppid]['executable'])
        if lvl >= max_depth:
            return None
        return check_parent(ppid, lvl=lvl + 1)

    shell_name = _get_executable(processes.get(pid))
    if shell_name in SHELL_NAMES:
        return (shell_name, processes[pid]['executable'])
    try:
        return check_parent(pid)
    except KeyError:
        return None
148172
def shell_config_cmd(argv):
    ""
    shell = supported_shell()
    if shell:
        print(pew_site / 'shell_config' / ('init.' + shell))
    else:
        err('Completions and prompts are unavailable for %s' %
            repr(os.environ.get('SHELL', '')))
1190602
def find_completions_at_cursor(ast_tree, filename, line, col, root_env=gcl.default_env):
  
  q = gcl.SourceQuery(filename, line, col - 1)
  rootpath = ast_tree.find_tokens(q)

  if is_identifier_position(rootpath):
    return find_inherited_key_completions(rootpath, root_env)

  try:
    ret = find_deref_completions(rootpath, root_env) or enumerate_scope(rootpath, root_env=root_env)
    assert isinstance(ret, dict)
    return ret
  except gcl.EvaluationError:
    # Probably an unbound value or something--just return an empty list
    return {}
839658
def find_inherited_key_completions(rootpath, root_env):
  
  tup = inflate_context_tuple(rootpath, root_env)
  if isinstance(tup, runtime.CompositeTuple):
    keys = set(k for t in tup.tuples[:-1] for k in t.keys())
    return {n: get_completion(tup, n) for n in keys}
  return {}
1092648
def config(env=DEFAULT_ENV, default=None):
    """"""

    conf = {}

    s = os.environ.get(env, default)

    if s:
        conf = parse(s)

    return conf
913025
def get_shell(pid=None, max_depth=6):
    
    pid = str(pid or os.getpid())
    mapping = _get_process_mapping()
    login_shell = os.environ.get('SHELL', '')
    for _ in range(max_depth):
        try:
            proc = mapping[pid]
        except KeyError:
            break
        name = os.path.basename(proc.args[0]).lower()
        if name in SHELL_NAMES:
            return (name, proc.args[0])
        elif proc.args[0].startswith('-'):
            # This is the login shell. Use the SHELL environ if possible
            # because it provides better information.
            if login_shell:
                name = login_shell.lower()
            else:
                name = proc.args[0][1:].lower()
            return (os.path.basename(name), name)
        pid = proc.ppid     # Go up one level.
    return None
48178
def get_configure_by_name(self, name):
        """"""

        for elem in self.configures:
            if elem.name == name:
                return elem
        return None