From a58c49836228ed92cda39e053beb563ba2107364 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Sun, 8 Jun 2014 21:43:22 +0400 Subject: [PATCH 01/15] [dpaste] Add dpaste plugin --- plugins/dpaste/LICENSE | 23 +++++++++++++++++++++++ plugins/dpaste/dpaste.fish | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 plugins/dpaste/LICENSE create mode 100644 plugins/dpaste/dpaste.fish diff --git a/plugins/dpaste/LICENSE b/plugins/dpaste/LICENSE new file mode 100644 index 0000000..2bcfcd0 --- /dev/null +++ b/plugins/dpaste/LICENSE @@ -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. diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish new file mode 100644 index 0000000..ba187c3 --- /dev/null +++ b/plugins/dpaste/dpaste.fish @@ -0,0 +1,37 @@ +# Just a dpaste (https://github.com/bartTC/dpaste) wrapper for fish-shell +# Roman Inflianskas (rominf) +# Based on fish-sprunge plugin: +# Paul Joannon (paulloz) +# https://github.com/Paulloz/fish-sprunge +# Based on oh-my-zsh's sprunge plugin + +if test -z $dpaste_keyword + set dpaste_keyword content +end +if test -z $dpaste_url + set dpaste_url https://dpaste.de/api/ +end + +function dpaste_send + curl -F "$dpaste_keyword=<-" $dpaste_url 2> /dev/null | sed "s/.*\"\(.*\)\".*/\1\n/" +end + +function dpaste + if isatty + if [ (count $argv) -gt 0 ] + if [ -f $argv ] + cat $argv + else + echo $argv + end | dpaste_send + else + echo -e "Usage: + * dpaste < README.md + * dpaste README.md + * cat README.md | dpaste + * dpaste "I \<3 to paste"" + end + else + dpaste_send + end +end From 9ce45f5f38fa365f3ef813819c5b96b65e1315b3 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 9 Jun 2014 10:54:21 +0400 Subject: [PATCH 02/15] [dpaste] Add "expires" option --- plugins/dpaste/dpaste.fish | 74 ++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index ba187c3..a00ec6c 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -5,33 +5,69 @@ # https://github.com/Paulloz/fish-sprunge # Based on oh-my-zsh's sprunge plugin -if test -z $dpaste_keyword - set dpaste_keyword content -end -if test -z $dpaste_url - set dpaste_url https://dpaste.de/api/ + +set dpaste_expires_choises '(onetime|never|hour|week|month)' + +function dpaste_set_defaults + 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 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 function dpaste - if isatty - if [ (count $argv) -gt 0 ] - if [ -f $argv ] - cat $argv + dpaste_set_defaults + set -g dpaste_send_url $dpaste_url + 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 - echo $argv - end | dpaste_send + dpaste_help + end else - echo -e "Usage: - * dpaste < README.md - * dpaste README.md - * cat README.md | dpaste - * dpaste "I \<3 to paste"" + dpaste_send end - else - dpaste_send end end From 4aedc2917fd678c7cf03f1fcab403da3cd051a05 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 9 Jun 2014 11:10:57 +0400 Subject: [PATCH 03/15] [dpaste] Underscoring all private variables and functions --- plugins/dpaste/dpaste.fish | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index a00ec6c..687ee59 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -6,9 +6,9 @@ # Based on oh-my-zsh's sprunge plugin -set dpaste_expires_choises '(onetime|never|hour|week|month)' +set __dpaste_expires_choises '(onetime|never|hour|week|month)' -function dpaste_set_defaults +function __dpaste_set_defaults if [ -z $dpaste_keyword ] set -g dpaste_keyword content end @@ -17,57 +17,57 @@ function dpaste_set_defaults end end -function dpaste_send +function __dpaste_send # echo $dpaste_url >&2 - # echo $dpaste_send_url >&2 - curl -F "$dpaste_keyword=<-" $dpaste_send_url + # 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" +function __dpaste_parse_expires + set expires_spec "-t $__dpaste_expires_choises" + set expires (echo $argv | sed -r "s/.*$expires_spec.*/\1/" | sed 's/hour/3600/' | sed 's/week/604800/' | sed 's/month/2592000/') + if [ -z (echo $expires | sed -r "s/$__dpaste_expires_choises//") ] + set __dpaste_send_url "$__dpaste_send_url&expires=$expires" end echo $argv | sed -r "s/$expires_spec//" end -function dpaste_help +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" + dpaste [-t EXPIRES] \"I \<3 to paste\" Options: - -t EXPIRES set snippet expiration time: $dpaste_expires_choises [default: month]" + -t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]" end -function dpaste_parse_help +function __dpaste_parse_help if contains -- -h $argv - dpaste_help + __dpaste_help end end function dpaste - dpaste_set_defaults - set -g dpaste_send_url $dpaste_url - dpaste_parse_help $argv + __dpaste_set_defaults + set -g __dpaste_send_url $dpaste_url + __dpaste_parse_help $argv or begin - set argv (dpaste_parse_expires $argv) + set argv (__dpaste_parse_expires $argv) if isatty if [ -n $argv ] if [ -f $argv ] cat $argv else echo $argv - end | dpaste_send + end | __dpaste_send else - dpaste_help + __dpaste_help end else - dpaste_send + __dpaste_send end end end From feff0bb89d30f2d96c91e9d19bdd9957883a8b5f Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 9 Jun 2014 13:44:46 +0400 Subject: [PATCH 04/15] [dpaste] Fixed file pasting with option -t --- plugins/dpaste/dpaste.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index 687ee59..c476769 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -29,7 +29,7 @@ function __dpaste_parse_expires if [ -z (echo $expires | sed -r "s/$__dpaste_expires_choises//") ] set __dpaste_send_url "$__dpaste_send_url&expires=$expires" end - echo $argv | sed -r "s/$expires_spec//" + echo $argv | sed -r "s/$expires_spec//" | xargs end function __dpaste_help From b3d40bb35d71e435b582bd5fb00cf3c437424f1f Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 11 Jun 2014 18:25:10 +0400 Subject: [PATCH 05/15] [dpaste] Add --help alias for help --- plugins/dpaste/dpaste.fish | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index c476769..795db9c 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -10,7 +10,7 @@ set __dpaste_expires_choises '(onetime|never|hour|week|month)' function __dpaste_set_defaults if [ -z $dpaste_keyword ] - set -g dpaste_keyword content + set -g dpaste_keyword 'content' end if [ -z $dpaste_url ] set -g dpaste_url 'https://dpaste.de/api/?format=url' @@ -45,9 +45,11 @@ Options: end function __dpaste_parse_help - if contains -- -h $argv - __dpaste_help + begin + contains -- -h $argv + or contains -- --help $argv end + and __dpaste_help end function dpaste From 32c1a02690a93ed60c263583a72047c852a44f3f Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 11 Jun 2014 23:08:35 +0400 Subject: [PATCH 06/15] [dpaste] Add compatibility with non GNU *nix --- plugins/dpaste/dpaste.fish | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index 795db9c..a19c609 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -15,21 +15,31 @@ function __dpaste_set_defaults if [ -z $dpaste_url ] set -g dpaste_url 'https://dpaste.de/api/?format=url' end + set -g __dpaste_send_url $dpaste_url end function __dpaste_send - # echo $dpaste_url >&2 - # echo $__dpaste_send_url >&2 curl -F "$dpaste_keyword=<-" $__dpaste_send_url 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 -r "s/.*$expires_spec.*/\1/" | sed 's/hour/3600/' | sed 's/week/604800/' | sed 's/month/2592000/') - if [ -z (echo $expires | sed -r "s/$__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" end - echo $argv | sed -r "s/$expires_spec//" | xargs + echo $argv | __sed "s/$expires_spec//" | xargs end function __dpaste_help @@ -54,7 +64,6 @@ end function dpaste __dpaste_set_defaults - set -g __dpaste_send_url $dpaste_url __dpaste_parse_help $argv or begin set argv (__dpaste_parse_expires $argv) From 4cb653919700f9aaf7eb0eacd3144d6e54cce438 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 11 Jun 2014 23:08:51 +0400 Subject: [PATCH 07/15] [dpaste] Add tests --- plugins/dpaste/tests/helper.fish | 7 +++++++ plugins/dpaste/tests/test_dpaste.fish | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 plugins/dpaste/tests/helper.fish create mode 100755 plugins/dpaste/tests/test_dpaste.fish diff --git a/plugins/dpaste/tests/helper.fish b/plugins/dpaste/tests/helper.fish new file mode 100644 index 0000000..0ac6202 --- /dev/null +++ b/plugins/dpaste/tests/helper.fish @@ -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 diff --git a/plugins/dpaste/tests/test_dpaste.fish b/plugins/dpaste/tests/test_dpaste.fish new file mode 100755 index 0000000..163302c --- /dev/null +++ b/plugins/dpaste/tests/test_dpaste.fish @@ -0,0 +1,23 @@ +#!/usr/bin/env fish + +function suite_dpaste + function setup + set -g __dpaste_expires_choises + source ../dpaste.fish + __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 + assert_equal text (__dpaste_parse_expires -t never text) + assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url + assert_equal text (__dpaste_parse_expires -t hour 3600) + assert_equal "https://dpaste.de/api/?format=url&expires=" $__dpaste_send_url + end +end + +if not set -q tank_running + source (dirname (status -f))/helper.fish + tank_run +end From 668849a9c3b052ead6759f2b5d0f266e4653a21e Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 11 Jun 2014 23:50:29 +0400 Subject: [PATCH 08/15] [dpaste] Fix tests --- plugins/dpaste/tests/test_dpaste.fish | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/dpaste/tests/test_dpaste.fish b/plugins/dpaste/tests/test_dpaste.fish index 163302c..77daa7a 100755 --- a/plugins/dpaste/tests/test_dpaste.fish +++ b/plugins/dpaste/tests/test_dpaste.fish @@ -10,10 +10,13 @@ function suite_dpaste function test_dpaste_parse_expires assert_equal text (__dpaste_parse_expires text) assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url + set -g __dpaste_send_url $dpaste_url assert_equal text (__dpaste_parse_expires -t never text) assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url - assert_equal text (__dpaste_parse_expires -t hour 3600) - assert_equal "https://dpaste.de/api/?format=url&expires=" $__dpaste_send_url + set -g __dpaste_send_url $dpaste_url + assert_equal text (__dpaste_parse_expires -t hour text) + assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url + set -g __dpaste_send_url $dpaste_url end end From e5b7c01934e94d7512fc659cfa6b8a86fb4aa63b Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 11 Jun 2014 23:51:39 +0400 Subject: [PATCH 09/15] [dpaste] Fix hour, week, month expired snippets --- plugins/dpaste/dpaste.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index a19c609..8eeed14 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -35,8 +35,9 @@ 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/') + set expires (echo $argv | __sed "s/.*$expires_spec.*/\1/") if [ -z (echo $expires | __sed "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" end echo $argv | __sed "s/$expires_spec//" | xargs From b1b7b0a0ee146b441e712268e766889e1d4a4b91 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 11 Jun 2014 23:53:40 +0400 Subject: [PATCH 10/15] [dpaste] Using sed -E everywhere --- plugins/dpaste/dpaste.fish | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index 8eeed14..7163f47 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -22,25 +22,14 @@ function __dpaste_send curl -F "$dpaste_keyword=<-" $__dpaste_send_url 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/") - if [ -z (echo $expires | __sed "s/$__dpaste_expires_choises//") ] + 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" end - echo $argv | __sed "s/$expires_spec//" | xargs + echo $argv | sed -E "s/$expires_spec//" | xargs end function __dpaste_help From b256aac2e19f3880c6d33130db03df66571acb1c Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Fri, 15 Aug 2014 12:41:55 +0400 Subject: [PATCH 11/15] [dpaste] Allow test run with any working directory --- plugins/dpaste/tests/test_dpaste.fish | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/dpaste/tests/test_dpaste.fish b/plugins/dpaste/tests/test_dpaste.fish index 77daa7a..c4f17cf 100755 --- a/plugins/dpaste/tests/test_dpaste.fish +++ b/plugins/dpaste/tests/test_dpaste.fish @@ -1,9 +1,11 @@ #!/usr/bin/env fish +set -l script_dir (dirname (status -f)) + function suite_dpaste function setup set -g __dpaste_expires_choises - source ../dpaste.fish + source $script_dir/../dpaste.fish __dpaste_set_defaults end @@ -21,6 +23,6 @@ function suite_dpaste end if not set -q tank_running - source (dirname (status -f))/helper.fish + source $script_dir/helper.fish tank_run end From e957365d75870547abb92b6748482a349b4df5e9 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Sat, 16 Aug 2014 00:31:46 +0400 Subject: [PATCH 12/15] [dpaste] Another try to fix tests running on OS X --- plugins/dpaste/tests/test_dpaste.fish | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/dpaste/tests/test_dpaste.fish b/plugins/dpaste/tests/test_dpaste.fish index c4f17cf..1bd9fba 100755 --- a/plugins/dpaste/tests/test_dpaste.fish +++ b/plugins/dpaste/tests/test_dpaste.fish @@ -1,11 +1,7 @@ #!/usr/bin/env fish -set -l script_dir (dirname (status -f)) - function suite_dpaste function setup - set -g __dpaste_expires_choises - source $script_dir/../dpaste.fish __dpaste_set_defaults end @@ -23,6 +19,8 @@ function suite_dpaste end if not set -q tank_running - source $script_dir/helper.fish + source (dirname (status -f))/helper.fish + set -g __dpaste_expires_choises + source (dirname (status -f))/../dpaste.fish tank_run end From 36aa069f7b6864f527c6f7b774d167bd5551aacd Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Tue, 25 Nov 2014 23:47:58 +0300 Subject: [PATCH 13/15] [dpaste] Add system tests --- plugins/dpaste/tests/test_dpaste.fish | 76 +++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/plugins/dpaste/tests/test_dpaste.fish b/plugins/dpaste/tests/test_dpaste.fish index 1bd9fba..d91e764 100755 --- a/plugins/dpaste/tests/test_dpaste.fish +++ b/plugins/dpaste/tests/test_dpaste.fish @@ -1,4 +1,47 @@ #!/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 + # 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) + # 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 @@ -16,11 +59,44 @@ function suite_dpaste assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url set -g __dpaste_send_url $dpaste_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 + From bb1d149e2c2517095cbd74b84fb4c9cc008d465c Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 26 Nov 2014 01:57:14 +0300 Subject: [PATCH 14/15] [dpaste] Add time options: 1, onetime, 2, twotimes --- plugins/dpaste/dpaste.fish | 28 ++++++++++++++++++--------- plugins/dpaste/tests/test_dpaste.fish | 25 +++++++++++++++--------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index 7163f47..3ca64a3 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -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 # Roman Inflianskas (rominf) # Based on fish-sprunge plugin: @@ -6,27 +10,33 @@ # 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 - 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 + set -g __dpaste_url_dpaste_de 'https://dpaste.de/api/?format=url' + set -q dpaste_keyword; or set -g dpaste_keyword 'content' + set -q dpaste_url; or set -g dpaste_url $__dpaste_url_dpaste_de set -g __dpaste_send_url $dpaste_url end 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 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//") ] - 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" end echo $argv | sed -E "s/$expires_spec//" | xargs diff --git a/plugins/dpaste/tests/test_dpaste.fish b/plugins/dpaste/tests/test_dpaste.fish index d91e764..6944983 100755 --- a/plugins/dpaste/tests/test_dpaste.fish +++ b/plugins/dpaste/tests/test_dpaste.fish @@ -21,9 +21,6 @@ end function test_dpaste_system 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) # now it shouldn't be available curl_and_fail $url @@ -44,20 +41,30 @@ function dpaste_teardown end function suite_dpaste + function setup __dpaste_set_defaults + set -g __dpaste_send_url $__dpaste_url_dpaste_de end function test_dpaste_parse_expires assert_equal text (__dpaste_parse_expires text) assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url - set -g __dpaste_send_url $dpaste_url - assert_equal text (__dpaste_parse_expires -t never text) - assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url - set -g __dpaste_send_url $dpaste_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 - 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 function test_dpaste_system_file_redirect @@ -87,6 +94,7 @@ function suite_dpaste end test_dpaste_system dpaste_text end + end @@ -99,4 +107,3 @@ if not set -q tank_running tank_run dpaste_teardown end - From 2d363c740d8fe44372417bb9f4354eda65d66125 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 26 Nov 2014 14:01:46 +0300 Subject: [PATCH 15/15] [dpaste] Make dpaste a replacement for sprunge --- plugins/dpaste/dpaste.fish | 30 ++++++++++++++++++++++----- plugins/dpaste/tests/test_dpaste.fish | 2 +- plugins/sprunge/sprunge.fish | 1 + 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/plugins/dpaste/dpaste.fish b/plugins/dpaste/dpaste.fish index 3ca64a3..11fb562 100644 --- a/plugins/dpaste/dpaste.fish +++ b/plugins/dpaste/dpaste.fish @@ -14,9 +14,18 @@ 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 -q dpaste_keyword; or set -g dpaste_keyword 'content' - set -q dpaste_url; or set -g dpaste_url $__dpaste_url_dpaste_de - set -g __dpaste_send_url $dpaste_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 @@ -24,7 +33,7 @@ function __dpaste_send command curl --silent $argv end - curl -F "$dpaste_keyword=<-" $__dpaste_send_url | read -l url + curl -F "$__dpaste_keyword=<-" $__dpaste_send_url | read -l url if [ $__dpaste_eat_once = 1 ] curl $url >/dev/null end @@ -51,7 +60,18 @@ function __dpaste_help dpaste [-t EXPIRES] \"I \<3 to paste\" Options: - -t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]" + -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 diff --git a/plugins/dpaste/tests/test_dpaste.fish b/plugins/dpaste/tests/test_dpaste.fish index 6944983..43c2fad 100755 --- a/plugins/dpaste/tests/test_dpaste.fish +++ b/plugins/dpaste/tests/test_dpaste.fish @@ -43,8 +43,8 @@ end function suite_dpaste function setup + set dpaste_site 'dpaste.de' __dpaste_set_defaults - set -g __dpaste_send_url $__dpaste_url_dpaste_de end function test_dpaste_parse_expires diff --git a/plugins/sprunge/sprunge.fish b/plugins/sprunge/sprunge.fish index bc4b44c..d206f12 100644 --- a/plugins/sprunge/sprunge.fish +++ b/plugins/sprunge/sprunge.fish @@ -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 ]