Новый бинд для скриншота выборной области загрузки в Chibisafe и копирования общедоступной ссылки
This commit is contained in:
1 parent
c80e4353ca
commit
7c8631f9ea
4 files changed
+111
-8
No files matched your search
@@ -51,6 +51,18 @@ bind = $mainMod, L, exec, $HOME/.config/wlogout/current_wall.sh && loginctl lock
|
||||
bindl = $mainMod ALT, D, exec, hyprctl dispatch dpms toggle
|
||||
bindl = $mainMod ALT, S, exec, $HOME/.config/wlogout/current_wall.sh && systemctl suspend
|
||||
|
||||
# Screenshot a window
|
||||
bind = $mainMod, PRINT, exec, hyprshot -z -m window -o ~/Pictures/Screen
|
||||
# Screenshot of a region
|
||||
bind = SHIFT, Print, exec, grim -c -g "$(slurp)" - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of the region taken" -t 2000
|
||||
# Screenshot of the whole screen
|
||||
bind = , Print, exec, grim -c - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of whole screen taken" -t 2000
|
||||
# Screenshot of a region and upload to Chibisafe
|
||||
bind = $mainMod SHIFT, PRINT, exec, $HOME/.config/hypr/scripts/screenshot_to_chibisafe.sh
|
||||
|
||||
# Emoji Picker
|
||||
bind = $mainMod SHIFT, E, exec, emote
|
||||
|
||||
# Move focus with mainMod + arrow keys
|
||||
bind = $mainMod, left, movefocus, l
|
||||
bind = $mainMod, right, movefocus, r
|
||||
@@ -121,11 +133,3 @@ bindl = , XF86AudioNext, exec, playerctl next
|
||||
bindl = , XF86AudioPause, exec, playerctl play-pause
|
||||
bindl = , XF86AudioPlay, exec, playerctl play-pause
|
||||
bindl = , XF86AudioPrev, exec, playerctl previous
|
||||
|
||||
# Screenshots
|
||||
bind = $mainMod, PRINT, exec, hyprshot -z -m window -o ~/Pictures/Screen # Screenshot a window
|
||||
bind = SHIFT, Print, exec, grim -c -g "$(slurp)" - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of the region taken" -t 2000 # Screenshot of a region
|
||||
bind = , Print, exec, grim -c - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of whole screen taken" -t 2000 # Screenshot of the whole screen
|
||||
|
||||
# Emoji Picker
|
||||
bind = $mainMod SHIFT, E, exec, emote
|
||||
@@ -0,0 +1,6 @@
|
||||
# ChibiSafe URL for accessing your service
|
||||
CHIBISAFE_URL=https://chibisafe.example
|
||||
|
||||
# ChibiSafe API token, which can be obtained from your account dashboard (https://chibisafe.example/dashboard/account)
|
||||
CHIBISAFE_API_TOKEN=your_api_token
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
A simple Chibisafe file uploader that uses the Chibisafe API and API key to upload files.
|
||||
|
||||
It is designed for Linux distros running Wayland (I use Arch Linux + Hyprland).
|
||||
|
||||
If it doesn't work on your system, check the commands in the functions:
|
||||
`send_notification()` and `copy_to_clipboard()`
|
||||
|
||||
Usage:
|
||||
python3.12 chibisafe_uploader.py /path/to/file
|
||||
"""
|
||||
|
||||
import os
|
||||
import mimetypes
|
||||
import requests
|
||||
import dotenv
|
||||
import logging
|
||||
import argparse
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
|
||||
def send_notification(message: str) -> None:
|
||||
os.system(f'notify-send "ChibisafeUploader" "{message}" -t 3000')
|
||||
|
||||
def copy_to_clipboard(url: str) -> None:
|
||||
os.system(f'echo "{url}" | wl-copy')
|
||||
|
||||
|
||||
def upload_file(file_path: str) -> None:
|
||||
"""
|
||||
Upload a file to Chibisafe API.
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
logger.error(f"Error. File {file_path} not found.")
|
||||
send_notification(f"❌ File {file_path} not found.")
|
||||
return
|
||||
|
||||
|
||||
file_name = os.path.basename(file_path)
|
||||
mime_type, _ = mimetypes.guess_type(file_path)
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
url=f"{os.getenv("CHIBISAFE_URL")}/api/upload",
|
||||
|
||||
headers={
|
||||
"x-api-key": os.getenv("CHIBISAFE_API_TOKEN"),
|
||||
"user-agent": "Mozilla/5.0 Chrome/131.0.0.0 Safari/537.36",
|
||||
},
|
||||
|
||||
files={
|
||||
"file": (file_name, open(file_path, "rb"), mime_type or "application/octet-stream"),
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
logger.info(f"Successful. API response: {response.json()}")
|
||||
|
||||
send_notification("✅ File uploaded successfully")
|
||||
copy_to_clipboard(response.json()["url"])
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"Error occurred while uploading file.\n{e}")
|
||||
send_notification(f"❌ Error occurred while uploading file.\n{e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description="A simple Chibisafe file uploader that uses the Chibisafe API to upload files."
|
||||
)
|
||||
parser.add_argument("file_path", help="Full path to the file to upload")
|
||||
args = parser.parse_args()
|
||||
|
||||
upload_file(args.file_path)
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
TEMP_DIR="/tmp"
|
||||
FILENAME="$(date +%F_%T)-grim.png"
|
||||
FILE_PATH="$TEMP_DIR/$FILENAME"
|
||||
|
||||
# Take the screenshot of the region
|
||||
grim -c -g "$(slurp)" "$FILE_PATH" || exit 1
|
||||
|
||||
# Upload the screenshot to ChibiSafe with Python script
|
||||
"$HOME/.config/hypr/scripts/.venv/bin/python3.12" "$HOME/.config/hypr/scripts/chibisafe_uploader.py" "$FILE_PATH"
|
||||
|
||||
rm "$FILE_PATH"
|
||||
Reference in new issue
Block a user