<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
  doitlive
  ~~~~~~~~

  A tool for "live" presentations in the terminal.

  :copyright: (c) 2014 by <NAME>.
  :license: MIT, see LICENSE for more details.
"""

from __future__ import unicode_literals
import os
import sys
import re
import getpass
import socket
import subprocess
from tempfile import NamedTemporaryFile
from collections import OrderedDict

import click
from click import echo, style, secho, getchar
from click.termui import strip_ansi

__version__ = '1.0-dev'
__author__ = '<NAME>'
__license__ = 'MIT'

env = os.environ
PY2 = int(sys.version[0]) == 2
if not PY2:
    unicode = str
    basestring = (str, bytes)

THEMES = OrderedDict([
    ('default', '{user.cyan.bold}@{hostname.blue}:{dir.green} $'),

    ('sorin', '{cwd.cyan} {git_branch.green.square} ' +
    ''.join([style('❯', fg='red'),  style('❯', fg='white'), style('❯', fg='green')])),

    ('nicolauj', style('❯', fg='white')),

    ('steeef', '{user.red} at {hostname.yellow} in {cwd.green} '
                '{git_branch.cyan.paren}\n$'),

    ('redhat', '[{user}@{hostname} {dir}]$'),
    ('redhat_color', '[{user.cyan.bold}@{hostname.blue} {dir.green}]$'),

    ('walters', '{user}@{hostname.underlined}>'),
    ('walters_color', '{user.cyan.bold}@{hostname.blue.underlined}>'),

    ('minimal', '{dir} {git_branch.square} »'),
    ('minimal_color', '{dir.cyan} {git_branch.blue.square} »'),

    ('osx', '{hostname}:{dir} {user}$'),
    ('osx_color', '{hostname.blue}:{dir.green} {user.cyan}$')
])

HERE = os.path.abspath(os.path.dirname(__file__))
ESC = u'\x1b'
RETURNS = {'\r', '\n'}
OPTION_RE = re.compile(r'^#\s?doitlive\s+'
            '(?P<option>prompt|shell|alias|env|speed):'
            '\s*(?P<arg>.+)$')


TESTING = False


class TermString(unicode):
    """A string-like object that can be formatted with ANSI styles. Useful for
    styling strings within a string.format "template."
    """

    def _styled(self, **styles):
        return TermString(style(self, **styles))

    # Colors

    @property
    def blue(self): return self._styled(fg='blue')
    @property
    def magenta(self): return self._styled(fg='magenta')
    @property
    def red(self): return self._styled(fg='red')
    @property
    def white(self): return self._styled(fg='white')
    @property
    def green(self): return self._styled(fg='green')
    @property
    def black(self): return self._styled(fg='black')
    @property
    def yellow(self): return self._styled(fg='yellow')
    @property
    def cyan(self): return self._styled(fg='cyan')
    @property
    def reset(self): return self._styled(fg='reset')

    # Styling

    @property
    def bold(self):
        return self._styled(bold=True)

    @property
    def blink(self):
        return self._styled(blink=True)

    @property
    def underlined(self):
        return self._styled(underline=True)

    @property
    def dim(self):
        return self._styled(dim=True)

    def _bracketed(self, left, right):
        if strip_ansi(self):
            return TermString(''.join([left, self, right]))
        else:
            return TermString('')

    @property
    def paren(self):
        return self._bracketed('(', ')')

    @property
    def square(self):
        return self._bracketed('[', ']')

    @property
    def curly(self):
        return self._bracketed('{', '}')


def get_current_git_branch():
    command = ['git', 'symbolic-ref', '--short', '-q', 'HEAD']
    try:
        proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = proc.communicate()
        return out.strip()
    except subprocess.CalledProcessError:
        pass
    return ''


def get_prompt_state():
    full_cwd = os.getcwd()
    cwd_raw = full_cwd.replace(env['HOME'], '~')
    dir_raw = '~' if full_cwd == env['HOME'] else os.path.split(full_cwd)[-1]
    return {
        'user': TermString(getpass.getuser()),
        'cwd': TermString(cwd_raw),
        'dir': TermString(dir_raw),
        'hostname': TermString(socket.gethostname()),
        'git_branch': TermString(get_current_git_branch()),
    }


def ensure_utf(string):
    return string.encode('utf-8') if PY2 else string


def run_command(cmd, shell=None, aliases=None, envvars=None, test_mode=True):
    shell = shell or env.get('DOITLIVE_INTERPRETER') or '/bin/bash'<commit_msg>Add common symbols to prompt template context<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
  doitlive
  ~~~~~~~~

  A tool for "live" presentations in the terminal.

  :copyright: (c) 2014 by <NAME>.
  :license: MIT, see LICENSE for more details.
"""

from __future__ import unicode_literals
import os
import sys
import re
import getpass
import socket
import subprocess
from tempfile import NamedTemporaryFile
from collections import OrderedDict

import click
from click import echo, style, secho, getchar
from click.termui import strip_ansi

__version__ = '1.0-dev'
__author__ = '<NAME>'
__license__ = 'MIT'

env = os.environ
PY2 = int(sys.version[0]) == 2
if not PY2:
    unicode = str
    basestring = (str, bytes)

THEMES = OrderedDict([
    ('default', '{user.cyan.bold}@{<EMAIL>}:{dir.green} $'),

    ('sorin', '{cwd.cyan} {git_branch.green.square} '
        '{r_angle.red}{r_angle.yellow}{r_angle.green}'),

    ('nicolauj', '{r_angle.white}'),

    ('steeef', '{user.red} at {hostname.yellow} in {cwd.green} '
                '{git_branch.cyan.paren}\n$'),

    ('redhat', '[{user}@{hostname} {dir}]$'),
    ('redhat_color', '[{user.cyan.bold}@{<EMAIL>} {dir.green}]$'),

    ('walters', '{user}@{hostname.underlined}>'),
    ('walters_color', '{user.cyan.bold}@{hostname.blue.underlined}>'),

    ('minimal', '{dir} {git_branch.square} »'),
    ('minimal_color', '{dir.cyan} {git_branch.blue.square} »'),

    ('osx', '{hostname}:{dir} {user}$'),
    ('osx_color', '{hostname.blue}:{dir.green} {user.cyan}$')
])

HERE = os.path.abspath(os.path.dirname(__file__))
ESC = '\x1b'
RETURNS = {'\r', '\n'}
OPTION_RE = re.compile(r'^#\s?doitlive\s+'
            '(?P<option>prompt|shell|alias|env|speed):'
            '\s*(?P<arg>.+)$')


TESTING = False


class TermString(unicode):
    """A string-like object that can be formatted with ANSI styles. Useful for
    styling strings within a string.format "template."
    """

    def _styled(self, **styles):
        return TermString(style(self, **styles))

    # Colors

    @property
    def blue(self): return self._styled(fg='blue')
    @property
    def magenta(self): return self._styled(fg='magenta')
    @property
    def red(self): return self._styled(fg='red')
    @property
    def white(self): return self._styled(fg='white')
    @property
    def green(self): return self._styled(fg='green')
    @property
    def black(self): return self._styled(fg='black')
    @property
    def yellow(self): return self._styled(fg='yellow')
    @property
    def cyan(self): return self._styled(fg='cyan')
    @property
    def reset(self): return self._styled(fg='reset')

    # Styling

    @property
    def bold(self):
        return self._styled(bold=True)

    @property
    def blink(self):
        return self._styled(blink=True)

    @property
    def underlined(self):
        return self._styled(underline=True)

    @property
    def dim(self):
        return self._styled(dim=True)

    def _bracketed(self, left, right):
        if strip_ansi(self):
            return TermString(''.join([left, self, right]))
        else:
            return TermString('')

    @property
    def paren(self):
        return self._bracketed('(', ')')

    @property
    def square(self):
        return self._bracketed('[', ']')

    @property
    def curly(self):
        return self._bracketed('{', '}')


def get_current_git_branch():
    command = ['git', 'symbolic-ref', '--short', '-q', 'HEAD']
    try:
        proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = proc.communicate()
        return out.strip()
    except subprocess.CalledProcessError:
        pass
    return ''


# Some common symbols used in prompts
R_ANGLE = TermString('❯')
R_ANGLE_DOUBLE = TermString('»')
DOLLAR = TermString('$')
PERCENT = TermString('%')

def get_prompt_state():
    full_cwd = os.getcwd()
    cwd_raw = full_cwd.replace(env['HOME'], '~')
    dir_raw = '~' if full_cwd == env['HOME'] else os.path.split(full_cwd)[-1]
    return {
        'user': TermString(getpass.getuser()),
        'cwd': TermString(cwd_raw),
        'dir': TermString(dir_raw),
        'hostname': TermString(socket.gethostname()),
        'git_branch': TermString(get_current_git_branch()),
        # Symbols
        'r_angle': R_ANGLE,
        'r_angle_double': R_ANGLE_DOUBLE,
        'dollar': DOLLAR,
        'percent': PERCENT,
    }


def ensure_utf(string):
    return string.encode('utf-8') if PY2 else string


def run_command(cmd, shell=None, aliases=None, envvars=None, test_mode=True):
    shell = shell or env.get('DOITLIVE_INTERPRETER') or '/bin/bash'
{'fraction_non_alphanumeric': 0.17074521094009523, 'fraction_numerical': 0.003321891263425977, 'mean_word_length': 3.367504835589942, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1715429', 'n_tokens_mistral': 3172, 'n_tokens_neox': 3099, 'n_words': 677}