diff --git a/plugins/filepicker/filepicker.plugin.zsh b/plugins/filepicker/filepicker.plugin.zsh new file mode 100644 index 000000000..70b8804f0 --- /dev/null +++ b/plugins/filepicker/filepicker.plugin.zsh @@ -0,0 +1,2 @@ +#!/bin/zsh +alias filepicker=$ZSH/plugins/filepicker/filepicker.rb \ No newline at end of file diff --git a/plugins/filepicker/filepicker.rb b/plugins/filepicker/filepicker.rb new file mode 100755 index 000000000..9f9f9f230 --- /dev/null +++ b/plugins/filepicker/filepicker.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +require 'rubygems' + +# check required gems +['json'].each do |gem| + begin + require gem + rescue LoadError + puts "You need to install #{gem}: gem install #{gem}" + exit!(1) + end +end + +# read api key +config_file = "#{ENV['HOME']}/.filepicker" +unless File.exist?(config_file) + puts "You need to type your API key " + config_file + exit!(1) +end +api_key = File.read(config_file) + +# checking input file +if ARGV[0].nil? + puts "You need to specify a file to upload." + exit!(1) +end + +# upload +file_name = ARGV[0] +json_return = `curl -s -F fileUpload=@#{file_name} 'https://www.filepicker.io/api/store/S3?key=#{api_key}&filename=#{file_name}'` +url = JSON.parse(json_return)['url'] + +# output to consle the link +puts url + +# copy to mac clipboard +`echo #{url} | pbcopy` \ No newline at end of file