Skip to content

Commit b1fbd4b

Browse files
committed
fix(search): enable search for systemctl and journalctl topics
1 parent b99af62 commit b1fbd4b

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

cheat.sh

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -157,42 +157,23 @@ show_cheat() {
157157
return 1
158158
fi
159159

160-
# Write all output to a temporary file for robust pagination
161-
local tmpfile=$(mktemp)
162-
substitute_translations "$template_file" "$lang_file" > "$tmpfile"
163-
local total_lines=$(wc -l < "$tmpfile")
164-
local lines_per_page=10
165-
local current_page=1
166-
local total_pages=$(( (total_lines + lines_per_page - 1) / lines_per_page ))
167-
168-
local i=1
169-
while (( i <= total_lines )); do
170-
echo -e "${CYAN}${BOLD}--- Page $current_page of $total_pages ---${NC}"
171-
echo ""
172-
for ((j=0; j<lines_per_page && i<=total_lines; j++, i++)); do
173-
local line
174-
line=$(sed -n "${i}p" "$tmpfile")
175-
if [[ "$line" =~ ^# ]]; then
176-
echo -e "${CYAN}${BOLD}$line${NC}"
177-
elif [[ "$line" =~ ^\$ ]]; then
178-
echo -e "${GREEN}$line${NC}"
179-
elif [[ "$line" =~ ^\> ]]; then
180-
echo -e "${YELLOW}$line${NC}"
181-
else
182-
echo "$line"
183-
fi
184-
done
185-
if (( i <= total_lines )); then
186-
echo ""
187-
echo -e "${MAGENTA}Press Enter for next page, 'q' to quit:${NC}"
188-
read -r input
189-
if [[ "$input" == "q" ]]; then
190-
break
191-
fi
160+
# Simple approach: output all content with colors
161+
# User can pipe to 'less' or 'more' for pagination if needed
162+
while IFS= read -r line; do
163+
if [[ "$line" =~ ^# ]]; then
164+
# Headers
165+
echo -e "${CYAN}${BOLD}$line${NC}"
166+
elif [[ "$line" =~ ^\$ ]]; then
167+
# Commands
168+
echo -e "${GREEN}$line${NC}"
169+
elif [[ "$line" =~ ^\> ]]; then
170+
# Descriptions
171+
echo -e "${YELLOW}$line${NC}"
172+
else
173+
# Regular text
174+
echo "$line"
192175
fi
193-
current_page=$((current_page + 1))
194-
done
195-
rm -f "$tmpfile"
176+
done < <(substitute_translations "$template_file" "$lang_file")
196177
}
197178

198179
# Search in cheat sheets
@@ -241,6 +222,8 @@ search_cheats() {
241222
docker_*) topic="docker" ;;
242223
bash_*) topic="bash" ;;
243224
vim_*) topic="vim" ;;
225+
systemctl_*) topic="systemctl" ;;
226+
journalctl_*) topic="systemctl" ;;
244227
*) continue ;;
245228
esac
246229

0 commit comments

Comments
 (0)