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

85 lines
2.0 KiB
Fish
Raw Normal View History

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
set __dpaste_expires_choises '(onetime|never|hour|week|month)'
2014-06-09 06:54:21 +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
set -g __dpaste_send_url $dpaste_url
2014-06-08 17:43:22 +00:00
end
function __dpaste_send
curl -F "$dpaste_keyword=<-" $__dpaste_send_url
2014-06-09 06:54:21 +00:00
end
function __sed
set sed_extended_regexp_flag -r
switch (uname)
case *BSD
set sed_extended_regexp_flag -E
case Darwin
set sed_extended_regexp_flag -E
end
sed $sed_extended_regexp_flag $argv
end
function __dpaste_parse_expires
set expires_spec "-t $__dpaste_expires_choises"
set expires (echo $argv | __sed "s/.*$expires_spec.*/\1/" | sed 's/hour/3600/' | sed 's/week/604800/' | sed 's/month/2592000/')
if [ -z (echo $expires | __sed "s/$__dpaste_expires_choises//") ]
set __dpaste_send_url "$__dpaste_send_url&expires=$expires"
2014-06-09 06:54:21 +00:00
end
echo $argv | __sed "s/$expires_spec//" | xargs
2014-06-09 06:54:21 +00:00
end
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]
dpaste [-t EXPIRES] \"I \<3 to paste\"
2014-06-09 06:54:21 +00:00
Options:
-t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]"
2014-06-09 06:54:21 +00:00
end
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
__dpaste_set_defaults
__dpaste_parse_help $argv
2014-06-09 06:54:21 +00:00
or begin
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
end | __dpaste_send
2014-06-08 17:43:22 +00:00
else
__dpaste_help
2014-06-09 06:54:21 +00:00
end
2014-06-08 17:43:22 +00:00
else
__dpaste_send
2014-06-08 17:43:22 +00:00
end
end
end