2014-06-08 17:43:22 +00:00
|
|
|
# Just a dpaste (https://github.com/bartTC/dpaste) wrapper for fish-shell
|
|
|
|
# Roman Inflianskas (rominf) <infroma@gmail.com>
|
|
|
|
# Based on fish-sprunge plugin:
|
|
|
|
# Paul Joannon (paulloz) <paul.joannon@gmail.com>
|
|
|
|
# https://github.com/Paulloz/fish-sprunge
|
|
|
|
# Based on oh-my-zsh's sprunge plugin
|
|
|
|
|
2014-06-09 06:54:21 +00:00
|
|
|
|
2014-06-09 07:10:57 +00:00
|
|
|
set __dpaste_expires_choises '(onetime|never|hour|week|month)'
|
2014-06-09 06:54:21 +00:00
|
|
|
|
2014-06-09 07:10:57 +00:00
|
|
|
function __dpaste_set_defaults
|
2014-06-09 06:54:21 +00:00
|
|
|
if [ -z $dpaste_keyword ]
|
2014-06-11 14:25:10 +00:00
|
|
|
set -g dpaste_keyword 'content'
|
2014-06-09 06:54:21 +00:00
|
|
|
end
|
|
|
|
if [ -z $dpaste_url ]
|
|
|
|
set -g dpaste_url 'https://dpaste.de/api/?format=url'
|
|
|
|
end
|
2014-06-11 19:08:35 +00:00
|
|
|
set -g __dpaste_send_url $dpaste_url
|
2014-06-08 17:43:22 +00:00
|
|
|
end
|
|
|
|
|
2014-06-09 07:10:57 +00:00
|
|
|
function __dpaste_send
|
|
|
|
curl -F "$dpaste_keyword=<-" $__dpaste_send_url
|
2014-06-09 06:54:21 +00:00
|
|
|
end
|
|
|
|
|
2014-06-09 07:10:57 +00:00
|
|
|
function __dpaste_parse_expires
|
|
|
|
set expires_spec "-t $__dpaste_expires_choises"
|
2014-06-11 19:53:40 +00:00
|
|
|
set expires (echo $argv | sed -E "s/.*$expires_spec.*/\1/")
|
|
|
|
if [ -z (echo $expires | sed -E "s/$__dpaste_expires_choises//") ]
|
2014-06-11 19:51:39 +00:00
|
|
|
set expires (echo $expires | sed 's/hour/3600/' | sed 's/week/604800/' | sed 's/month/2592000/')
|
2014-06-09 07:10:57 +00:00
|
|
|
set __dpaste_send_url "$__dpaste_send_url&expires=$expires"
|
2014-06-09 06:54:21 +00:00
|
|
|
end
|
2014-06-11 19:53:40 +00:00
|
|
|
echo $argv | sed -E "s/$expires_spec//" | xargs
|
2014-06-09 06:54:21 +00:00
|
|
|
end
|
|
|
|
|
2014-06-09 07:10:57 +00:00
|
|
|
function __dpaste_help
|
2014-06-09 06:54:21 +00:00
|
|
|
echo -e \
|
|
|
|
"Usage:
|
|
|
|
dpaste [-t EXPIRES] < README.md
|
|
|
|
dpaste [-t EXPIRES] README.md
|
|
|
|
cat README.md | dpaste [-t EXPIRES]
|
2014-06-09 07:10:57 +00:00
|
|
|
dpaste [-t EXPIRES] \"I \<3 to paste\"
|
2014-06-09 06:54:21 +00:00
|
|
|
|
|
|
|
Options:
|
2014-06-09 07:10:57 +00:00
|
|
|
-t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]"
|
2014-06-09 06:54:21 +00:00
|
|
|
end
|
|
|
|
|
2014-06-09 07:10:57 +00:00
|
|
|
function __dpaste_parse_help
|
2014-06-11 14:25:10 +00:00
|
|
|
begin
|
|
|
|
contains -- -h $argv
|
|
|
|
or contains -- --help $argv
|
2014-06-09 06:54:21 +00:00
|
|
|
end
|
2014-06-11 14:25:10 +00:00
|
|
|
and __dpaste_help
|
2014-06-08 17:43:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function dpaste
|
2014-06-09 07:10:57 +00:00
|
|
|
__dpaste_set_defaults
|
|
|
|
__dpaste_parse_help $argv
|
2014-06-09 06:54:21 +00:00
|
|
|
or begin
|
2014-06-09 07:10:57 +00:00
|
|
|
set argv (__dpaste_parse_expires $argv)
|
2014-06-09 06:54:21 +00:00
|
|
|
if isatty
|
|
|
|
if [ -n $argv ]
|
|
|
|
if [ -f $argv ]
|
|
|
|
cat $argv
|
|
|
|
else
|
|
|
|
echo $argv
|
2014-06-09 07:10:57 +00:00
|
|
|
end | __dpaste_send
|
2014-06-08 17:43:22 +00:00
|
|
|
else
|
2014-06-09 07:10:57 +00:00
|
|
|
__dpaste_help
|
2014-06-09 06:54:21 +00:00
|
|
|
end
|
2014-06-08 17:43:22 +00:00
|
|
|
else
|
2014-06-09 07:10:57 +00:00
|
|
|
__dpaste_send
|
2014-06-08 17:43:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|