Merge pull request #170 from rominf/dpaste

pull/2/head
Bruno Pinto 10 years ago
commit c56d016f7d

@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright (c) 2014 Roman Inflianskas
Copyright (c) 2014 Paul Joannon (sprunge.fish)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,104 @@
#!/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
# 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
set __dpaste_expires_choises '(onetime|1|twotimes|2|hour|week|month|never)'
function __dpaste_set_defaults
set -g __dpaste_url_dpaste_de 'https://dpaste.de/api/?format=url'
set -g __dpaste_keyword_dpaste_de 'content'
set -g __dpaste_url_sprunge_us 'http://sprunge.us/'
set -g __dpaste_keyword_sprunge_us 'sprunge'
set -q dpaste_site; or set -g dpaste_site 'dpaste.de'
set suffix (echo $dpaste_site | sed "s/\./_/g")
set -g __dpaste_keyword (eval 'echo $__dpaste_keyword_'$suffix)
set -q __dpaste_keyword; or set -g __dpaste_keyword $__dpaste_keyword_dpaste_de
set -g __dpaste_send_url (eval 'echo $__dpaste_url_'$suffix)
set -q __dpaste_send_url; or set -g __dpaste_send_url $__dpaste_url_dpaste_de
set -g __dpaste_eat_once 0
end
function __dpaste_send
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
function __dpaste_parse_expires
set expires_spec "-t $__dpaste_expires_choises"
set expires (echo $argv | sed -E "s/.*$expires_spec.*/\1/")
if [ -z (echo $expires | sed -E "s/$__dpaste_expires_choises//") ]
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"
end
echo $argv | sed -E "s/$expires_spec//" | xargs
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]
Configuration:
You can use this plugin with other dpaste instances.
If you have a dpaste instance on 'example.com' just insert those lines
into your config.fish file:
set __dpaste_url_example_com 'https://example.com/api/?format=url'
set dpaste_site 'example.com'
You can even use this plugin with sprunge.us.
Note, that sprunge.us doesn't support '-t' option.
set dpaste_site 'sprunge.us'"
end
function __dpaste_parse_help
begin
contains -- -h $argv
or contains -- --help $argv
end
and __dpaste_help
end
function dpaste
__dpaste_set_defaults
__dpaste_parse_help $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
__dpaste_help
end
else
__dpaste_send
end
end
end

@ -0,0 +1,7 @@
set -l fish_tank /usr/local/share/fish-tank/tank.fish
if not test -e $fish_tank
echo 'error: fish-tank is required to run these tests (https://github.com/terlar/fish-tank)'
exit 1
end
source $fish_tank

@ -0,0 +1,109 @@
#!/usr/bin/env fish
# vim: ai ts=2 sw=2 et sts=2
function echo_text
set -g __test_text 'Hello, tests! I am just testing suite for oh-my-fish plugin: https://github.com/bpinto/oh-my-fish/pull/170'
echo -e $__test_text
end
function curl
command curl --silent $argv
end
function curl_and_check
assert_equal $argv[2..-1] (curl $argv[1])
end
function curl_and_fail
assert_match '.*404 Not found.*' (curl $argv[1])
end
function test_dpaste_system
set url (eval $argv[1])/raw
curl_and_check $url (echo_text)
# now it shouldn't be available
curl_and_fail $url
end
function dpaste_setup
set -g test_dir /tmp/dpaste_test
set -g test_file $test_dir/file
mkdir -p $test_dir
pushd
cd $test_dir
echo_text > $test_file
end
function dpaste_teardown
rm -rf $test_dir
popd
end
function suite_dpaste
function setup
set dpaste_site 'dpaste.de'
__dpaste_set_defaults
end
function test_dpaste_parse_expires
assert_equal text (__dpaste_parse_expires text)
assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
end
function test_dpaste_parse_expires_1
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 "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_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
function test_dpaste_system_file_redirect
function dpaste_file_redirect
dpaste -t onetime < /tmp/dpaste_test/file
end
test_dpaste_system dpaste_file_redirect
end
function test_dpaste_system_file
function dpaste_file
dpaste -t onetime /tmp/dpaste_test/file
end
test_dpaste_system dpaste_file
end
function test_dpaste_system_stdin
function dpaste_stdin
echo_text | dpaste -t onetime
end
test_dpaste_system dpaste_stdin
end
function test_dpaste_system_text
function dpaste_text
dpaste -t onetime "$__test_text"
end
test_dpaste_system dpaste_text
end
end
if not set -q tank_running
source (dirname (status -f))/helper.fish
set -g __dpaste_expires_choises
source (dirname (status -f))/../dpaste.fish
dpaste_setup
tank_run
dpaste_teardown
end

@ -4,6 +4,7 @@
# Based on oh-my-zsh's sprunge plugin
function sprunge
echo -e 'This plugin is obsolete.\nConsider using dpaste, it is tested, has more features, and supports different sites, including sprunge.\nFor more information, enable dpaste plugin and execute it:\n$ dpaste\n' >&2
if isatty
if [ (count $argv) -gt 0 ]
if [ -f $argv ]

Loading…
Cancel
Save