mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-03 15:40:32 +00:00
[dpaste] Add time options: 1, onetime, 2, twotimes
This commit is contained in:
parent
36aa069f7b
commit
bb1d149e2c
@ -1,3 +1,7 @@
|
|||||||
|
#!/usr/bin/env fish
|
||||||
|
# vim: ai ts=2 sw=2 et sts=2
|
||||||
|
|
||||||
|
|
||||||
# Just a dpaste (https://github.com/bartTC/dpaste) wrapper for fish-shell
|
# Just a dpaste (https://github.com/bartTC/dpaste) wrapper for fish-shell
|
||||||
# Roman Inflianskas (rominf) <infroma@gmail.com>
|
# Roman Inflianskas (rominf) <infroma@gmail.com>
|
||||||
# Based on fish-sprunge plugin:
|
# Based on fish-sprunge plugin:
|
||||||
@ -6,27 +10,33 @@
|
|||||||
# Based on oh-my-zsh's sprunge plugin
|
# Based on oh-my-zsh's sprunge plugin
|
||||||
|
|
||||||
|
|
||||||
set __dpaste_expires_choises '(onetime|never|hour|week|month)'
|
set __dpaste_expires_choises '(onetime|1|twotimes|2|hour|week|month|never)'
|
||||||
|
|
||||||
function __dpaste_set_defaults
|
function __dpaste_set_defaults
|
||||||
if [ -z $dpaste_keyword ]
|
set -g __dpaste_url_dpaste_de 'https://dpaste.de/api/?format=url'
|
||||||
set -g dpaste_keyword 'content'
|
set -q dpaste_keyword; or set -g dpaste_keyword 'content'
|
||||||
end
|
set -q dpaste_url; or set -g dpaste_url $__dpaste_url_dpaste_de
|
||||||
if [ -z $dpaste_url ]
|
|
||||||
set -g dpaste_url 'https://dpaste.de/api/?format=url'
|
|
||||||
end
|
|
||||||
set -g __dpaste_send_url $dpaste_url
|
set -g __dpaste_send_url $dpaste_url
|
||||||
end
|
end
|
||||||
|
|
||||||
function __dpaste_send
|
function __dpaste_send
|
||||||
curl -F "$dpaste_keyword=<-" $__dpaste_send_url
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
function __dpaste_parse_expires
|
function __dpaste_parse_expires
|
||||||
set expires_spec "-t $__dpaste_expires_choises"
|
set expires_spec "-t $__dpaste_expires_choises"
|
||||||
set expires (echo $argv | sed -E "s/.*$expires_spec.*/\1/")
|
set expires (echo $argv | sed -E "s/.*$expires_spec.*/\1/")
|
||||||
if [ -z (echo $expires | sed -E "s/$__dpaste_expires_choises//") ]
|
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/')
|
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/')
|
||||||
set __dpaste_send_url "$__dpaste_send_url&expires=$expires"
|
set __dpaste_send_url "$__dpaste_send_url&expires=$expires"
|
||||||
end
|
end
|
||||||
echo $argv | sed -E "s/$expires_spec//" | xargs
|
echo $argv | sed -E "s/$expires_spec//" | xargs
|
||||||
|
@ -21,9 +21,6 @@ end
|
|||||||
|
|
||||||
function test_dpaste_system
|
function test_dpaste_system
|
||||||
set url (eval $argv[1])/raw
|
set url (eval $argv[1])/raw
|
||||||
# everything is correct:
|
|
||||||
# one time snippets are available twice if you use curl
|
|
||||||
curl_and_check $url (echo_text)
|
|
||||||
curl_and_check $url (echo_text)
|
curl_and_check $url (echo_text)
|
||||||
# now it shouldn't be available
|
# now it shouldn't be available
|
||||||
curl_and_fail $url
|
curl_and_fail $url
|
||||||
@ -44,20 +41,30 @@ function dpaste_teardown
|
|||||||
end
|
end
|
||||||
|
|
||||||
function suite_dpaste
|
function suite_dpaste
|
||||||
|
|
||||||
function setup
|
function setup
|
||||||
__dpaste_set_defaults
|
__dpaste_set_defaults
|
||||||
|
set -g __dpaste_send_url $__dpaste_url_dpaste_de
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_dpaste_parse_expires
|
function test_dpaste_parse_expires
|
||||||
assert_equal text (__dpaste_parse_expires text)
|
assert_equal text (__dpaste_parse_expires text)
|
||||||
assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
|
assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
|
||||||
set -g __dpaste_send_url $dpaste_url
|
end
|
||||||
assert_equal text (__dpaste_parse_expires -t never text)
|
|
||||||
assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url
|
function test_dpaste_parse_expires_1
|
||||||
set -g __dpaste_send_url $dpaste_url
|
assert_equal text (__dpaste_parse_expires -t 1 text)
|
||||||
|
assert_equal "https://dpaste.de/api/?format=url&expires=onetime" $__dpaste_send_url
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_dpaste_parse_expires_hour
|
||||||
assert_equal text (__dpaste_parse_expires -t hour text)
|
assert_equal text (__dpaste_parse_expires -t hour text)
|
||||||
assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url
|
assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url
|
||||||
set -g __dpaste_send_url $dpaste_url
|
end
|
||||||
|
|
||||||
|
function test_dpaste_parse_expires_never
|
||||||
|
assert_equal text (__dpaste_parse_expires -t never text)
|
||||||
|
assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_dpaste_system_file_redirect
|
function test_dpaste_system_file_redirect
|
||||||
@ -87,6 +94,7 @@ function suite_dpaste
|
|||||||
end
|
end
|
||||||
test_dpaste_system dpaste_text
|
test_dpaste_system dpaste_text
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -99,4 +107,3 @@ if not set -q tank_running
|
|||||||
tank_run
|
tank_run
|
||||||
dpaste_teardown
|
dpaste_teardown
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user