Compare commits

...

10 Commits

Author SHA1 Message Date
Jack L. Frost 19f6c5249a remove debug stuff
Signed-off-by: fbt <fbt@fleshless.org>
2022-12-28 04:19:58 +00:00
Jack L. Frost 823a2847c8 encode all the stuff
Signed-off-by: fbt <fbt@fleshless.org>
2022-12-28 04:16:26 +00:00
Jack L. Frost 6e2c506e72 alignment
Signed-off-by: fbt <fbt@fleshless.org>
2022-04-18 10:25:48 +00:00
Jack L. Frost 3f094a2b47 xclip selector selector :>
Signed-off-by: fbt <fbt@fleshless.org>
2021-10-06 13:49:35 +03:00
Jack L. Frost cd5f695936 clipboard option
Signed-off-by: fbt <fbt@fleshless.org>
2021-10-06 13:40:45 +03:00
Jack L. Frost 8aea6446bb forgot this one
Signed-off-by: fbt <fbt@fleshless.org>
2021-10-06 13:22:17 +03:00
Jack L. Frost fb38496fe9 just return 1
Signed-off-by: fbt <fbt@fleshless.org>
2021-04-19 16:14:19 +03:00
Jack L. Frost df4e1d0370 Smarter args
Signed-off-by: fbt <fbt@fleshless.org>
2020-10-03 19:44:19 +03:00
Jack L. Frost b63ae67204 it's actually just format
Signed-off-by: fbt <fbt@fleshless.org>
2020-08-21 15:42:52 +03:00
Jack L. Frost f103e564dc readme
Signed-off-by: fbt <fbt@fleshless.org>
2020-05-24 04:36:13 +03:00
3 changed files with 45 additions and 16 deletions

View File

@ -18,6 +18,8 @@ Call ufw -h for help.
Dependencies: curl, jq
The config goes into `$XDG_CONFIG_DIR/ufw`.
ufwd
----

58
ufw
View File

@ -43,6 +43,7 @@ usage() {
-t|--tags "<tag1[, tag2,..]>" # Add tags to the file.
-q|--quiet # Be quiet.
-v|--void # Don't add the file to my files.
-c|--clipboard # Throw the result into the clipboard
Config options (~/.config/ufw):
secret # Your personal token. Get it at https://zfh.so/settings_form
@ -83,7 +84,10 @@ get_max_filesize() {
get_album_id() {
declare api_response api_status api_status_message
api_response=$( curl -f "$cfg_service_url/albumctl.json?m=new&name=$1&secret=$secret" )
api_response=$( curl --get \
--data-urlencode "name=$1" \
--data-urlencode "secret=$secret" \
"$cfg_service_url/albumctl.json?m=new" )
get_api_status <<< "$api_response"
@ -140,7 +144,7 @@ upload() {
api_response=$( curl \
-F file="@$file" \
-F api_format='json' \
-F format='json' \
-F flag_private="$flag_private" \
-F secret="$secret" \
-F tags="$tags" \
@ -170,6 +174,8 @@ upload() {
(( flag_directlink )) || file_link="${file_link#*.}"
}
(( flag_clipboard )) && xclip "${xclip_args[@]}" <<< "$file_link"
printf '%s\n' "$file_link"
if (( flag_rm )); then
@ -185,14 +191,18 @@ upload() {
get_shortlink() {
declare url=$1 api_response api_status api_status_message
api_response=$( curl "$cfg_service_url/shrink.json?url=${url}&secret=$secret" )
api_response=$( curl --data-urlencode "url=$url" \
--data-urlencode "secret=$secret" \
"$cfg_service_url/shrink.json" )
get_api_status <<< "$api_response"
if (( api_status == 200 )); then
read -r short_url real_url < <(
jq -r '.data.short_url' <<< "$api_response"
)
(( flag_clipboard )) && xclip "${xclip_args[@]}" <<< "$short_url"
printf '%s\n' "$short_url"
else
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
@ -233,6 +243,7 @@ get_my_ip() {
if (( api_status == 200 )); then
my_ip=$( jq -r '.data.ip' <<< "$api_response" )
(( flag_clipboard )) && xclip "${xclip_args[@]}" <<< "$my_ip"
printf '%s\n' "$my_ip"
else
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
@ -290,7 +301,7 @@ set_argv() {
unset -v arg opt c
case "$1" in
(--) argv+=( "$1" ); break;;
(--) argv+=( "$1" ); shift; break;;
(--*)
IFS='=' read arg opt <<< "$1"
@ -315,6 +326,10 @@ set_argv() {
esac
shift
done
if (( $# )); then
argv+=( "$@" )
fi
}
main() {
@ -342,7 +357,7 @@ main() {
if [[ -f "$cfg_file" ]]; then
if ! source "$cfg_file"; then
printf 'Failed to source configuration file: %s\n' "$cfg_file"
return $?
return 1
fi
fi
@ -353,6 +368,8 @@ main() {
: ${cfg_max_filesize:='200M'}
: ${flag_shortlink:=0}
: ${flag_directlink:=1}
: ${flag_clipboard:=0}
: ${xclip_selector:='clipboard'}
while [[ "$1" ]]; do
case "$1" in
@ -375,6 +392,10 @@ main() {
(-q|--quiet) flag_quiet=1;;
(-v|--void) flag_void=1;;
# Clipboard
(-c|--clipboard) flag_clipboard=1;;
(-C|--xclip-selector) xclip_selector=$2; shift;;
(--notify) flag_notify=1;;
(--no-notify|-n) flag_notify=0;;
@ -396,11 +417,19 @@ main() {
return 1
;;
*) break;;
*) args+=( "$1" );;
esac
shift
done
xclip_args+=( -selection "$xclip_selector" )
# Catch the args after --
if (( $# )); then
args+=( "$@" )
shift
fi
TEMPDIR="$cfg_tmp_dir"
for i in "$cfg_tmp_dir"; do
@ -410,21 +439,18 @@ main() {
case "${action:-upload}" in
upload)
get_token || return $?
(( ${#args[@]} )) || return 1
if (( $# )); then
for t in "$@"; do
upload "$t"
done
else
upload
fi
for t in "${args[@]}"; do
upload "$t"
done
;;
url)
get_token || return $?
for t in "$@"; do
get_shortlink "$1"
for t in "${args[@]}"; do
get_shortlink "$t"
done
;;

1
ufwd
View File

@ -14,6 +14,7 @@ usage() {
printf ' -h # Show this message.\n'
printf ' -n # Enable notifications with notify-send. Must be installed.\n'
printf ' -d [path] # Set the dir that is to be watched.\n'
printf ' -s # Push the file url into the clipboard.\n'
}
upload() {