-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautofocus
More file actions
executable file
·63 lines (57 loc) · 1.21 KB
/
Copy pathautofocus
File metadata and controls
executable file
·63 lines (57 loc) · 1.21 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
#!/bin/sh
TARGET=$1
if [ -z "${TARGET}" ]
then
echo "Please give a target file."
exit 1
fi
shift
ACTION=$1
if [ -z "${ACTION}" ]
then
ACTION="ls"
else
shift
fi
strikeGrep='^~.*~$'
strikeP () {
echo "$@" | grep -q -E "${strikeGrep}"
}
trimEmptyLines () {
sed -i "/^$/d" "$1"
}
case ${ACTION} in
ls|show)
i=0
while read -r p; do
echo "${i} - ${p}";
i=$((i + 1))
done <"${TARGET}"
;;
add)
echo "$@" >> "${TARGET}"
;;
strike)
targetLine=$1
targetLine=$((targetLine + 1))
echo "${targetLine}"
lineText=$(sed "${targetLine}q;d" "${TARGET}")
echo "${lineText}"
if strikeP "${lineText}"
then
sed -i "${targetLine} s/^~\(.*\)~$/\1/" "${TARGET}"
else
sed -i "${targetLine} s/^.*$/~\0~/" "${TARGET}"
fi
;;
sink)
strikeLines=$(grep -E "${strikeGrep}" "${TARGET}")
noStrikeLines=$(grep -v -E "${strikeGrep}" "${TARGET}")
echo "${noStrikeLines}" > "${TARGET}"
echo "${strikeLines}" >> "${TARGET}"
trimEmptyLines "${TARGET}"
;;
*)
echo "Unknown action"
;;
esac