<commit_before>import { getCurrentWindow } from 'remote';
import home from 'home-dir';
import path from 'path'

const HOME = home();

function _tildify(home, p) {
  const s = path.normalize(p) + path.sep;
  return (s.indexOf(home) === 0 ? s.replace(home + path.sep, '~' + path.sep) : s).slice(0, -1);
}

function tildify(path) {
  if(!path){
    return ''
  }
  return _tildify(HOME, path)
}

export function initNativeHandlers(store) {
  store
    .map(state => {
      const { executionState, filename } = state;
      return {
        title: `${tildify(filename) || 'Untitled'} - ${executionState}`,
        path: filename,
      };
    })
    .distinctUntilChanged()
    .debounceTime(200)
    .subscribe(res => {
      const win = getCurrentWindow();
      // TODO: Investigate if setRepresentedFilename() is a no-op on non-OS X
      if (res.path && win.setRepresentedFilename) {
        // TODO: this needs to be the full path to the file
        win.setRepresentedFilename(res.path);
      }
      win.setTitle(res.title);
    });
}<commit_msg>Lint the tildify, clean up.<commit_after>import { getCurrentWindow } from 'remote';
import home from 'home-dir';
import path from 'path';

const HOME = home();

/**
 * Turn a path like /Users/n/mine.ipynb to ~/mine.ipynb
 * @param  {string} p the full path to a file
 * @return {string}   tildified path
 */
function tildify(p) {
  if (!p) {
    return '';
  }
  const s = path.normalize(p) + path.sep;
  return (s.indexOf(HOME) === 0 ? s.replace(HOME + path.sep, `~${path.sep}`) : s).slice(0, -1);
}

export function initNativeHandlers(store) {
  store
    .map(state => {
      const { executionState, filename } = state;
      return {
        title: `${tildify(filename) || 'Untitled'} - ${executionState}`,
        path: filename,
      };
    })
    .distinctUntilChanged()
    .debounceTime(200)
    .subscribe(res => {
      const win = getCurrentWindow();
      // TODO: Investigate if setRepresentedFilename() is a no-op on non-OS X
      if (res.path && win.setRepresentedFilename) {
        // TODO: this needs to be the full path to the file
        win.setRepresentedFilename(res.path);
      }
      win.setTitle(res.title);
    });
}
{'fraction_non_alphanumeric': 0.1494775102226261, 'fraction_numerical': 0.005452067242162653, 'mean_word_length': 2.8031088082901556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4134321', 'n_tokens_mistral': 746, 'n_tokens_neox': 728, 'n_words': 189}