cswimr/home
Archived
Template
1
0
Fork 0

changed a bunch of function stuff and added flameshot-screenshot

This commit is contained in:
cswimr 2024-10-11 23:24:25 -04:00
parent aa5315906b
commit e05e8a9a95
Signed by: cswimr
GPG key ID: A9C162E867C851FA

View file

@ -31,50 +31,58 @@ function clip {
}
function zipline {
# see spectacle-screenshot for example usage
# see spectacle-screenshot and flameshot-screenshot for example usage
readonly file=${1:?Please provide the path to the file you want to upload.}
readonly name=${2:?Please provide an application name to use in notify-send.}
readonly desktopentry=${3:?Please provide a path to a desktop entry file.}
readonly name=${2}
readonly desktopentry=${3}
readonly token=${ZIPLINE_TOKEN:?Environment variable ZIPLINE_TOKEN is not set. Please set it to your Zipline API token. I recommend placing it in a file at ~/.config/environment.d/zipline.conf}
readonly url=${ZIPLINE_URL:?Environment variable ZIPLINE_URL is not set. Please set it to the URL of your Zipline instance. I recommend placing it in a file at ~/.config/environment.d/zipline.conf}
temp_file=$(mktemp)
temp_file=$(mktemp /tmp/zipline-upload.XXXXXXXX.json)
trap 'rm -f "$temp_file"' EXIT
if (( ! $+commands[jq] )); then
echo "jq is not installed."
return 1
return 127
fi
if (( ! $+commands[curl] )); then
echo "curl is not installed."
return 1
fi
if (( ! $+commands[notify-send] )); then
echo "notify-send is not installed."
return 1
return 127
fi
if [[ ! -f "${file}" ]]; then
echo "File does not exist."
return 1
return 66
fi
if ! does-desktop-entry-exist "$desktopentry"; then
echo "Desktop entry does not exist."
return 1
if [[ -n "${name}" && -n "${desktopentry}" ]]; then
if ! does-desktop-entry-exist "$desktopentry"; then
echo "Desktop entry does not exist."
return 66
fi
if (( ! $+commands[notify-send] )); then
echo "notify-send is not installed."
return 127
fi
readonly use_send_notify=true
else
readonly use_send_notify=false
fi
if curl -sS -fH "authorization: $token" "${url%/}/api/upload" -F file="@$file" -H "Content-Type: multipart/form-data" >"$temp_file" 2>&1; then
readonly link=$(jq -r '.files[0]' <"$temp_file" | tr -d '\n')
echo -n "$link" | clip
echo "Upload successful. Link copied to clipboard: $link"
notify-send -a "$name" -u low -c transfer.complete -i "$file" -h "string:desktop-entry:$desktopentry" "Upload Successful" "Link copied to clipboard:\n$link"
if $use_send_notify; then
notify-send -a "$name" -u low -c transfer.complete -i "$file" -h "string:desktop-entry:$desktopentry" "Upload Successful" "Link copied to clipboard:\n$link"
fi
else
echo "Upload failed. Error message: $(<"$temp_file")"
notify-send -a "$name" -u critical -c transfer.error -h "string:desktop-entry:$desktopentry" "Upload Failed" "$(<"$temp_file")"
if $use_send_notify; then
notify-send -a "$name" -u critical -c transfer.error -h "string:desktop-entry $desktopentry" "Upload Failed" "$(<"$temp_file")"
fi
return 1
fi
}
@ -83,6 +91,12 @@ function spectacle-screenshot {
# takes one argument, the path to save the screenshot to - if not provided, a temp file will be used
if (( ! $+commands[spectacle] )); then
echo "spectacle is not installed."
return 127
fi
if [[ -f "${1}" ]]; then
echo "File already exists. Please provide a different file path, or use the zipline function to upload the file."
echo "Example: zipline \"$file\""
return 1
fi
@ -92,13 +106,40 @@ function spectacle-screenshot {
readonly file=$1
fi
spectacle --nonotify --background --region --copy-image --output "$file"
[ ! -s "$file" ] && exit 1
command spectacle --nonotify --background --region --copy-image --output "$file"
[ ! -s "$file" ] && return 1
trap 'rm -f "$file"' EXIT
zipline "$file" Spectacle org.kde.spectacle.desktop
}
function flameshot-screenshot {
# takes one argument, the path to save the screenshot to - if not provided, a temp file will be used
if (( ! $+commands[flameshot] )); then
echo "flameshot is not installed."
return 127
fi
if [[ -f "${1}" ]]; then
echo "File already exists. Please provide a different file path, or use the zipline function to upload the file."
echo "Example: zipline \"${1}\""
return 1
fi
if [[ -z "${1}" ]]; then
readonly file=$(mktemp /tmp/flameshot-screenshot.XXXXXXXX.png)
else
readonly file=$1
fi
command flameshot gui --clipboard --raw > $file
echo "Screenshot saved to $file"
[ ! -s "$file" ] && return 1
trap 'rm -f "$file"' EXIT
zipline "$file" Flameshot org.flameshot.Flameshot.desktop
}
function does-desktop-entry-exist {
readonly desktopentry=${1:?Please provide the full filename of the desktop entry.}
local entrypaths=(
@ -130,6 +171,6 @@ function fastfetch ff neofetch nf {
echo "Warning: fastfetch is not installed, falling back to neofetch."
command neofetch $@
else
echo "Warning: fastfetch and neofetch are not installed, cannot fetch system information."
echo "Fatal: fastfetch and neofetch are not installed, cannot fetch system information."
fi
}