2014-11-26 06:57:14 +08:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
# vim: ai ts=2 sw=2 et sts=2
|
|
|
|
|
|
|
|
|
2014-06-09 01:43:22 +08: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 14:54:21 +08:00
|
|
|
|
2014-11-26 06:57:14 +08:00
|
|
|
set __dpaste_expires_choises '(onetime|1|twotimes|2|hour|week|month|never)'
|
2014-06-09 14:54:21 +08:00
|
|
|
|
2014-06-09 15:10:57 +08:00
|
|
|
function __dpaste_set_defaults
|
2014-11-26 06:57:14 +08:00
|
|
|
set -g __dpaste_url_dpaste_de 'https://dpaste.de/api/?format=url'
|
|
|
|
set -q dpaste_keyword; or set -g dpaste_keyword 'content'
|
|
|
|
set -q dpaste_url; or set -g dpaste_url $__dpaste_url_dpaste_de
|
2014-06-12 03:08:35 +08:00
|
|
|
set -g __dpaste_send_url $dpaste_url
|
2014-06-09 01:43:22 +08:00
|
|
|
end
|
|
|
|
|
2014-06-09 15:10:57 +08:00
|
|
|
function __dpaste_send
|
2014-11-26 06:57:14 +08:00
|
|
|
function curl
|
|
|
|
command curl --silent $argv
|
|
|
|
end
|
|
|
|
|
|
|
|
curl -F "$dpaste_keyword=<-" $__dpaste_send_url | read -l url
|
|
|
|
if [ $__dpaste_eat_once = 1 ]
|
|
|
|
curl $url >/dev/null
|
|
|
|
end
|
|
|
|
echo $url
|
2014-06-09 14:54:21 +08:00
|
|
|
end
|
|
|
|
|
2014-06-09 15:10:57 +08:00
|
|
|
function __dpaste_parse_expires
|
|
|
|
set expires_spec "-t $__dpaste_expires_choises"
|
2014-06-12 03:53:40 +08:00
|
|
|
set expires (echo $argv | sed -E "s/.*$expires_spec.*/\1/")
|
|
|
|
if [ -z (echo $expires | sed -E "s/$__dpaste_expires_choises//") ]
|
2014-11-26 06:57:14 +08:00
|
|
|
echo $expires | grep -qE '(onetime|1)'; set -g __dpaste_eat_once (and echo 1; or echo 0)
|
|
|
|
set expires (echo $expires | sed -E 's/(1|2|twotimes)/onetime/;s/hour/3600/;s/week/604800/;s/month/2592000/')
|
2014-06-09 15:10:57 +08:00
|
|
|
set __dpaste_send_url "$__dpaste_send_url&expires=$expires"
|
2014-06-09 14:54:21 +08:00
|
|
|
end
|
2014-06-12 03:53:40 +08:00
|
|
|
echo $argv | sed -E "s/$expires_spec//" | xargs
|
2014-06-09 14:54:21 +08:00
|
|
|
end
|
|
|
|
|
2014-06-09 15:10:57 +08:00
|
|
|
function __dpaste_help
|
2014-06-09 14:54:21 +08:00
|
|
|
echo -e \
|
|
|
|
"Usage:
|
|
|
|
dpaste [-t EXPIRES] < README.md
|
|
|
|
dpaste [-t EXPIRES] README.md
|
|
|
|
cat README.md | dpaste [-t EXPIRES]
|
2014-06-09 15:10:57 +08:00
|
|
|
dpaste [-t EXPIRES] \"I \<3 to paste\"
|
2014-06-09 14:54:21 +08:00
|
|
|
|
|
|
|
Options:
|
2014-06-09 15:10:57 +08:00
|
|
|
-t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]"
|
2014-06-09 14:54:21 +08:00
|
|
|
end
|
|
|
|
|
2014-06-09 15:10:57 +08:00
|
|
|
function __dpaste_parse_help
|
2014-06-11 22:25:10 +08:00
|
|
|
begin
|
|
|
|
contains -- -h $argv
|
|
|
|
or contains -- --help $argv
|
2014-06-09 14:54:21 +08:00
|
|
|
end
|
2014-06-11 22:25:10 +08:00
|
|
|
and __dpaste_help
|
2014-06-09 01:43:22 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function dpaste
|
2014-06-09 15:10:57 +08:00
|
|
|
__dpaste_set_defaults
|
|
|
|
__dpaste_parse_help $argv
|
2014-06-09 14:54:21 +08:00
|
|
|
or begin
|
2014-06-09 15:10:57 +08:00
|
|
|
set argv (__dpaste_parse_expires $argv)
|
2014-06-09 14:54:21 +08:00
|
|
|
if isatty
|
|
|
|
if [ -n $argv ]
|
|
|
|
if [ -f $argv ]
|
|
|
|
cat $argv
|
|
|
|
else
|
|
|
|
echo $argv
|
2014-06-09 15:10:57 +08:00
|
|
|
end | __dpaste_send
|
2014-06-09 01:43:22 +08:00
|
|
|
else
|
2014-06-09 15:10:57 +08:00
|
|
|
__dpaste_help
|
2014-06-09 14:54:21 +08:00
|
|
|
end
|
2014-06-09 01:43:22 +08:00
|
|
|
else
|
2014-06-09 15:10:57 +08:00
|
|
|
__dpaste_send
|
2014-06-09 01:43:22 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|