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
-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
```

72
pb
View File

@ -1,12 +1,13 @@
#!/bin/sh
version="v.2018.08.14"
ENDPOINT="https://0x0.tilde.team"
flag_options="hvfs::x"
version="v.2018.08.15"
ENDPOINT="https://ttm.sh"
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
}
@ -41,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}"
@ -66,6 +72,10 @@ while true; do
-v)
flag_version=1
;;
-c)
flag_colors=1
shift
;;
-f)
flag_file=1
;;
@ -102,16 +112,24 @@ 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
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
@ -119,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"
fi
if [ -f "${f}" ]; then
curl -F"file=@${f}" "${ENDPOINT}"
printf "%s" "$RESET"
if [ ${flag_colors} -gt 0 ]; then
printf "%s" "$RESET"
fi
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

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
pb \- a helper utility for using 0x0 pastebin services
.SH SYNOPSIS
@ -32,6 +32,9 @@ Explicitly interpret stdin as filename or names
.B -s <server_address>
Use alternative pastebin server address
.TP
.B -c
Pretty color output
.TP
.B -v
Display current version information.
.TP