Skip to content

Instantly share code, notes, and snippets.

@IvanShamatov
Created February 20, 2020 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanShamatov/d88626ee7df349b34ed3e9671dc1d726 to your computer and use it in GitHub Desktop.
Save IvanShamatov/d88626ee7df349b34ed3e9671dc1d726 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'resolv'
require 'uri'
def filter_arguments(line)
line.gsub(/(\S+)=\S+/, '\1=[FILTERED_VALUE]')
end
def filter_ip_v4_addresses(line)
line.gsub(Resolv::IPv4::Regex, '[FILTERED_IP]')
end
def filter_ip_v6_addresses(line)
line.gsub(Resolv::IPv6::Regex, '[FILTERED_IP]')
end
def filter_urls(line)
line.gsub(URI::DEFAULT_PARSER.make_regexp, '[FILTERED_URI]')
end
def filter_emails(line)
line.gsub(URI::MailTo::EMAIL_REGEXP, '[FILTERED_EMAIL]')
end
def history_files
%w[.bash_history .zsh_history].map do |file|
history_file = File.join(ENV['HOME'], file)
File.read(history_file) if File.exists?(history_file)
end
end
history_files.each do |file|
file.each_line do |line|
line = filter_arguments(line)
line = filter_ip_v4_addresses(line)
line = filter_ip_v6_addresses(line)
line = filter_urls(line)
line = filter_emails(line)
puts line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment