From 5a59ee60f30fdb9b9080a6e6043b31237427ead2 Mon Sep 17 00:00:00 2001 From: Ritchie Cunningham Date: Tue, 22 Apr 2025 23:49:15 +0100 Subject: [PATCH] [Change] Changed documentation after applying dacav's patches. --- README.md | 33 ++++++++++++++++++++------------- imgbb | 22 ++++++++++++++-------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d59fb9f..adb3ed5 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Ideal for quickly sharing screenshots or images in environments like IRC without **Author:** Ritchie Cunningham +**Contributors:** dacav + **Version:** 1.0 (as of 22/04/2025) ## Features @@ -30,10 +32,11 @@ Make sure you have the following command-line tools installed: ```bash sudo apt install jq # Debian. ``` -* **xclip:** Used for accessing the X11 clipboard. **This script will not work on Wayland sessions.** +* **xclip:** Used for accessing the X11 clipboard. **This is for X11. Wayland users, see below..** ```bash sudo apt install xclip # Debian. ``` +* **wl-clipboard** Used for accessing the Wayland clipboard. **This is for Wayland. X11 users, see above.** * **notify-send (Optional):** Used for desktop notifications. The script works without it but won't show popups. ```bash sudo apt install notify-send # Debian (often in libnotify-bin). @@ -55,23 +58,26 @@ Make sure you have the following command-line tools installed: mkdir -p ~/.local/bin ln -s "$(pwd)/imgbb" ~/.local/bin/imgbb ``` - Now you can just run `imgbb` from your terminal. ## Configuration This script requires a **free API key** from ImgBB: 1. Go to [https://api.imgbb.com/](https://api.imgbb.com/) and register or log in to get your key. -2. Store the key in `.config/imgbb/uploader/api_key`. - * **File** Create the directory and file, then paste *only* your API key inside: - ```bash - mkdir -p ~/.config/imgbb_uploader - nano ~/.config/imgbb_uploader/api_key - # Paste your key, save the file. - # Set permissions so only you can read it: - chmod 600 ~/.config/imgbb_uploader/api_key - ``` - +2. Set the API key using *one* of these methods (script checks in this order): + * Store the key in `.config/imgbb/uploader/api_key`. + * **File** Create the config file `~/.config/imgbb_uploader.conf` and add a line like: + ```bash + echo "api_key="YOUR_KEY_HERE" > ~/.config/imgbb_uploader.conf + # Set permissions so only you can read it: + chmod 600 ~/.config/imgbb_uploader.conf + ``` + * **Environment Variable:** Set the `IMGBB_API_KEY` variable in your environment + ```bash + export IMGBB_API_KEY="YOUR KEY HERE" + ``` + Now you can just run `imgbb` from your terminal. + ## Usage **Options:** @@ -104,7 +110,8 @@ imgbb -h # Notes -Currently relies on xclip and therefore only works reliably under X11 sessions. Wayland support would require adding logic to use wl-clipboard. +- Supports both X11 (using xclip) and Wayland (using wl-clipboard) sessions. It detects the session type using $XDG_SESSION_TYPE. + # License diff --git a/imgbb b/imgbb index 7842930..f87bf51 100755 --- a/imgbb +++ b/imgbb @@ -5,8 +5,9 @@ # to ImgBB (imgbb.com) using their V1 API. Retrieves the direct # image URL, prints it to stdout, and copies it to the X11 clipboard. # Author: Ritchie Cunningham -# License: GPL License -# Version: 3.0 +# Contributors: dacav +# License: GPL 3.0 License +# Version: 1.2 # Date: 22/04/2025 # ----------------------------------------------------------------------------- # Usage Examples: @@ -23,18 +24,23 @@ # - bash (v4+ required for =~, (( )), BASH_REMATCH) # - curl: (e.g., sudo apt install curl) # - jq: (e.g., sudo apt install jq) -# - xclip: (X11 clipboard access) (e.g., sudo apt install xclip) +# - Clipboard tool: +# - xclip: (X11 clipboard access) (e.g., sudo apt install xclip) +# - wl-clipboard (For Wayland clipboard access) (e.g., sudo apt install wl-clipboard) # - notify-send: (Optional, for desktop notifications) (e.g., sudo apt install notify-send) # - Coreutils: (mktemp, basename, rm, cat, echo, etc. - usually standard) # ----------------------------------------------------------------------------- # Configuration: # Requires an ImgBB API key (v1). Get one free: https://api.imgbb.com/ -# Store the key: -# - File: ~/.config/imgbb_uploader/api_key (chmod 600 recommended) -# (Create directory: mkdir -p ~/.config/imgbb_uploader) +# Set the API key using ONE of these methods (checked in this order): +# 1. Environment Variable: IMGBB_API_KEY="YOUR KEY HERE" +# 2. Config File: Create ~/.config/imgbb_uploader.conf and add a line like: +# api_key="YOUR_KEY_HERE" +# (We'll soon have other defaults to set here). # ----------------------------------------------------------------------------- # Notes: -# - Uses 'xclip', works on X11 sessions only. Wayland requires 'wl-clipboard'. +# - Supports both X11 (using xclip) and Wayland (using wl-clipboard) sessions. +# It detects the session type using $XDG_SESSION_TYPE. # ----------------------------------------------------------------------------- # === Default Configuration & Argument Parsing. === @@ -93,7 +99,7 @@ while [[ $# -gt 0 ]]; do unit="${BASH_REMATCH[2]}" # The unit part. # Default to minutes if no unit was provided. - if [ -z "$unit" ]; then unit="s"; fi + if [ -z "$unit" ]; then unit="m"; fi # Calculate total seconds based on the unit. case "$unit" in