changed a bunch of function stuff and added flameshot-screenshot
This commit is contained in:
parent
aa5315906b
commit
e05e8a9a95
1 changed files with 61 additions and 20 deletions
|
@ -31,50 +31,58 @@ function clip {
|
||||||
}
|
}
|
||||||
|
|
||||||
function zipline {
|
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 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 name=${2}
|
||||||
readonly desktopentry=${3:?Please provide a path to a desktop entry file.}
|
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 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}
|
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
|
trap 'rm -f "$temp_file"' EXIT
|
||||||
|
|
||||||
if (( ! $+commands[jq] )); then
|
if (( ! $+commands[jq] )); then
|
||||||
echo "jq is not installed."
|
echo "jq is not installed."
|
||||||
return 1
|
return 127
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( ! $+commands[curl] )); then
|
if (( ! $+commands[curl] )); then
|
||||||
echo "curl is not installed."
|
echo "curl is not installed."
|
||||||
return 1
|
return 127
|
||||||
fi
|
|
||||||
|
|
||||||
if (( ! $+commands[notify-send] )); then
|
|
||||||
echo "notify-send is not installed."
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "${file}" ]]; then
|
if [[ ! -f "${file}" ]]; then
|
||||||
echo "File does not exist."
|
echo "File does not exist."
|
||||||
return 1
|
return 66
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "${name}" && -n "${desktopentry}" ]]; then
|
||||||
if ! does-desktop-entry-exist "$desktopentry"; then
|
if ! does-desktop-entry-exist "$desktopentry"; then
|
||||||
echo "Desktop entry does not exist."
|
echo "Desktop entry does not exist."
|
||||||
return 1
|
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
|
fi
|
||||||
|
|
||||||
if curl -sS -fH "authorization: $token" "${url%/}/api/upload" -F file="@$file" -H "Content-Type: multipart/form-data" >"$temp_file" 2>&1; then
|
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')
|
readonly link=$(jq -r '.files[0]' <"$temp_file" | tr -d '\n')
|
||||||
echo -n "$link" | clip
|
echo -n "$link" | clip
|
||||||
echo "Upload successful. Link copied to clipboard: $link"
|
echo "Upload successful. Link copied to clipboard: $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"
|
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
|
else
|
||||||
echo "Upload failed. Error message: $(<"$temp_file")"
|
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
|
return 1
|
||||||
fi
|
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
|
# takes one argument, the path to save the screenshot to - if not provided, a temp file will be used
|
||||||
if (( ! $+commands[spectacle] )); then
|
if (( ! $+commands[spectacle] )); then
|
||||||
echo "spectacle is not installed."
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -92,13 +106,40 @@ function spectacle-screenshot {
|
||||||
readonly file=$1
|
readonly file=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
spectacle --nonotify --background --region --copy-image --output "$file"
|
command spectacle --nonotify --background --region --copy-image --output "$file"
|
||||||
[ ! -s "$file" ] && exit 1
|
[ ! -s "$file" ] && return 1
|
||||||
|
|
||||||
trap 'rm -f "$file"' EXIT
|
trap 'rm -f "$file"' EXIT
|
||||||
zipline "$file" Spectacle org.kde.spectacle.desktop
|
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 {
|
function does-desktop-entry-exist {
|
||||||
readonly desktopentry=${1:?Please provide the full filename of the desktop entry.}
|
readonly desktopentry=${1:?Please provide the full filename of the desktop entry.}
|
||||||
local entrypaths=(
|
local entrypaths=(
|
||||||
|
@ -130,6 +171,6 @@ function fastfetch ff neofetch nf {
|
||||||
echo "Warning: fastfetch is not installed, falling back to neofetch."
|
echo "Warning: fastfetch is not installed, falling back to neofetch."
|
||||||
command neofetch $@
|
command neofetch $@
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue