mirror of
https://tildegit.org/tomasino/pb.git
synced 2024-12-23 03:25:18 +01:00
adds filetype override for standard input binary files
This commit is contained in:
parent
1dfca9b2cd
commit
f9883a8a76
@ -1,4 +1,4 @@
|
|||||||
pb ![calver](https://img.shields.io/badge/calver-2020.09.05-22bfda.svg?style=flat-square) [![Build Status](https://drone.tildegit.org/api/badges/tomasino/pb/status.svg)](https://drone.tildegit.org/tomasino/pb) ![license](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat-square)
|
pb ![calver](https://img.shields.io/badge/calver-2020.10.27-22bfda.svg?style=flat-square) [![Build Status](https://drone.tildegit.org/api/badges/tomasino/pb/status.svg)](https://drone.tildegit.org/tomasino/pb) ![license](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat-square)
|
||||||
------
|
------
|
||||||
|
|
||||||
**pb** is a helper utility for using 0x0 pastebin services
|
**pb** is a helper utility for using 0x0 pastebin services
|
||||||
@ -39,6 +39,12 @@ Shorten a URL
|
|||||||
pb -u https://google.com
|
pb -u https://google.com
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Re-upload an image from the web
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s https://tildegit.org/_/static/img/gitea-lg.png | pb -e "png"
|
||||||
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -48,6 +54,7 @@ pb -u https://google.com
|
|||||||
-c Pretty color output
|
-c Pretty color output
|
||||||
-u Shorten URL
|
-u Shorten URL
|
||||||
-s server_address Use alternative pastebin server address
|
-s server_address Use alternative pastebin server address
|
||||||
|
-e bin_extension Specify a binary file extension used in the upload
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
|
53
pb
53
pb
@ -1,15 +1,17 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# init variables
|
# init variables
|
||||||
version="v2020.07.05"
|
version="v2020.10.27"
|
||||||
ENDPOINT="https://ttm.sh"
|
ENDPOINT="https://ttm.sh"
|
||||||
flag_options=":hvcufs::"
|
flag_options=":hvcufe:s::"
|
||||||
flag_version=0
|
flag_version=0
|
||||||
flag_help=0
|
flag_help=0
|
||||||
flag_file=0
|
flag_file=0
|
||||||
flag_url=0
|
flag_url=0
|
||||||
flag_colors=0
|
flag_colors=0
|
||||||
|
flag_ext=0
|
||||||
data=""
|
data=""
|
||||||
|
EXT=""
|
||||||
|
|
||||||
# help message available via func
|
# help message available via func
|
||||||
show_help() {
|
show_help() {
|
||||||
@ -27,6 +29,7 @@ OPTIONAL FLAGS:
|
|||||||
-c Pretty color output
|
-c Pretty color output
|
||||||
-u Shorten URL
|
-u Shorten URL
|
||||||
-s server_address Use alternative pastebin server address
|
-s server_address Use alternative pastebin server address
|
||||||
|
-e bin_extension Specify a binary file extension used in the upload
|
||||||
END
|
END
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,13 +58,6 @@ die () {
|
|||||||
exit "${code}"
|
exit "${code}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# is not interactive shell, use stdin
|
|
||||||
if [ -t 0 ]; then
|
|
||||||
flag_file=1
|
|
||||||
else
|
|
||||||
data="$(cat < /dev/stdin )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# attempt to parse options or die
|
# attempt to parse options or die
|
||||||
if ! parsed=$(getopt ${flag_options} "$@"); then
|
if ! parsed=$(getopt ${flag_options} "$@"); then
|
||||||
printf "pb: unknown option\\n"
|
printf "pb: unknown option\\n"
|
||||||
@ -85,6 +81,11 @@ while true; do
|
|||||||
-f)
|
-f)
|
||||||
flag_file=1
|
flag_file=1
|
||||||
;;
|
;;
|
||||||
|
-e)
|
||||||
|
shift
|
||||||
|
flag_ext=1
|
||||||
|
EXT="$1"
|
||||||
|
;;
|
||||||
-s)
|
-s)
|
||||||
shift
|
shift
|
||||||
ENDPOINT="$1"
|
ENDPOINT="$1"
|
||||||
@ -103,11 +104,6 @@ while true; do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
# if data variable is empty (not a pipe) use params as fallback
|
|
||||||
if [ -z "$data" ]; then
|
|
||||||
data="$*"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# display current version
|
# display current version
|
||||||
if [ ${flag_version} -gt 0 ]; then
|
if [ ${flag_version} -gt 0 ]; then
|
||||||
printf "%s\\n" "${version}"
|
printf "%s\\n" "${version}"
|
||||||
@ -120,6 +116,24 @@ if [ ${flag_help} -gt 0 ]; then
|
|||||||
die "" 0
|
die "" 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# is not interactive shell, use stdin
|
||||||
|
if [ -t 0 ]; then
|
||||||
|
flag_file=1
|
||||||
|
else
|
||||||
|
if [ ${flag_ext} -gt 0 ]; then
|
||||||
|
# short-circuit stdin access to ensure binary data is transferred to curl
|
||||||
|
curl -sF"file=@-;filename=null.${EXT}" "${ENDPOINT}" < /dev/stdin
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
data="$(cat < /dev/stdin )"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if data variable is empty (not a pipe) use params as fallback
|
||||||
|
if [ -z "$data" ]; then
|
||||||
|
data="$*"
|
||||||
|
fi
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
if [ ${flag_colors} -gt 0 ]; then
|
if [ ${flag_colors} -gt 0 ]; then
|
||||||
SUCCESS=$(tput setaf 190)
|
SUCCESS=$(tput setaf 190)
|
||||||
@ -167,8 +181,13 @@ if [ ${flag_file} -gt 0 ]; then
|
|||||||
fi
|
fi
|
||||||
# check if file exists
|
# check if file exists
|
||||||
if [ -f "${f}" ]; then
|
if [ -f "${f}" ]; then
|
||||||
# send file to endpoint
|
if [ ${flag_ext} -gt 0 ]; then
|
||||||
result=$(curl -sF"file=@${f}" "${ENDPOINT}")
|
# send file to endpoint masked with new extension
|
||||||
|
result=$(curl -sF"file=@${f};filename=null.${EXT}" "${ENDPOINT}")
|
||||||
|
else
|
||||||
|
# send file to endpoint
|
||||||
|
result=$(curl -sF"file=@${f}" "${ENDPOINT}")
|
||||||
|
fi
|
||||||
printf "%s%s%s\\n" "$SUCCESS" "$result" "$RESET"
|
printf "%s%s%s\\n" "$SUCCESS" "$result" "$RESET"
|
||||||
else
|
else
|
||||||
# print error message
|
# print error message
|
||||||
@ -189,7 +208,7 @@ else
|
|||||||
printf "%sNo data found for upload. Please try again.%s\\n" "$ERROR" "$RESET"
|
printf "%sNo data found for upload. Please try again.%s\\n" "$ERROR" "$RESET"
|
||||||
else
|
else
|
||||||
# data available
|
# data available
|
||||||
# send data to endpoint, print short url
|
# send data to endpoint
|
||||||
result=$(printf "%s" "${data}" | curl -sF"file=@-;filename=null.txt" "${ENDPOINT}")
|
result=$(printf "%s" "${data}" | curl -sF"file=@-;filename=null.txt" "${ENDPOINT}")
|
||||||
printf "%s%s%s\\n" "$SUCCESS" "$result" "$RESET"
|
printf "%s%s%s\\n" "$SUCCESS" "$result" "$RESET"
|
||||||
fi
|
fi
|
||||||
|
9
pb.1
9
pb.1
@ -1,4 +1,4 @@
|
|||||||
.TH PB 1 "05 September 2020" "v2020.09.05"
|
.TH PB 1 "27 October 2020" "v2020.10.27"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
pb \- a helper utility for using 0x0 pastebin services
|
pb \- a helper utility for using 0x0 pastebin services
|
||||||
@ -28,6 +28,13 @@ Explicitly interpret stdin as filename or names.
|
|||||||
.BI -s " server_address"
|
.BI -s " server_address"
|
||||||
Use alternative pastebin server address.
|
Use alternative pastebin server address.
|
||||||
.TP
|
.TP
|
||||||
|
.BI -e " bin_extension"
|
||||||
|
Specifes the file extension used in the upload of binary content passed to
|
||||||
|
.B pb
|
||||||
|
via standard input.
|
||||||
|
.I Note:
|
||||||
|
this attribute will not work with file uploads or URL shortening.
|
||||||
|
.TP
|
||||||
.B -u
|
.B -u
|
||||||
Shorten a URL.
|
Shorten a URL.
|
||||||
.TP
|
.TP
|
||||||
|
Loading…
Reference in New Issue
Block a user