Skip to content

Commit 1699f2d

Browse files
A Dynamic Collection of Shell Scripts with Educational Purpose
1 parent e395595 commit 1699f2d

4 files changed

Lines changed: 155 additions & 3 deletions

File tree

scripts/md2odt.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ main() {
9999
echo -e "${GREEN}Copying clipboard content to $temp_file${NC}"
100100

101101
# Tries different clipboard methods
102-
if command -v xclip &> /dev/null; then
102+
if command -v xclip &> /dev/null && [[ "${XDG_SESSION_TYPE,,}" != "wayland" ]]; then
103103
xclip -o -selection clipboard > "$temp_file"
104-
elif command -v xsel &> /dev/null; then
104+
elif command -v xsel &> /dev/null && [[ "${XDG_SESSION_TYPE,,}" != "wayland" ]]; then
105105
xsel --clipboard --output > "$temp_file"
106-
elif command -v wl-copy &> /dev/null; then
106+
elif command -v wl-copy &> /dev/null && [[ "${XDG_SESSION_TYPE,,}" == "wayland" ]]; then
107107
wl-paste > "$temp_file"
108108
else
109109
echo -e "${RED}Error: No clipboard utility found (xclip, xsel or wl-clipboard)${NC}"

scripts/smartresize

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Verifica se o ImageMagick está instalado
4+
if ! command -v magick &> /dev/null; then
5+
echo "O ImageMagick (magick) não está instalado. Por favor, instale-o primeiro."
6+
exit 1
7+
fi
8+
9+
# Verifica os argumentos
10+
if [ "$#" -ne 3 ] || [ "$1" != "-s" ]; then
11+
echo "Uso: $0 -s <largura_referência> <largura_desejada>"
12+
echo "Exemplo: $0 -s 560 270"
13+
exit 1
14+
fi
15+
16+
ref_width=$2
17+
target_width=$3
18+
19+
echo "Redimensionando imagens com largura > $ref_width para $target_width pixels (mantendo proporção)..."
20+
21+
# Encontra e processa imagens recursivamente
22+
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.webp" \) | while read -r img; do
23+
width=$(magick identify -format "%w" "$img")
24+
25+
if [ "$width" -gt "$ref_width" ]; then
26+
echo "Redimensionando $img (original: ${width}px)..."
27+
magick "$img" -resize "${target_width}x" "$img"
28+
else
29+
echo "Ignorando $img (${width}px <= ${ref_width}px)"
30+
fi
31+
done
32+
33+
echo "Processo concluído!"

scripts/text_it

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
# License: GPLv3
3+
# Credits: Felipe Facundes
4+
5+
: <<'DOCUMENTATION'
6+
This script (text_it) saves clipboard content to a file, supporting Termux, macOS, X11, and Wayland.
7+
It detects the OS and uses the appropriate clipboard tool ('termux-clipboard-get', 'pbpaste', 'xclip', 'wl-paste').
8+
If no text is found or tools are missing, it shows an error. The output file is specified as an argument.
9+
Works cross-platform with clear success/error messages.
10+
DOCUMENTATION
11+
12+
# Colors for messages (optional)
13+
RED='\033[0;31m'
14+
GREEN='\033[0;32m'
15+
NC='\033[0m' # No Color
16+
17+
# Creates a temporary file
18+
temp_file=$(mktemp)
19+
20+
# Definitive file
21+
file="$*"
22+
23+
show_documentation() {
24+
awk '
25+
BEGIN { inside_block = 0 }
26+
27+
# Check the beginning of the DOCUMENTATION block
28+
/: <<'\''DOCUMENTATION'\''/ { inside_block = 1; next }
29+
30+
# Check the end of the DOCUMENTATION block
31+
inside_block && $0 == "DOCUMENTATION" { inside_block = 0; exit }
32+
33+
# Print lines within the DOCUMENTATION block
34+
inside_block { print }
35+
' "$0"
36+
}
37+
38+
help() {
39+
show_documentation
40+
41+
echo -e "\nUsage: ${0##*/} <filename>"
42+
}
43+
44+
if [[ "$1" == -h ]] || [[ "$1" == --help ]]; then
45+
help
46+
47+
# Check if a file name was provided
48+
elif [ -z "$1" ]; then
49+
echo -e "${RED}Error: Please provide a filename as argument${NC}\n"
50+
help
51+
exit 1
52+
fi
53+
54+
# Try different clipboard methods
55+
if [[ -n "$TERMUX_VERSION" ]]; then
56+
# Termux (Android)
57+
if command -v termux-clipboard-get &> /dev/null; then
58+
termux-clipboard-get > "$temp_file"
59+
else
60+
echo -e "${RED}Error: termux-clipboard-get not found (Termux clipboard utility)${NC}"
61+
exit 1
62+
fi
63+
elif [[ "$(uname)" == "Darwin" ]]; then
64+
# macOS
65+
if command -v pbpaste &> /dev/null; then
66+
pbpaste > "$temp_file"
67+
else
68+
echo -e "${RED}Error: pbpaste not found (macOS clipboard utility)${NC}"
69+
exit 1
70+
fi
71+
elif [[ "${XDG_SESSION_TYPE,,}" == "wayland" ]]; then
72+
# Wayland
73+
if command -v wl-paste &> /dev/null; then
74+
wl-paste > "$temp_file"
75+
else
76+
echo -e "${RED}Error: wl-paste not found (wl-clipboard package required)${NC}"
77+
exit 1
78+
fi
79+
else
80+
# X11
81+
if command -v xclip &> /dev/null; then
82+
xclip -o -selection clipboard > "$temp_file"
83+
elif command -v xsel &> /dev/null; then
84+
xsel --clipboard --output > "$temp_file"
85+
else
86+
echo -e "${RED}Error: No clipboard utility found (xclip or xsel required)${NC}"
87+
exit 1
88+
fi
89+
fi
90+
91+
# Check if the clipboard had content
92+
if [ ! -s "$temp_file" ]; then
93+
echo -e "${RED}Error: Clipboard is empty or contains no text${NC}"
94+
rm "$temp_file"
95+
exit 1
96+
fi
97+
98+
# Moves the temporary file to the final destination
99+
mv "$temp_file" "$file"
100+
101+
echo -e "${GREEN}Success: Clipboard content saved to '$file'${NC}"

scripts/utils/optipng_recursive

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
script="${0##*/}"
4+
lock_file="/tmp/${script}.lock"
5+
touch "$lock_file"
6+
7+
_check() {
8+
if [[ -f "$lock_file" ]]; then
9+
optipng -o7 -nc "$1"
10+
fi
11+
}
12+
13+
export -f _check
14+
export lock_file
15+
16+
find . -type f -iname "*.png" -exec bash -c '_check "{}"' \;
17+
18+
rm "$lock_file"

0 commit comments

Comments
 (0)