784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
|
# File 'lib/na/next_action.rb', line 784
def delete_search(strings = nil)
NA.notify('{r}Name search required', exit_code: 1) if strings.nil? || strings.empty?
file = database_path(file: 'saved_searches.yml')
NA.notify('{r}No search definitions file found', exit_code: 1) unless File.exist?(file)
searches = YAML.safe_load(file.read_file)
keys = searches.keys.delete_if { |k| k !~ /(#{strings.join('|')})/ }
res = yn(NA::Color.template(%({y}Remove #{keys.count > 1 ? 'searches' : 'search'} {bw}"#{keys.join(', ')}"{x})),
default: false)
NA.notify('{r}Cancelled', exit_code: 1) unless res
searches.delete_if { |k| keys.include?(k) }
File.open(file, 'w') { |f| f.puts(YAML.dump(searches)) }
NA.notify("{y}Deleted {bw}#{keys.count}{xy} #{keys.count > 1 ? 'searches' : 'search'}", exit_code: 0)
end
|