Skip to content

Commit 03c3f0a

Browse files
authored
Merge pull request #25 from moheladwy/enhance/xclip-compatibility-terminals
Improve xclip compatibility for terminal emulators
2 parents 220dfdc + 984deac commit 03c3f0a

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,7 @@ cython_debug/
170170
*.png
171171
*.gif
172172
output*.txt
173+
174+
175+
#Ignore vscode AI rules
176+
.github/instructions/codacy.instructions.md

OCR4Linux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ========================================================================================================================
22
# Author:
33
# Mohamed Hussein Al-Adawy
4-
# Version: 1.3.0
4+
# Version: 1.4.0
55
# Description:
66
# OCR4Linux.py is a Python script that handles image preprocessing and text extraction using Tesseract OCR.
77
# The script takes an input image, processes it for optimal OCR accuracy, and extracts text while preserving

OCR4Linux.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# ========================================================================================================================
33
# Author: Mohamed Hussein Al-Adawy
4-
# Version: 1.2.0
4+
# Version: 1.4.0
55
# Description:
66
# OCR4Linux is a versatile text extraction tool for Linux systems that:
77
# 1. Takes screenshots of selected areas using:
@@ -189,14 +189,18 @@ choose_lang() {
189189

190190
# take shots using grimblast for wayland
191191
takescreenshot_wayland() {
192+
log_message "Taking screenshot using grimblast for Wayland..."
192193
sleep $SLEEP_DURATION
193194
grimblast --notify copysave area "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
195+
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME in wayland session"
194196
}
195197

196198
# take shots using scrot for x11
197199
takescreenshot_x11() {
200+
log_message "Taking screenshot using scrot for X11..."
198201
sleep $SLEEP_DURATION
199202
scrot -s -Z 0 -o -F "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
203+
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME in x11 session"
200204
}
201205

202206
# Run the screenshot functions based on the session type.
@@ -206,7 +210,6 @@ takescreenshot() {
206210
else
207211
takescreenshot_x11
208212
fi
209-
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
210213
}
211214

212215
# Pass the screenshot to OCR tool to extract text from the image.
@@ -232,13 +235,18 @@ extract_text() {
232235

233236
# Copy the extracted text to clipboard using wl-copy and cliphist.
234237
copy_to_wayland_clipboard() {
238+
log_message "Copying extracted text to Wayland clipboard using wl-copy and cliphist..."
235239
cliphist store <"$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
236240
cliphist list | head -n 1 | cliphist decode | wl-copy
241+
log_message "Extracted text copied to Wayland clipboard successfully."
237242
}
238243

239244
# Copy the extracted text to clipboard using xclip.
240245
copy_to_x11_clipboard() {
241-
xclip -selection clipboard -t text/plain -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
246+
log_message "Copying extracted text to X11 clipboard using xclip..."
247+
xclip -selection clipboard -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
248+
xclip -selection primary -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
249+
log_message "Extracted text copied to X11 clipboard successfully."
242250
}
243251

244252
# Run the copy to clipboard functions based on the session type.

setup.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# ========================================================================================================================
33
# Author:
44
# Mohamed Hussein Al-Adawy
5-
# Version: 1.3.0
5+
# Version: 1.4.0
66
# Description:
77
# This setup script installs and configures OCR4Linux and its dependencies.
88
# It handles the installation of:
@@ -53,39 +53,56 @@ x11_session_apps=(
5353

5454
# Check if yay is installed.
5555
check_yay() {
56+
echo "Checking for yay AUR helper..."
5657
if ! command -v yay &>/dev/null; then
5758
read -r -p "yay is not installed. Do you want to install yay? (y/n): " choice
5859
if [ "$choice" = "y" ]; then
5960
sudo pacman -S --needed --noconfirm git base-devel
6061
git clone https://aur.archlinux.org/yay.git
6162
cd yay || exit
6263
makepkg -si --noconfirm
64+
echo "yay has been installed successfully."
6365
else
6466
echo "Please install yay first!"
6567
return 1
6668
fi
69+
else
70+
echo "yay is already installed."
6771
fi
6872
}
6973

7074
# Install the required packages.
7175
install_requirements() {
76+
echo "Installing system requirements..."
7277
yay -S --noconfirm --needed "${sys_requirements[@]}"
7378

7479
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
80+
echo "Installing Wayland session applications..."
7581
yay -S --noconfirm --needed "${wayland_session_apps[@]}"
7682
else
83+
echo "Installing X11 session applications..."
7784
yay -S --noconfirm --needed "${x11_session_apps[@]}"
7885
fi
86+
87+
echo "All requirements have been installed successfully."
7988
}
8089

8190
# Main function.
8291
main() {
92+
echo "========================================================================================================"
93+
echo "Starting OCR4Linux setup..."
94+
echo "========================================================================================================"
8395
check_yay
96+
echo "========================================================================================================"
8497
install_requirements
85-
98+
echo "========================================================================================================"
8699
# Copy the script to the user's home directory.
100+
echo "Setting up OCR4Linux configuration..."
87101
mkdir -p "$HOME/.config/OCR4Linux"
88102
cp -r ./* "$HOME/.config/OCR4Linux"
103+
echo "OCR4Linux has been set up successfully in $HOME/.config/OCR4Linux"
104+
echo "Setup completed. You can now use OCR4Linux."
105+
echo "========================================================================================================"
89106
}
90107

91108
main

0 commit comments

Comments
 (0)