<commit_before>import React from 'react';
import fs from 'fs';
import fuzzySearch from '../lib/fuzzySearch';
import shellCommand from '../lib/shellCommand';

const DIR_REGEXP = /^\/(.*\/)*(.*)/
const HOME_DIR_REGEXP = /^\~/;

/**
 * Plugin to look and display local and external IPs
 * @param  {String} term
 */
export default (term, callback) => {
  let path = term;
  if (path.match(HOME_DIR_REGEXP)) {
    path = path.replace(HOME_DIR_REGEXP, `/Users/${process.env['USER']}`);
  }
  const match = path.match(DIR_REGEXP);
  if (match) {
    const dir = match[1] ? `/${match[1]}` : '/';
    const fileName = match[2];
    fs.readdir(dir, (err, items) => {
      if (fileName) {
        items = fuzzySearch(items, fileName);
      }
      const result = items.map(file => {
        const path = [dir, file].join('');
        return {
          id: path,
          title: file,
          subtitle: path,
          clipboard: path,
          term: path,
          onSelect: shellCommand.bind(null, `open ${path}`),
        };
      });
      callback(term, result);
    });<commit_msg>Always go inside home directory when user enters `~`<commit_after>import React from 'react';
import fs from 'fs';
import fuzzySearch from '../lib/fuzzySearch';
import shellCommand from '../lib/shellCommand';

const DIR_REGEXP = /^\/(.*\/)*(.*)/
const HOME_DIR_REGEXP = /^\~/;

/**
 * Plugin to look and display local and external IPs
 * @param  {String} term
 */
export default (term, callback) => {
  let path = term;
  if (path.match(HOME_DIR_REGEXP)) {
    path = path.replace(HOME_DIR_REGEXP, `/Users/${process.env['USER']}/`);
  }
  const match = path.match(DIR_REGEXP);
  if (match) {
    const dir = match[1] ? `/${match[1]}` : '/';
    const fileName = match[2];
    fs.readdir(dir, (err, items) => {
      if (fileName) {
        items = fuzzySearch(items, fileName);
      }
      const result = items.map(file => {
        const path = [dir, file].join('');
        return {
          id: path,
          title: file,
          subtitle: path,
          clipboard: path,
          term: path,
          onSelect: shellCommand.bind(null, `open ${path}`),
        };
      });
      callback(term, result);
    });
{'fraction_non_alphanumeric': 0.17135086128739802, 'fraction_numerical': 0.0027198549410698096, 'mean_word_length': 2.4810725552050474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1263288', 'n_tokens_mistral': 724, 'n_tokens_neox': 716, 'n_words': 184}