oh-my-fish/plugins/dpaste/dpaste.fish

75 lines
1.8 KiB
Fish
Raw Normal View History

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
set __dpaste_expires_choises '(onetime|never|hour|week|month)'
2014-06-09 14:54:21 +08:00
function __dpaste_set_defaults
2014-06-09 14:54:21 +08:00
if [ -z $dpaste_keyword ]
2014-06-11 22:25:10 +08:00
set -g dpaste_keyword 'content'
2014-06-09 14:54:21 +08:00
end
if [ -z $dpaste_url ]
set -g dpaste_url 'https://dpaste.de/api/?format=url'
end
set -g __dpaste_send_url $dpaste_url
2014-06-09 01:43:22 +08:00
end
function __dpaste_send
curl -F "$dpaste_keyword=<-" $__dpaste_send_url
2014-06-09 14:54:21 +08:00
end
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//") ]
set expires (echo $expires | sed 's/hour/3600/' | sed 's/week/604800/' | sed 's/month/2592000/')
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
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]
dpaste [-t EXPIRES] \"I \<3 to paste\"
2014-06-09 14:54:21 +08:00
Options:
-t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]"
2014-06-09 14:54:21 +08:00
end
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
__dpaste_set_defaults
__dpaste_parse_help $argv
2014-06-09 14:54:21 +08:00
or begin
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
end | __dpaste_send
2014-06-09 01:43:22 +08:00
else
__dpaste_help
2014-06-09 14:54:21 +08:00
end
2014-06-09 01:43:22 +08:00
else
__dpaste_send
2014-06-09 01:43:22 +08:00
end
end
end