forked from sachaos/todoist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
todoist_functions.sh
89 lines (79 loc) · 2.47 KB
/
todoist_functions.sh
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
select_items_command="todoist --namespace --project-namespace list | peco | cut -d ' ' -f 1 | tr '\n' ' '"
function insert-in-buffer () {
if [ -n "$1" ]; then
local new_left=""
if [ -n "$LBUFFER" ]; then
new_left="${new_left}${LBUFFER} "
fi
if [ -n "$2" ]; then
new_left="${new_left}${2} "
fi
new_left="${new_left}$1"
BUFFER=${new_left}${RBUFFER}
CURSOR=${#new_left}
fi
}
# todoist find item
function peco-todoist-item () {
local SELECTED_ITEMS="$(eval ${select_items_command})"
insert-in-buffer $SELECTED_ITEMS
}
zle -N peco-todoist-item
bindkey "^xtt" peco-todoist-item
# todoist find project
function peco-todoist-project () {
local SELECTED_PROJECT="$(todoist --project-namespace projects | peco | head -n1 | cut -d ' ' -f 1)"
insert-in-buffer "${SELECTED_PROJECT}" "-P"
}
zle -N peco-todoist-project
bindkey "^xtp" peco-todoist-project
# todoist find labels
function peco-todoist-labels () {
local SELECTED_LABELS="$(todoist labels | peco | cut -d ' ' -f 1 | tr '\n' ',' | sed -e 's/,$//')"
insert-in-buffer "${SELECTED_LABELS}" "-L"
}
zle -N peco-todoist-labels
bindkey "^xtl" peco-todoist-labels
# todoist select date
function peco-todoist-date () {
date -v 1d &>/dev/null
if [ $? -eq 0 ]; then
# BSD date option
OPTION="-v+#d"
else
# GNU date option
OPTION="-d # day"
fi
local SELECTED_DATE="$(seq 0 30 | xargs -I# date $OPTION '+%d/%m/%Y %a' | peco | cut -d ' ' -f 1)"
insert-in-buffer "'${SELECTED_DATE}'" "-d"
}
zle -N peco-todoist-date
bindkey "^xtd" peco-todoist-date
function todoist-exec-with-select-task () {
if [ -n "$2" ]; then
BUFFER="todoist $1 $(echo "$2" | tr '\n' ' ')"
CURSOR=$#BUFFER
zle accept-line
fi
}
# todoist close
function peco-todoist-close() {
local SELECTED_ITEMS="$(eval ${select_items_command})"
todoist-exec-with-select-task close $SELECTED_ITEMS
}
zle -N peco-todoist-close
bindkey "^xtc" peco-todoist-close
# todoist delete
function peco-todoist-delete() {
local SELECTED_ITEMS="$(eval ${select_items_command})"
todoist-exec-with-select-task delete $SELECTED_ITEMS
}
zle -N peco-todoist-delete
bindkey "^xtk" peco-todoist-delete
# todoist open
function peco-todoist-open() {
local SELECTED_ITEMS="$(eval ${select_items_command})"
todoist-exec-with-select-task "show --browse" $SELECTED_ITEMS
}
zle -N peco-todoist-open
bindkey "^xto" peco-todoist-open