mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-11-04 09:01:56 +00:00 
			
		
		
		
	Add initial version of curl plugin
This commit is contained in:
		
							
								
								
									
										21
									
								
								plugins/curl.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								plugins/curl.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
function tempdir()
 | 
			
		||||
    local stream = assert(io.popen('mktemp --directory'))
 | 
			
		||||
    local output = stream:read('*all')
 | 
			
		||||
    stream:close()
 | 
			
		||||
    return string.gsub(output, "\n", "")
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function preprocess(path_or_url)
 | 
			
		||||
    filename_from_url = string.match(path_or_url, '^https?://.*/(.*)$')
 | 
			
		||||
    if filename_from_url then
 | 
			
		||||
        local temp_directory = tempdir()
 | 
			
		||||
        local new_path = temp_directory .. "/" .. filename_from_url
 | 
			
		||||
 | 
			
		||||
        -- TODO: how to prevent shell injection bugs?
 | 
			
		||||
        os.execute("curl --silent '" .. path_or_url .. "' --output '" .. new_path .. "'")
 | 
			
		||||
 | 
			
		||||
        return new_path
 | 
			
		||||
    else
 | 
			
		||||
        return path_or_url
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
		Reference in New Issue
	
	Block a user