blob: bdacdfd5c57e1d60e913f2860302b74483e794f6 (
plain) (
blame)
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
|
#!/bin/sh
NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
msg_info() {
echo -e "${GREEN}$1${NC}"
}
msg_warn() {
echo -e "${YELLOW}$1${NC}"
}
msg_error() {
echo -e "${RED}$1${NC}"
}
print_help() {
echo
echo "joyce - record your consciousness with ease."
echo
echo "USAGE:"
echo " joyce COMMAND [OPTION...]"
echo
echo "COMMANDs are:"
echo " n | new {title}:"
echo " create a new note, setting the title to {title} if provided."
echo " This is the default command."
echo " h | help:"
echo " print this help"
echo
echo "OPTIONs for 'new' are:"
echo " -c | --clipboard:"
echo " grab a URL from the clipboard."
echo " -u | --url {url}:"
echo " pass a URL from command line."
echo
}
BASE="$GIT/stream"
STREAM="$BASE/stream.txt"
COMMAND=${1:-new}
[[ $# -ge 1 ]] && shift
CLIPBOARD=0
URL=""
while [ $# != 0 ]
do
arg=$1
case "$arg" in
-c|--clipboard)
CLIPBOARD=1
;;
-u|--url)
[[ $# -gt 1 ]] &&\
URL=$2 &&\
shift
;;
*)
msg_error "$1: invalid option"
print_help
exit 1
;;
esac
shift
done
case $COMMAND in
n|new)
pushd "$BASE"
# Sync notes
git pull origin master
# Add new note
DATE="$(date --iso-8601=seconds)"
LINE="$DATE\t"
if [ "$CLIPBOARD" -eq 1 ]; then
CLIP=""
if which xclip >/dev/null 2>&1 ; then
CLIP="$(xclip -out -selection clipboard)"
elif which termux-clipboard-get >/dev/null 2>&1 ; then
CLIP="$(termux-clipboard-get)"
fi
LINE="$LINE[<++>]($CLIP)"
elif [ -n "$URL" ]; then
LINE="$LINE[<++>]($URL)"
fi
LINE="$LINE<++>"
echo -e "$LINE" >> "$STREAM"
nvim + +startinsert "$STREAM"
# Sync notes back
git add "$STREAM"
git commit -m "[$DATE] Update notes"
git push origin master
;;
help)
print_help
;;
*)
msg_error "$COMMAND: invalid command"
print_help
exit 2
;;
esac
exit 0
|