-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoJoo
More file actions
executable file
·75 lines (57 loc) · 2.04 KB
/
JoJoo
File metadata and controls
executable file
·75 lines (57 loc) · 2.04 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Script to search Google using lynx
# --- Dependencies Check ---
# Check for lynx
if ! command -v lynx &> /dev/null; then
echo "Error: lynx is not installed. Please install it." >&2
exit 1
fi
# Check for jq (for URL encoding)
if ! command -v jq &> /dev/null; then
echo "Warning: jq is not installed. URL encoding might be basic." >&2
# We can proceed with basic encoding, but jq is better
fi
# --- Input Check ---
# Check if a search query was provided
if [[ $# -eq 0 ]]; then
echo "Usage: $0 <search query>" >&2
echo "Example: $0 weather in Münster" >&2
exit 1
fi
# Combine all command-line arguments into a single query string
QUERY="$*"
# --- Prepare Search URL ---
# URL encode the query
# Using jq if available (more robust)
if command -v jq &> /dev/null; then
ENCODED_QUERY=$(printf "%s" "$QUERY" | jq -sRr @uri)
else
# Basic encoding: replace spaces with '+' (less robust for other special chars)
ENCODED_QUERY=$(printf "%s" "$QUERY" | sed 's/ /+/g')
# You might need more complex pure bash encoding here if jq isn't an option
# and you encounter issues with special characters.
fi
# Construct Google Search URL
# Using google.de and German language based on your location context
SEARCH_URL="https://www.google.de/search?q=${ENCODED_QUERY}&hl=en"
# Alternatively, for generic google.com in English:
# SEARCH_URL="https://www.google.com/search?q=${ENCODED_QUERY}&hl=en"
# --- Execute Search ---
echo "Searching Google for: '$QUERY'"
echo "Using URL: $SEARCH_URL"
echo "Launching lynx..."
echo "--- (Press 'q' to quit lynx) ---"
sleep 1 # Brief pause before launching lynx
# Execute lynx to display the search results interactively
# You can navigate using arrow keys, follow links with Enter/Right Arrow,
# go back with Left Arrow, and quit with 'q'.
lynx -accept_all_cookies "$SEARCH_URL"
# --- Exit ---
# Check lynx exit status (optional)
if [[ $? -ne 0 ]]; then
echo "Lynx exited with an error or was terminated." >&2
# Exit with an error code if lynx failed
exit 1
fi
echo "Exited JoJoo."
exit 0