def _info(ns): env = builtins.__xonsh_env__ try: ply.__version__ = ply.__version__ except AttributeError: ply.__version__ = '3.8' data = [ ('xonsh', XONSH_VERSION), ('Git SHA', githash()), ('Python', '{}.{}.{}'.format(*PYTHON_VERSION_INFO)), ('PLY', ply.__version__), ('have readline', is_readline_available()), ('prompt toolkit', ptk_version() or None), ('shell type', env.get('SHELL_TYPE')), ('pygments', pygments_version()), ('on posix', bool(ON_POSIX)), ('on linux', ON_LINUX)] if ON_LINUX: data.append(('distro', linux_distro())) data.extend([ ('on darwin', ON_DARWIN), ('on windows', ON_WINDOWS), ('on cygwin', ON_CYGWIN), ('is superuser', is_superuser()), ('default encoding', DEFAULT_ENCODING), ('xonsh encoding', env.get('XONSH_ENCODING')), ('encoding errors', env.get('XONSH_ENCODING_ERRORS')), ]) formatter = _xonfig_format_json if ns.json else _xonfig_format_human s = formatter(data) return s
def _info(ns): env = builtins.__xonsh__.env data = [("xonsh", XONSH_VERSION)] hash_, date_ = githash() if hash_: data.append(("Git SHA", hash_)) data.append(("Commit Date", date_)) data.extend([ ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)), ("PLY", ply.__version__), ("have readline", is_readline_available()), ("prompt toolkit", ptk_version() or None), ("shell type", env.get("SHELL_TYPE")), ("pygments", pygments_version()), ("on posix", bool(ON_POSIX)), ("on linux", bool(ON_LINUX)), ]) if ON_LINUX: data.append(("distro", linux_distro())) data.extend([ ("on darwin", ON_DARWIN), ("on windows", ON_WINDOWS), ("on cygwin", ON_CYGWIN), ("on msys2", ON_MSYS), ("is superuser", is_superuser()), ("default encoding", DEFAULT_ENCODING), ("xonsh encoding", env.get("XONSH_ENCODING")), ("encoding errors", env.get("XONSH_ENCODING_ERRORS")), ]) formatter = _xonfig_format_json if ns.json else _xonfig_format_human s = formatter(data) return s
def _info(ns): env = builtins.__xonsh_env__ try: ply.__version__ = ply.__version__ except AttributeError: ply.__version__ = '3.8' data = [('xonsh', XONSH_VERSION), ('Git SHA', githash()), ('Python', '{}.{}.{}'.format(*PYTHON_VERSION_INFO)), ('PLY', ply.__version__), ('have readline', is_readline_available()), ('prompt toolkit', ptk_version() or None), ('shell type', env.get('SHELL_TYPE')), ('pygments', pygments_version()), ('on posix', bool(ON_POSIX)), ('on linux', ON_LINUX)] if ON_LINUX: data.append(('distro', linux_distro())) data.extend([ ('on darwin', ON_DARWIN), ('on windows', ON_WINDOWS), ('on cygwin', ON_CYGWIN), ('is superuser', is_superuser()), ('default encoding', DEFAULT_ENCODING), ('xonsh encoding', env.get('XONSH_ENCODING')), ('encoding errors', env.get('XONSH_ENCODING_ERRORS')), ]) formatter = _xonfig_format_json if ns.json else _xonfig_format_human s = formatter(data) return s
def _info(ns): env = builtins.__xonsh_env__ try: ply.__version__ = ply.__version__ except AttributeError: ply.__version__ = "3.8" data = [ ("xonsh", XONSH_VERSION), ("Git SHA", githash()), ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)), ("PLY", ply.__version__), ("have readline", is_readline_available()), ("prompt toolkit", ptk_version() or None), ("shell type", env.get("SHELL_TYPE")), ("pygments", pygments_version()), ("on posix", bool(ON_POSIX)), ("on linux", ON_LINUX), ] if ON_LINUX: data.append(("distro", linux_distro())) data.extend( [ ("on darwin", ON_DARWIN), ("on windows", ON_WINDOWS), ("on cygwin", ON_CYGWIN), ("is superuser", is_superuser()), ("default encoding", DEFAULT_ENCODING), ("xonsh encoding", env.get("XONSH_ENCODING")), ("encoding errors", env.get("XONSH_ENCODING_ERRORS")), ] ) formatter = _xonfig_format_json if ns.json else _xonfig_format_human s = formatter(data) return s
def _info(to_json=False, ) -> str: """Displays configuration information Parameters ---------- to_json : -j, --json reports results as json """ env = XSH.env data: tp.List[tp.Any] = [("xonsh", XONSH_VERSION)] hash_, date_ = githash() if hash_: data.append(("Git SHA", hash_)) data.append(("Commit Date", date_)) data.extend([ ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)), ("PLY", ply.__version__), ("have readline", is_readline_available()), ("prompt toolkit", ptk_version() or None), ("shell type", env.get("SHELL_TYPE")), ("history backend", env.get("XONSH_HISTORY_BACKEND")), ("pygments", pygments_version()), ("on posix", bool(ON_POSIX)), ("on linux", bool(ON_LINUX)), ]) if ON_LINUX: data.append(("distro", linux_distro())) data.append(("on wsl", bool(ON_WSL))) if ON_WSL: data.append(("wsl version", 1 if ON_WSL1 else 2)) data.extend([ ("on darwin", bool(ON_DARWIN)), ("on windows", bool(ON_WINDOWS)), ("on cygwin", bool(ON_CYGWIN)), ("on msys2", bool(ON_MSYS)), ("is superuser", is_superuser()), ("default encoding", DEFAULT_ENCODING), ("xonsh encoding", env.get("XONSH_ENCODING")), ("encoding errors", env.get("XONSH_ENCODING_ERRORS")), ]) jup_ksm = jup_kernel = None try: from jupyter_client.kernelspec import KernelSpecManager jup_ksm = KernelSpecManager() jup_kernel = jup_ksm.find_kernel_specs().get(XONSH_JUPYTER_KERNEL) except Exception: pass data.extend([("on jupyter", jup_ksm is not None), ("jupyter kernel", jup_kernel)]) data.extend([("xontrib", xontribs_loaded())]) data.extend([("RC file", XSH.rc_files)]) formatter = _xonfig_format_json if to_json else _xonfig_format_human s = formatter(data) return s
def _info(ns): env = builtins.__xonsh__.env data = [("xonsh", XONSH_VERSION)] hash_, date_ = githash() if hash_: data.append(("Git SHA", hash_)) data.append(("Commit Date", date_)) data.extend( [ ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)), ("PLY", ply.__version__), ("have readline", is_readline_available()), ("prompt toolkit", ptk_version() or None), ("shell type", env.get("SHELL_TYPE")), ("pygments", pygments_version()), ("on posix", bool(ON_POSIX)), ("on linux", bool(ON_LINUX)), ] ) if ON_LINUX: data.append(("distro", linux_distro())) data.extend( [ ("on darwin", bool(ON_DARWIN)), ("on windows", bool(ON_WINDOWS)), ("on cygwin", bool(ON_CYGWIN)), ("on msys2", bool(ON_MSYS)), ("is superuser", is_superuser()), ("default encoding", DEFAULT_ENCODING), ("xonsh encoding", env.get("XONSH_ENCODING")), ("encoding errors", env.get("XONSH_ENCODING_ERRORS")), ] ) jup_ksm = jup_kernel = None try: from jupyter_client.kernelspec import KernelSpecManager jup_ksm = KernelSpecManager() jup_kernel = jup_ksm.find_kernel_specs().get(XONSH_JUPYTER_KERNEL) except Exception: pass data.extend([("on jupyter", jup_ksm is not None), ("jupyter kernel", jup_kernel)]) data.extend([("xontrib", xontribs_loaded())]) formatter = _xonfig_format_json if ns.json else _xonfig_format_human s = formatter(data) return s
def PROMPT_FIELDS(): return dict( user=xp.os_environ.get("USERNAME" if xp.ON_WINDOWS else "USER", "<user>"), prompt_end="#" if xt.is_superuser() else "$", hostname=socket.gethostname().split(".", 1)[0], cwd=_dynamically_collapsed_pwd, cwd_dir=lambda: os.path.dirname(_replace_home_cwd()), cwd_base=lambda: os.path.basename(_replace_home_cwd()), short_cwd=_collapsed_pwd, curr_branch=current_branch, branch_color=branch_color, branch_bg_color=branch_bg_color, current_job=_current_job, env_name=env_name, vte_new_tab_cwd=vte_new_tab_cwd, gitstatus=gitstatus_prompt, )
def FORMATTER_DICT(): return dict( user=os.environ.get('USERNAME' if xp.ON_WINDOWS else 'USER', '<user>'), prompt_end='#' if xt.is_superuser() else '$', hostname=socket.gethostname().split('.', 1)[0], cwd=_dynamically_collapsed_pwd, cwd_dir=lambda: os.path.dirname(_replace_home_cwd()), cwd_base=lambda: os.path.basename(_replace_home_cwd()), short_cwd=_collapsed_pwd, curr_branch=current_branch, branch_color=branch_color, branch_bg_color=branch_bg_color, current_job=_current_job, env_name=env_name, vte_new_tab_cwd=vte_new_tab_cwd, gitstatus=gitstatus_prompt, )
def load_initial(self): from xonsh.prompt import gitstatus from xonsh.prompt.cwd import ( _collapsed_pwd, _dynamically_collapsed_pwd, _replace_home_cwd, ) from xonsh.prompt.env import env_name, vte_new_tab_cwd from xonsh.prompt.job import _current_job from xonsh.prompt.times import _localtime from xonsh.prompt.vc import branch_bg_color, branch_color, current_branch self.update( dict( user=xp.os_environ.get("USERNAME" if xp.ON_WINDOWS else "USER", "<user>"), prompt_end="#" if xt.is_superuser() else "$", hostname=socket.gethostname().split(".", 1)[0], cwd=_dynamically_collapsed_pwd, cwd_dir=lambda: os.path.join( os.path.dirname(_replace_home_cwd()), ""), cwd_base=lambda: os.path.basename(_replace_home_cwd()), short_cwd=_collapsed_pwd, curr_branch=current_branch, branch_color=branch_color, branch_bg_color=branch_bg_color, current_job=_current_job, env_name=env_name, env_prefix="(", env_postfix=") ", vte_new_tab_cwd=vte_new_tab_cwd, time_format="%H:%M:%S", localtime=_localtime, last_return_code=lambda: XSH.env.get("LAST_RETURN_CODE", 0), last_return_code_if_nonzero=lambda: XSH.env.get( "LAST_RETURN_CODE", 0) or None, )) for val in self.get_fields(gitstatus): self[val.name] = val
pattern="[" u"\U0001F600-\U0001F64F" # emoticons u"\U0001F300-\U0001F5FF" # symbols & pictographs u"\U0001F680-\U0001F6FF" # transport & map symbols u"\U0001F1E0-\U0001F1FF" # flags (iOS) "]+", flags=re.UNICODE) return regrex_pattern.sub(replace_char, text) def _field_date_time_tz(): t = time.strftime('%y-%m-%d %H:%M:%S%z', time.localtime()) return t[:-2] if t[-2:] == '00' else t __xonsh__.env['PROMPT_FIELDS']['prompt_end_xonsh'] = "#" if is_superuser( ) else "@" __xonsh__.env['PROMPT_FIELDS']['cwd_abs'] = lambda: str( Path(__xonsh__.env['PROMPT_FIELDS']['cwd']()).expanduser()) __xonsh__.env['PROMPT_FIELDS']['date_time_tz'] = _field_date_time_tz # DEPRECATED: use `{gitstatus#nocolorx}` instead of `{gitstatus_noc}` __xonsh__.env['PROMPT_FIELDS']['gitstatus_noc'] = lambda: _remove_colors( __xonsh__.env['PROMPT_FIELDS']['gitstatus']()) def _screens(): line = [] sty = None for l in __xonsh__.subproc_captured_stdout(['screen', '-ls']).splitlines(): if '\t' in l: screen_name = l.split('\t')[1].split('.')[1]