mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-03 15:40:32 +00:00
[dpaste] Add "expires" option
This commit is contained in:
parent
a58c498362
commit
9ce45f5f38
@ -5,33 +5,69 @@
|
|||||||
# https://github.com/Paulloz/fish-sprunge
|
# https://github.com/Paulloz/fish-sprunge
|
||||||
# Based on oh-my-zsh's sprunge plugin
|
# Based on oh-my-zsh's sprunge plugin
|
||||||
|
|
||||||
if test -z $dpaste_keyword
|
|
||||||
set dpaste_keyword content
|
set dpaste_expires_choises '(onetime|never|hour|week|month)'
|
||||||
end
|
|
||||||
if test -z $dpaste_url
|
function dpaste_set_defaults
|
||||||
set dpaste_url https://dpaste.de/api/
|
if [ -z $dpaste_keyword ]
|
||||||
|
set -g dpaste_keyword content
|
||||||
|
end
|
||||||
|
if [ -z $dpaste_url ]
|
||||||
|
set -g dpaste_url 'https://dpaste.de/api/?format=url'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function dpaste_send
|
function dpaste_send
|
||||||
curl -F "$dpaste_keyword=<-" $dpaste_url 2> /dev/null | sed "s/.*\"\(.*\)\".*/\1\n/"
|
# echo $dpaste_url >&2
|
||||||
|
# echo $dpaste_send_url >&2
|
||||||
|
curl -F "$dpaste_keyword=<-" $dpaste_send_url
|
||||||
|
end
|
||||||
|
|
||||||
|
function dpaste_parse_expires
|
||||||
|
set expires_spec "-t $dpaste_expires_choises"
|
||||||
|
set dpaste_expires (echo $argv | sed -r "s/.*$expires_spec.*/\1/" | sed 's/hour/3600/' | sed 's/week/604800/' | sed 's/month/2592000/')
|
||||||
|
if [ -z (echo $dpaste_expires | sed -r "s/$dpaste_expires_choises//") ]
|
||||||
|
set dpaste_send_url "$dpaste_send_url&expires=$dpaste_expires"
|
||||||
|
end
|
||||||
|
echo $argv | sed -r "s/$expires_spec//"
|
||||||
|
end
|
||||||
|
|
||||||
|
function dpaste_help
|
||||||
|
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"
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-t EXPIRES set snippet expiration time: $dpaste_expires_choises [default: month]"
|
||||||
|
end
|
||||||
|
|
||||||
|
function dpaste_parse_help
|
||||||
|
if contains -- -h $argv
|
||||||
|
dpaste_help
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function dpaste
|
function dpaste
|
||||||
if isatty
|
dpaste_set_defaults
|
||||||
if [ (count $argv) -gt 0 ]
|
set -g dpaste_send_url $dpaste_url
|
||||||
if [ -f $argv ]
|
dpaste_parse_help $argv
|
||||||
cat $argv
|
or begin
|
||||||
|
set argv (dpaste_parse_expires $argv)
|
||||||
|
if isatty
|
||||||
|
if [ -n $argv ]
|
||||||
|
if [ -f $argv ]
|
||||||
|
cat $argv
|
||||||
|
else
|
||||||
|
echo $argv
|
||||||
|
end | dpaste_send
|
||||||
else
|
else
|
||||||
echo $argv
|
dpaste_help
|
||||||
end | dpaste_send
|
end
|
||||||
else
|
else
|
||||||
echo -e "Usage:
|
dpaste_send
|
||||||
* dpaste < README.md
|
|
||||||
* dpaste README.md
|
|
||||||
* cat README.md | dpaste
|
|
||||||
* dpaste "I \<3 to paste""
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
dpaste_send
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user