notedux 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/notedux +79 -0
  2. package/package.json +19 -0
package/notedux ADDED
@@ -0,0 +1,79 @@
1
+ #!/bin/bash
2
+
3
+ CONFIG_FILE="$HOME/.notedux.conf"
4
+
5
+ # load config if exist
6
+ if [ -f "$CONFIG_FILE" ]; then
7
+ source "$CONFIG_FILE"
8
+ fi
9
+
10
+ TOKEN=""
11
+
12
+ # parsign arguments
13
+ while getopts "t:" opt; do
14
+ case $opt in
15
+ t)
16
+ TOKEN_SET=1
17
+ TOKEN="$OPTARG"
18
+ ;;
19
+ esac
20
+ done
21
+
22
+
23
+ shift $((OPTIND -1))
24
+
25
+ TEXT="$*"
26
+
27
+ # use default if token is missing
28
+ if [ -z "$TOKEN" ]; then
29
+ TOKEN="$DEFAULT_TOKEN"
30
+ fi
31
+
32
+ # no token - create it !
33
+ if [ -z "$TOKEN" ]; then
34
+ echo "No token found. Creating new one..."
35
+
36
+ RESPONSE=$(curl -s -X POST https://notedux.com/api/note/create)
37
+
38
+ if command -v jq >/dev/null 2>&1; then
39
+ TOKEN=$(echo "$RESPONSE" | jq -r '.token')
40
+ else
41
+ TOKEN=$(echo "$RESPONSE" | grep -o '"token"[ ]*:[ ]*"[^"]*"' | sed 's/.*:\s*"//;s/"//')
42
+ fi
43
+
44
+ if [ -z "$TOKEN" ]; then
45
+ echo "Error: could not create token."
46
+ exit 1
47
+ fi
48
+
49
+ echo "DEFAULT_TOKEN=\"$TOKEN\"" > "$CONFIG_FILE"
50
+ echo "Token created and saved to config."
51
+ fi
52
+
53
+ # =========================
54
+ # GET if there is no TEXT
55
+ # =========================
56
+ if [ -z "$TEXT" ]; then
57
+ RESPONSE=$(curl -s -X POST https://notedux.com/api/note/get \
58
+ --data-urlencode "token=$TOKEN")
59
+
60
+ echo "$RESPONSE"
61
+ exit 0
62
+ fi
63
+
64
+ # =========================
65
+ # ADD NOTE
66
+ # =========================
67
+ RESPONSE=$(curl -s -X POST https://notedux.com/api/note/add \
68
+ --data-urlencode "token=$TOKEN" \
69
+ --data-urlencode "text=$TEXT")
70
+
71
+ # pokušaj da izvučeš link
72
+ LINK=$(echo "$RESPONSE" | grep -o '"link"[ ]*:[ ]*"[^"]*"' | sed 's/.*:\s*"//;s/"//')
73
+
74
+ if [ -n "$LINK" ]; then
75
+ echo "Note created:"
76
+ echo "$LINK"
77
+ else
78
+ echo "$RESPONSE"
79
+ fi
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "notedux",
3
+ "version": "1.0.0",
4
+ "description": "Take notes from terminal",
5
+ "bin": {
6
+ "notedux": "notedux"
7
+ },
8
+ "files": [
9
+ "notedux"
10
+ ],
11
+ "keywords": [
12
+ "notes",
13
+ "cli",
14
+ "terminal"
15
+ ],
16
+ "author": "Dejan Sabados",
17
+ "license": "GPL-2.0-only",
18
+ "preferGlobal": true
19
+ }