Merge branch 'master' of tildeverse.org:tomasino/pb

* 'master' of tildeverse.org:tomasino/pb:
  change url to ttm.sh
  added -c to bash completion
  upped version number, added dodcumentation for -c
  without -c, remove extra labels
  color formatting added with -c
This commit is contained in:
James Tomasino 2018-08-16 12:49:24 -04:00
commit 79bda6971e
3 changed files with 60 additions and 18 deletions

View File

@ -38,6 +38,7 @@ Upload a file to a different pastebin endpoint
```bash ```bash
-f Explicitly interpret stdin as filename -f Explicitly interpret stdin as filename
-s server_address Use alternative pastebin server address -s server_address Use alternative pastebin server address
-c Pretty color output
-v Show current version number -v Show current version number
-h Show help -h Show help
``` ```

72
pb
View File

@ -1,12 +1,13 @@
#!/bin/sh #!/bin/sh
version="v.2018.08.14" version="v.2018.08.15"
ENDPOINT="https://0x0.tilde.team" ENDPOINT="https://ttm.sh"
flag_options="hvfs::x" flag_options="hvcfs::x"
flag_version=0 flag_version=0
flag_help=0 flag_help=0
flag_file=0 flag_file=0
flag_shortlist=0 flag_shortlist=0
flag_colors=0
data="" data=""
SUCCESS=$(tput setaf 190) SUCCESS=$(tput setaf 190)
@ -25,6 +26,7 @@ OPTIONAL FLAGS:
-h Show this help -h Show this help
-v Show current version number -v Show current version number
-f Explicitly interpret stdin as filename -f Explicitly interpret stdin as filename
-c Pretty color output
-s server_address Use alternative pastebin server address -s server_address Use alternative pastebin server address
END END
} }
@ -41,7 +43,11 @@ die () {
if [ "${code}" -eq 0 ]; then if [ "${code}" -eq 0 ]; then
printf "%s\\n" "${msg}" printf "%s\\n" "${msg}"
else 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
fi fi
exit "${code}" exit "${code}"
@ -66,6 +72,10 @@ while true; do
-v) -v)
flag_version=1 flag_version=1
;; ;;
-c)
flag_colors=1
shift
;;
-f) -f)
flag_file=1 flag_file=1
;; ;;
@ -102,16 +112,24 @@ if [ ${flag_help} -gt 0 ]; then
fi fi
if [ ${flag_shortlist} -gt 0 ]; then if [ ${flag_shortlist} -gt 0 ]; then
out="-f -v -h -s" out="-f -v -h -s -c"
lsresults="$(ls)" lsresults="$(ls)"
die "${out} ${lsresults}" 0 die "${out} ${lsresults}" 0
fi fi
if [ ${flag_file} -gt 0 ]; then if [ ${flag_file} -gt 0 ]; then
if [ -z "${data}" ]; 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 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 # attempt to split data and upload each string as file
for f in ${data} for f in ${data}
do do
@ -119,26 +137,46 @@ if [ ${flag_file} -gt 0 ]; then
if [ "$f" = "$data" ]; then if [ "$f" = "$data" ]; then
break; break;
fi fi
printf "%s${f}\\t%s" "$RESET" "$SUCCESS" if [ ${flag_colors} -gt 0 ]; then
printf "%s%s\\t%s" "$RESET" "${f}" "$SUCCESS"
fi
if [ -f "${f}" ]; then if [ -f "${f}" ]; then
curl -F"file=@${f}" "${ENDPOINT}" curl -F"file=@${f}" "${ENDPOINT}"
printf "%s" "$RESET" if [ ${flag_colors} -gt 0 ]; then
printf "%s" "$RESET"
fi
else 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 fi
done done
else else
printf "%s${data}\\t%s" "$RESET" "$SUCCESS" if [ ${flag_colors} -gt 0 ]; then
curl -F"file=@${data}" "${ENDPOINT}" printf "%s${data}\\t%s" "$RESET" "$SUCCESS"
printf "%s" "$RESET" curl -F"file=@${data}" "${ENDPOINT}"
printf "%s" "$RESET"
else
curl -F"file=@${data}" "${ENDPOINT}"
fi
fi fi
else else
if [ -z "${data}" ]; then 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 else
printf "%s" "$SUCCESS" if [ ${flag_colors} -gt 0 ]; then
printf "%s" "${data}" | curl -F"file=@-;filename=null.txt" "${ENDPOINT}" printf "%s" "$SUCCESS"
printf "%s" "$RESET" 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
fi fi

5
pb.1
View File

@ -1,4 +1,4 @@
.TH PB 1 "14 August 2018" "v2018.08.14" .TH PB 1 "15 August 2018" "v2018.08.14"
.SH NAME .SH NAME
pb \- a helper utility for using 0x0 pastebin services pb \- a helper utility for using 0x0 pastebin services
.SH SYNOPSIS .SH SYNOPSIS
@ -32,6 +32,9 @@ Explicitly interpret stdin as filename or names
.B -s <server_address> .B -s <server_address>
Use alternative pastebin server address Use alternative pastebin server address
.TP .TP
.B -c
Pretty color output
.TP
.B -v .B -v
Display current version information. Display current version information.
.TP .TP