<commit_before>require "fileutils"
require "pathname"

module HFAM
  module Command
    class Source < Base

      def run(command)
        src  = command[1]

        ::HFAM::Logger.error("No such file or directory: #{src}") and return unless File.exist? src

        # preprend the dest file with a '.' if the src file is not a hidden file 
        file = src.split('/').last
        file = ::FileUtils.hidden_file?(file) ? file : ".#{file}"
        dest = command[2] || "#{::HFAM::HOME}/#{file}"

        # https://wiki.ubuntu.com/DashAsBinSh#My_production_system_has_broken_and_I_just_want_to_get_it_back_up.21
        # Sometime the default shell /bin/sh is a symlink to another shell
        # Pathname#realpath permits to get the target of a symlink 
        real_shell_path = ::Pathname.new(ENV['SHELL']).realpath.to_s

        # /bin/dash doesn't implement the builtin 'source'. Instead, it uses the '.' command
        cmd = real_shell_path.split('/').last == "dash" ? '.' : "source"

        (cmd = "#{real_shell_path} -c '#{cmd} #{dest}'") && result = `#{cmd}`

        ::HFAM::Logger.success("Source: Command result: #{result}")
        ::HFAM::Logger.success("Source: #{cmd}")

      rescue ::Errno::EACCES => e
        l::HFAM::Logger.error("Unable to source #{dest} (Permission Denied)")
      end

    end
  end
end<commit_msg>fix(comments): fix typo in command/source.rb<commit_after>require "fileutils"
require "pathname"

module HFAM
  module Command
    class Source < Base

      def run(command)
        src  = command[1]

        ::HFAM::Logger.error("No such file or directory: #{src}") and return unless File.exist? src

        # preprend the dest file with a '.' if the src file is not a hidden file 
        file = src.split('/').last
        file = ::FileUtils.hidden_file?(file) ? file : ".#{file}"
        dest = command[2] || "#{::HFAM::HOME}/#{file}"

        # https://wiki.ubuntu.com/DashAsBinSh#My_production_system_has_broken_and_I_just_want_to_get_it_back_up.21
        # Sometime the default shell /bin/sh is a symlink to another shell
        # Pathname#realpath permits to reach the target of a symlink 
        real_shell_path = ::Pathname.new(ENV['SHELL']).realpath.to_s

        # /bin/dash doesn't implement the builtin 'source'. Instead, it uses the '.' command
        cmd = real_shell_path.split('/').last == "dash" ? '.' : "source"

        (cmd = "#{real_shell_path} -c '#{cmd} #{dest}'") && result = `#{cmd}`

        ::HFAM::Logger.success("Source: Command result: #{result}")
        ::HFAM::Logger.success("Source: #{cmd}")

      rescue ::Errno::EACCES => e
        l::HFAM::Logger.error("Unable to source #{dest} (Permission Denied)")
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.14968738506803972, 'fraction_numerical': 0.002942258183155572, 'mean_word_length': 2.9477503628447024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '745600', 'n_tokens_mistral': 895, 'n_tokens_neox': 866, 'n_words': 231}