commit b2d3ae26b8894a858f6248eb5ed6d95a5e840005
parent da7311007d4220a3577f559b80527839e825f8e7
Author: Yuval Langer <yuval.langer@gmail.com>
Date: Wed, 6 Dec 2023 20:06:09 +0200
Add a flag for setting the 0x0.st instance URL.
Diffstat:
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/bin/0x0.st b/bin/0x0.st
@@ -19,14 +19,16 @@ help_message () {
printf "\t%s [--debug] -s, --secondary\n" "$self_executable"
printf "\t%s [--debug] -b, --clipboard\n" "$self_executable"
printf "\t%s [--debug] -u URL, --url URL\n" "$self_executable"
+ printf "\t%s [--debug] -x URL, --null-dot-st-url URL\n" "$self_executable"
printf "\t%s [--debug] FILENAME\n" "$self_executable"
printf "\n"
printf "Flags:
- -p, --primary Operate on the PRIMARY selection.
- -s, --secondary Operate on the SECONDARY selection.
- -b, --clipboard Operate on the CLIPBOARD selection.
- -u, --url Tell 0x0.st to mirror the file at the URL.
- --debug Show debug information and do not upload to the 0x0.st.\n"
+ -p, --primary Operate on the PRIMARY selection.
+ -s, --secondary Operate on the SECONDARY selection.
+ -b, --clipboard Operate on the CLIPBOARD selection.
+ -u, --url Tell 0x0.st to mirror the file at the URL.
+ -x, --null-dot-st-url The 0x0.st instance address, instead of 0x0.st itself.
+ --debug Show debug information and do not upload to 0x0.st.\n"
printf "\n"
printf "Environment Variables:
URL_FOR_0X0_DOT_ST (all upper case)
@@ -38,6 +40,8 @@ print_variables() {
printf "Self executable: '%s'\n" "$self_executable" 1>&2
printf "Flags:\n" 1>&2
+ printf " null_dot_st_url_flag: '%s'\n" "$null_dot_st_url_flag"
+ printf " null_dot_st_url: '%s'\n" "$null_dot_st_url"
printf " xsel_flag: '%s'\n" "$xsel_flag" 1>&2
printf " target_url: '%s'\n" "$target_url" 1>&2
@@ -50,7 +54,7 @@ print_provide_one_and_only_one_flag_message () {
}
# https://www.baeldung.com/linux/bash-parse-command-line-arguments
-OUR_ARGUMENTS="$(getopt -o hpsbu: --long help,debug,primary,secondary,clipboard,url: -- "$@" )"
+OUR_ARGUMENTS="$(getopt -o hpsbu:x: --long help,debug,primary,secondary,clipboard,url:,null-dot-st-url: -- "$@" )"
eval set -- "$OUR_ARGUMENTS"
while [ -n "$*" ]; do
case "$1" in
@@ -100,6 +104,11 @@ while [ -n "$*" ]; do
target_url="$2"
shift 2
;;
+ -x | --null-dot-st-url )
+ null_dot_st_url_flag="$1"
+ null_dot_st_url="$2"
+ shift 2
+ ;;
--)
shift
filename="$1"
@@ -118,6 +127,10 @@ while [ -n "$*" ]; do
esac
done
+if [ -z "$null_dot_st_url_flag" ]; then
+ null_dot_st_url="$URL_FOR_0X0_DOT_ST"
+fi
+
if [ -n "$debug_flag" ]; then
print_variables
fi
@@ -139,18 +152,18 @@ if [ -n "$xsel_flag" ]; then
if [ -n "$debug_flag" ]; then
cat "$temp_file"
else
- curl -F"file=@${temp_file}" "$URL_FOR_0X0_DOT_ST"
+ curl -F"file=@${temp_file}" "$null_dot_st_url"
fi
elif [ -n "$url_flag" ]; then
if [ -n "$debug_flag" ]; then
curl "$target_url"
else
- curl -F"url=$target_url" "$URL_FOR_0X0_DOT_ST"
+ curl -F"url=$target_url" "$null_dot_st_url"
fi
else
if [ -n "$debug_flag" ]; then
cat "$filename"
else
- curl -F"file=@${filename}" "$URL_FOR_0X0_DOT_ST"
+ curl -F"file=@${filename}" "$null_dot_st_url"
fi
fi