-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsuckless-olh-query.sh
More file actions
31 lines (26 loc) · 972 Bytes
/
suckless-olh-query.sh
File metadata and controls
31 lines (26 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
# Open a dmenu which prompts for any number of whitespace-separated search terms and suggest old
# queries.
# Grep iteratively the one-line-help.txt file for lines that contain all of the given search terms.
# This is a neat way of querying and retrieving snippets from the one-line-help.txt file.
#
# Usage:
#
# suckless-olh-query.sh
#
# author: andreasl
query_history_file="${HOME}/.solhq_history"
historic_queries="$(tac "$query_history_file")"
if ! query="$(printf "$historic_queries" | dmenu -i -l 5 -p "olh query?:")"; then
exit 1
fi
file="${HOME}/Dev/Zeugs/one-line-help.txt"
results=$(<"$file")
for searchterm in ${query}; do
results="$(printf '%s' "$results" | grep -i "$searchterm")"
done
[ -z "$results" ] && exit 1
selected_result="$(printf '%s\n' "${results[@]}" | dmenu -i -l 30 -p "select:")"
[ -z "$selected_result" ] && exit 1
sed -i "/${query}/d" "$query_history_file"
printf -- '%s\n' "$query" >>"$query_history_file"