-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem
More file actions
executable file
·55 lines (46 loc) · 971 Bytes
/
mem
File metadata and controls
executable file
·55 lines (46 loc) · 971 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env zsh
STORE="$HOME/store.txt"
[[ -f "$STORE" ]] || touch "$STORE"
case "$1" in
add)
shift
while getopts "m:" opt; do
case "$opt" in
m)
msg="$OPTARG"
if [[ "$msg" == *$'\n'* ]]; then
echo "Error: multiline input not allowed"
exit 1
fi
echo "$(date '+%Y-%m-%d %H:%M:%S') | $msg" >> "$STORE"
;;
esac
done
;;
list)
if [[ "$2" == "-a" ]]; then
cat "$STORE"
else
tail -n 5 "$STORE"
fi
;;
search)
selected=$(tail -r "$STORE" | fzf --height=40% --reverse --border)
if [[ -n "$selected" ]]; then
text="${selected#*| }"
echo -n "$text" | pbcopy
echo "Copied: $text"
fi
;;
edit)
vim "$STORE"
;;
*)
echo "Usage:"
echo " mem add -m \"text\""
echo " mem list"
echo " mem list -a"
echo " mem search"
echo " mem edit"
;;
esac