<commit_before># Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
# @nolint
import os
import pickle
import re
import sys

import logger

OUTPUT_FILE = '~/.fbPager.sh'
SELECTION_PICKLE = '~/.fbPager.selection.pickle'
BASH_RC = '~/.bashrc'
DEBUG = '~/.fbPager.debug.text'

ALIAS_REGEX = re.compile('alias (\w+)=[\'"](.*?)[\'"]')


def debug(*args):
    for arg in args:
        appendToFile('echo "DEBUG: ' + str(arg) + '"')


def outputSelection(lineObjs):
    filePath = os.path.expanduser(SELECTION_PICKLE)
    indices = [l.index for l in lineObjs]
    pickle.dump(indices, open(filePath, 'w'))


def getEditorAndPath():
    editor_path = os.environ.get('EDITOR')
    if editor_path:
        editor = os.path.basename(editor_path)
        logger.addEvent('using_editor_' + editor)
        return editor, editor_path
    return 'vim', 'vim'


def getEditFileCommand(filePath, lineNum):
    editor, _editor_path = getEditorAndPath()
    if editor == 'vim' and lineNum != 0:
        return '%s +%d' % (filePath, lineNum)
    elif editor in ['joe', 'emacs'] and lineNum != 0:
        return '+%d %s' % (lineNum, filePath)
    else:
        return filePath


def getAliases():
    try:
        lines = open(os.path.expanduser(BASH_RC), 'r').readlines()
    except IOError:
        return {}
    pairs = []
    for line in lines:
        results = ALIAS_REGEX.search(line)<commit_msg>fix escaping bug with spaces in path<commit_after># Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
# @nolint
import os
import pickle
import re
import sys

import logger

OUTPUT_FILE = '~/.fbPager.sh'
SELECTION_PICKLE = '~/.fbPager.selection.pickle'
BASH_RC = '~/.bashrc'
DEBUG = '~/.fbPager.debug.text'

ALIAS_REGEX = re.compile('alias (\w+)=[\'"](.*?)[\'"]')


def debug(*args):
    for arg in args:
        appendToFile('echo "DEBUG: ' + str(arg) + '"')


def outputSelection(lineObjs):
    filePath = os.path.expanduser(SELECTION_PICKLE)
    indices = [l.index for l in lineObjs]
    pickle.dump(indices, open(filePath, 'w'))


def getEditorAndPath():
    editor_path = os.environ.get('EDITOR')
    if editor_path:
        editor = os.path.basename(editor_path)
        logger.addEvent('using_editor_' + editor)
        return editor, editor_path
    return 'vim', 'vim'


def getEditFileCommand(filePath, lineNum):
    editor, _editor_path = getEditorAndPath()
    if editor == 'vim' and lineNum != 0:
        return '\'%s\' +%d' % (filePath, lineNum)
    elif editor in ['joe', 'emacs'] and lineNum != 0:
        return '+%d \'%s\'' % (lineNum, filePath)
    else:
        return "'%s'" % filePath


def getAliases():
    try:
        lines = open(os.path.expanduser(BASH_RC), 'r').readlines()
    except IOError:
        return {}
    pairs = []
    for line in lines:
        results = ALIAS_REGEX.search(line)
{'fraction_non_alphanumeric': 0.13556231003039515, 'fraction_numerical': 0.00364741641337386, 'mean_word_length': 3.279583875162549, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5235379', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1101, 'n_words': 320}