forked from NerdyDayTrips/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.sh
More file actions
executable file
·119 lines (107 loc) · 3.06 KB
/
Copy pathedit.sh
File metadata and controls
executable file
·119 lines (107 loc) · 3.06 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
set -e
# Usage:
# cd content/daytrip
# echo eu/gb/dale-abbey.md >menu.txt
# # Fill menu.txt with filenames
# ../../edit.sh
function next_file() {
filename=$(head -n1 menu.txt)
echo ${filename} >>done.txt
mv menu.txt menu.txt~
tail -n+2 menu.txt~ >menu.txt
echo ${filename}
}
function last_file() {
# Back up two files, because we've consumed the current one already
mv menu.txt menu.txt~
tail -n2 done.txt >menu.txt
cat menu.txt~ >>menu.txt
mv done.txt done.txt~
head -n-2 done.txt~ >done.txt
}
function get_tag() {
tag="$1"
file="$2"
grep "^${tag}:" "${file}" | sed -e "s,^${tag}: \\?,," -e "s/['\"]//g"
}
function parse_lat() {
latlon="$1"
echo ${latlon} \
| sed -e "s/^[^0-9.-]*\\([0-9.-]\\+\\),.*/\\1/"
}
function parse_lng() {
latlon="$1"
echo ${latlon} \
| sed -e "s/^[^0-9.-]*[0-9.-]\\+,\\([0-9.-]\\+\\).*/\\1/"
}
while :; do
file=$(next_file)
slug=$(get_tag slug ${file})
sensible-browser "https://nerdydaytrips.org/${slug}/"
lat=$(get_tag lat ${file})
lng=$(get_tag lng ${file})
sensible-browser "https://www.openstreetmap.org/?mlat=${lat}&mlon=${lng}#map=17/${lat}/${lng}"
search=$(get_tag title ${file} | sed -e "s/ /+/g")
sensible-browser "https://duckduckgo.com/?q=${search}&t=vivaldi&ia=web"
while :; do
echo ${file}
cat ${file}
echo "[p]rint [u]rl [r]evert [g]eolocation [s]lug/file"
echo -n "[e]dit [n]ext [P]revious [D]elete [q]uit > "
read -n1 action
echo
case $action in
p)
echo ${file}
cat ${file}
;;
u)
read -p "URL: " url
if grep -q "^external_url:" ${file}; then
sed -i -e "s,external_url:.*\$,external_url: ${url}," ${file}
else
sed -i -e "/^title:/iexternal_url: ${url}" ${file}
fi
;;
r)
git co -- ${file}
;;
g)
read -p "lat,long: " latlong
lat=$(parse_lat ${latlong})
lng=$(parse_lng ${latlong})
sed -i \
-e "s/^lat:.*\$/lat: ${lat}/" \
-e "s/^lng:.*\$/lng: ${lng}/" \
${file}
;;
n)
break
;;
s)
read -p "slug: " slug
sed -i -e "s,^slug:.*\$,slug: ${slug}," ${file}
newdir=$(dirname ${slug})
newdir=${newdir/daytrip\//}
mkdir -p ${newdir}
mv ${file} ${slug#daytrip/}.md
file=${slug#daytrip/}.md
;;
e)
sensible-editor ${file}
;;
P)
last_file
break
;;
D)
rm ${file}
break
;;
q)
exit 0
;;
esac
done
done