-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddg.sh
69 lines (61 loc) · 1.55 KB
/
ddg.sh
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
#!/bin/bash
API_KEY="YOUR_API_KEY_HERE"
HISTORY_PATH="$HOME/.local/share/ddg"
LOG_FILE="$HISTORY_PATH/aliases_history.txt"
# Ensure the history directory exists
mkdir -p "$HISTORY_PATH"
generate_alias() {
RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{}' \
https://quack.duckduckgo.com/api/email/addresses)
ALIAS=$(echo "$RESPONSE" | grep -oP '(?<="address":")[^"]*')
if [ -n "$ALIAS" ]; then
FULL_ALIAS="[email protected]"
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
echo "$TIMESTAMP - $FULL_ALIAS" >> "$LOG_FILE"
echo "Email alias generated: $FULL_ALIAS"
else
echo "Failed to generate alias. Response: $RESPONSE"
fi
}
show_history() {
if [ -f "$LOG_FILE" ]; then
cat "$LOG_FILE"
else
echo "No aliases history found."
fi
}
show_menu() {
echo "Please choose an option:"
echo "1 - Generate email alias"
echo "2 - Show aliases history"
read -p "Enter your choice (1 or 2): " choice
case $choice in
1)
generate_alias
;;
2)
show_history
;;
*)
echo "Invalid choice. Please run the script again and select a valid option."
;;
esac
}
if [ -n "$1" ]; then
case $1 in
generate)
generate_alias
;;
history)
show_history
;;
*)
echo "Usage: $0 [generate|history]"
;;
esac
else
show_menu
fi