<commit_before>" vim: et sw=2 sts=2

scriptencoding utf-8

" Function: #escape {{{1
function! sy#util#escape(path) abort
  if exists('+shellslash')
    let old_ssl = &shellslash
    if fnamemodify(&shell, ':t') == 'cmd.exe'
      set noshellslash
    else
      set shellslash
    endif
  endif

  let path = shellescape(a:path)

  if exists('old_ssl')
    let &shellslash = old_ssl
  endif

  return path
endfunction

" Function: #separator {{{1
function! sy#util#separator() abort
  return !exists('+shellslash') || &shellslash ? '/' : '\'
endfunction<commit_msg>Add sy#util#run_in_dir to run system() within a specific directory<commit_after>" vim: et sw=2 sts=2

scriptencoding utf-8

" Function: #escape {{{1
function! sy#util#escape(path) abort
  if exists('+shellslash')
    let old_ssl = &shellslash
    if fnamemodify(&shell, ':t') == 'cmd.exe'
      set noshellslash
    else
      set shellslash
    endif
  endif

  let path = shellescape(a:path)

  if exists('old_ssl')
    let &shellslash = old_ssl
  endif

  return path
endfunction

" Function: #separator {{{1
function! sy#util#separator() abort
  return !exists('+shellslash') || &shellslash ? '/' : '\'
endfunction

" Function: #run_in_dir {{{1
function! sy#util#run_in_dir(dir, cmd) abort
  let chdir = haslocaldir() ? 'lcd' : 'cd'
  let cwd = getcwd()
  try
    exe chdir .' '. fnameescape(fnamemodify(a:dir, ':p'))
    let resp = system(a:cmd)
  finally
    exe chdir .' '. fnameescape(cwd)
  endtry
  return resp
endfunction
{'fraction_non_alphanumeric': 0.13560454241816966, 'fraction_numerical': 0.007348029392117568, 'mean_word_length': 3.7859424920127798, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '469807', 'n_tokens_mistral': 553, 'n_tokens_neox': 529, 'n_words': 140}