<commit_before># Cloned from https://github.com/fish-shell/fish-shell/issues/522

function source_script --description 'Source sh/csh file'
  set -l ext
  set -l type

  while true
    switch $argv[1]
      case '--sh'
      set type sh
      case '--csh'
      set type csh
      case '--bash'
      set type bash
      case '--ext'
      set ext 1
      case '*'
      break
    end
    set -e argv[1]
  end

  if not test "$type"
    for f in $argv
      switch $f
        case '*.sh'
        set type bash
        break
        case '*.csh' '*.tcsh'
        set type csh
        break
      end
    end
  end

  set -l exe
  set -l source

  switch "$type"
    case bash
    set exe /bin/bash
    set source .
    case sh
    set exe /bin/sh
    set source .
    case csh
    set exe /bin/tcsh
    set source source
    case '*'
    echo Unknown source type for "'$argv'"
  end

  if test "$ext"
    eval "exec $exe -c '$source $argv; exec fish'"
  else
    set -l f1 (mktemp -t tmp.XXXXXXXXXX)
    set -l f2 (mktemp -t tmp.XXXXXXXXXX)
    eval $exe -c "'env | sort > $f1; $source $argv; env | sort > $f2'"

    set -l filter "(^[^\+-]|^\+\+\+|^---|^[\+-]_|^[\+-]PIPESTATUS|^[\+-]COLUMNS)"
    set -l pattern 's/[:]\{0,1\}\([^:]\+\)/"\1" /g'

    set -l IFS '='
    set -l diffopts --old-line-format '-=%L' --new-line-format '+=%L' --unchanged-line-format ''
    diff $diffopts $f1 $f2 | grep -vE $filter | while read -l state var value
      switch $state$var
        case -PATH
        continue

        case +PATH
        eval set value (echo $value | tr : ' ')
        for pt in $value
            contains $pt $PATH; and continue
            if not test -d $pt
                echo "Unable to add '$pt' to \$PATH. Check existance."
                continue
            end
            #echo set -gx PATH $PATH $pt
            set -gx PATH $PATH $pt >  /dev/null
        end

        case '-*'
        #echo unset $var
        set -e $var

        case '+*'
        eval set -gx $var (echo $value | sed $pattern)
        #echo Set $var to: (echo $value | sed $pattern)

        case '*'
        echo Source error! Invalid case "'$state$var'"
      end
    end

    rm $f1 $f2 > /dev/null
  end
end<commit_msg>source_script: Use command for external commands<commit_after># Cloned from https://github.com/fish-shell/fish-shell/issues/522

function source_script --description 'Source sh/csh file'
  set -l ext
  set -l type

  while true
    switch $argv[1]
      case '--sh'
      set type sh
      case '--csh'
      set type csh
      case '--bash'
      set type bash
      case '--ext'
      set ext 1
      case '*'
      break
    end
    set -e argv[1]
  end

  if not test "$type"
    for f in $argv
      switch $f
        case '*.sh'
        set type bash
        break
        case '*.csh' '*.tcsh'
        set type csh
        break
      end
    end
  end

  set -l exe
  set -l source

  switch "$type"
    case bash
    set exe /bin/bash
    set source .
    case sh
    set exe /bin/sh
    set source .
    case csh
    set exe /bin/tcsh
    set source source
    case '*'
    echo Unknown source type for "'$argv'"
  end

  if test "$ext"
    eval "exec $exe -c '$source $argv; exec fish'"
  else
    set -l f1 (command mktemp -t tmp.XXXXXXXXXX)
    set -l f2 (command mktemp -t tmp.XXXXXXXXXX)
    eval $exe -c "'env | sort > $f1; $source $argv; env | sort > $f2'"

    set -l filter "(^[^\+-]|^\+\+\+|^---|^[\+-]_|^[\+-]PIPESTATUS|^[\+-]COLUMNS)"
    set -l pattern 's/[:]\{0,1\}\([^:]\+\)/"\1" /g'

    set -l IFS '='
    set -l diffopts --old-line-format '-=%L' --new-line-format '+=%L' --unchanged-line-format ''
    command diff $diffopts $f1 $f2 | command grep -vE $filter | while read -l state var value
      switch $state$var
        case -PATH
        continue

        case +PATH
        eval set value (echo $value | tr : ' ')
        for pt in $value
            contains $pt $PATH; and continue
            if not test -d $pt
                echo "Unable to add '$pt' to \$PATH. Check existance."
                continue
            end
            set -gx PATH $PATH $pt >  /dev/null
        end

        case '-*'
        set -e $var

        case '+*'
        eval set -gx $var (echo $value | command sed $pattern)

        case '*'
        echo Source error! Invalid case "'$state$var'"
      end
    end

    command rm $f1 $f2 > /dev/null
  end
end
{'fraction_non_alphanumeric': 0.13811149032992037, 'fraction_numerical': 0.007736063708759955, 'mean_word_length': 1.563265306122449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '94898', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1483, 'n_words': 531}