From 4f869332cfec6562c9ce166442c3871e16556d7f Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Wed, 15 Aug 2018 20:43:40 -0400 Subject: [PATCH 1/5] color formatting added with -c --- pb | 59 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/pb b/pb index b4d23a2..c80b885 100755 --- a/pb +++ b/pb @@ -2,11 +2,12 @@ version="v.2018.08.14" ENDPOINT="https://0x0.tilde.team" -flag_options="hvfs::x" +flag_options="hvcfs::x" flag_version=0 flag_help=0 flag_file=0 flag_shortlist=0 +flag_colors=0 data="" SUCCESS=$(tput setaf 190) @@ -25,6 +26,7 @@ OPTIONAL FLAGS: -h Show this help -v Show current version number -f Explicitly interpret stdin as filename + -c Pretty color output -s server_address Use alternative pastebin server address END } @@ -68,6 +70,10 @@ while true; do flag_version=1 shift ;; + -c) + flag_colors=1 + shift + ;; -f) flag_file=1 shift @@ -95,7 +101,6 @@ if [ -z "$data" ]; then data="$*" fi - if [ ${flag_version} -gt 0 ]; then printf "%s\\n" "${version}" die "" 0 @@ -114,9 +119,17 @@ fi if [ ${flag_file} -gt 0 ]; then if [ -z "${data}" ]; then - printf "%sProvide data to upload%s\\n" "$ERROR" "$RESET" + if [ ${flag_colors} -gt 0 ]; then + printf "%sProvide data to upload%s\\n" "$ERROR" "$RESET" + else + printf "Provide data to upload\\n" + fi elif [ ! -f "${data}" ]; then - printf "%s%s%s\\tFile not found.%s\\n" "$RESET" "${data}" "$ERROR" "$RESET" + if [ ${flag_colors} -gt 0 ]; then + printf "%s%s%s\\tFile not found.%s\\n" "$RESET" "${data}" "$ERROR" "$RESET" + else + printf "%s\\tFile not found.\\n" "${data}" + fi # attempt to split data and upload each string as file for f in ${data} do @@ -124,26 +137,46 @@ if [ ${flag_file} -gt 0 ]; then if [ "$f" = "$data" ]; then break; fi - printf "%s${f}\\t%s" "$RESET" "$SUCCESS" + if [ ${flag_colors} -gt 0 ]; then + printf "%s%s\\t%s" "$RESET" "${f}" "$SUCCESS" + else + printf "%s\\t" "${f}" + fi if [ -f "${f}" ]; then curl -F"file=@${f}" "${ENDPOINT}" printf "%s" "$RESET" else - printf "%sFile not found.%s\\n" "$ERROR" "$RESET" + if [ ${flag_colors} -gt 0 ]; then + printf "%sFile not found.%s\\n" "$ERROR" "$RESET" + else + printf "File not found.\\n" + fi fi done else - printf "%s${data}\\t%s" "$RESET" "$SUCCESS" - curl -F"file=@${data}" "${ENDPOINT}" - printf "%s" "$RESET" + if [ ${flag_colors} -gt 0 ]; then + printf "%s${data}\\t%s" "$RESET" "$SUCCESS" + curl -F"file=@${data}" "${ENDPOINT}" + printf "%s" "$RESET" + else + curl -F"file=@${data}" "${ENDPOINT}" + fi fi else if [ -z "${data}" ]; then - printf "%sNo data found for upload. Please try again.%s\\n" "$ERROR" "$RESET" + if [ ${flag_colors} -gt 0 ]; then + printf "%sNo data found for upload. Please try again.%s\\n" "$ERROR" "$RESET" + else + printf "No data found for upload. Please try again.\\n" + fi else - printf "%s" "$SUCCESS" - printf "%s" "${data}" | curl -F"file=@-;filename=null.txt" "${ENDPOINT}" - printf "%s" "$RESET" + if [ ${flag_colors} -gt 0 ]; then + printf "%s" "$SUCCESS" + printf "%s" "${data}" | curl -F"file=@-;filename=null.txt" "${ENDPOINT}" + printf "%s" "$RESET" + else + printf "%s" "${data}" | curl -F"file=@-;filename=null.txt" "${ENDPOINT}" + fi fi fi From 240ec24e4be7d10d6f1e3e723f217a612f11d2f3 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Wed, 15 Aug 2018 20:46:35 -0400 Subject: [PATCH 2/5] without -c, remove extra labels --- pb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pb b/pb index c80b885..b971c06 100755 --- a/pb +++ b/pb @@ -43,7 +43,11 @@ die () { if [ "${code}" -eq 0 ]; then printf "%s\\n" "${msg}" else - printf "%s%s%s\\n" "$ERROR" "${msg}" "$RESET" >&2 + if [ ${flag_colors} -gt 0 ]; then + printf "%s%s%s\\n" "$ERROR" "${msg}" "$RESET" >&2 + else + printf "%s\\n" "${msg}" >&2 + fi fi fi exit "${code}" @@ -139,12 +143,12 @@ if [ ${flag_file} -gt 0 ]; then fi if [ ${flag_colors} -gt 0 ]; then printf "%s%s\\t%s" "$RESET" "${f}" "$SUCCESS" - else - printf "%s\\t" "${f}" fi if [ -f "${f}" ]; then curl -F"file=@${f}" "${ENDPOINT}" - printf "%s" "$RESET" + if [ ${flag_colors} -gt 0 ]; then + printf "%s" "$RESET" + fi else if [ ${flag_colors} -gt 0 ]; then printf "%sFile not found.%s\\n" "$ERROR" "$RESET" From a20eeeed0f5ef8308972d271aa4dafb68f541ed5 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Wed, 15 Aug 2018 20:48:51 -0400 Subject: [PATCH 3/5] upped version number, added dodcumentation for -c --- README.md | 1 + pb | 2 +- pb.1 | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce20e65..6d4a680 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Upload a file to a different pastebin endpoint ```bash -f Explicitly interpret stdin as filename -s server_address Use alternative pastebin server address + -c Pretty color output -v Show current version number -h Show help ``` diff --git a/pb b/pb index b971c06..6c1e7ce 100755 --- a/pb +++ b/pb @@ -1,6 +1,6 @@ #!/bin/sh -version="v.2018.08.14" +version="v.2018.08.15" ENDPOINT="https://0x0.tilde.team" flag_options="hvcfs::x" flag_version=0 diff --git a/pb.1 b/pb.1 index 18058b0..387ee4e 100644 --- a/pb.1 +++ b/pb.1 @@ -1,4 +1,4 @@ -.TH PB 1 "14 August 2018" "v2018.08.14" +.TH PB 1 "15 August 2018" "v2018.08.14" .SH NAME pb \- a helper utility for using 0x0 pastebin services .SH SYNOPSIS @@ -32,6 +32,9 @@ Explicitly interpret stdin as filename or names .B -s Use alternative pastebin server address .TP +.B -c +Pretty color output +.TP .B -v Display current version information. .TP From c737aa956ceeb5da50dbb6f1f52622da526b1072 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Wed, 15 Aug 2018 20:50:22 -0400 Subject: [PATCH 4/5] added -c to bash completion --- pb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pb b/pb index 6c1e7ce..c5aaa53 100755 --- a/pb +++ b/pb @@ -116,7 +116,7 @@ if [ ${flag_help} -gt 0 ]; then fi if [ ${flag_shortlist} -gt 0 ]; then - out="-f -v -h -s" + out="-f -v -h -s -c" lsresults="$(ls)" die "${out} ${lsresults}" 0 fi From 9da21efe2d1b18406cefac7cbcba7e09f8304b4d Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 16 Aug 2018 00:34:13 -0400 Subject: [PATCH 5/5] change url to ttm.sh --- pb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pb b/pb index c5aaa53..1b197d5 100755 --- a/pb +++ b/pb @@ -1,7 +1,7 @@ #!/bin/sh version="v.2018.08.15" -ENDPOINT="https://0x0.tilde.team" +ENDPOINT="https://ttm.sh" flag_options="hvcfs::x" flag_version=0 flag_help=0