-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanna
executable file
·69 lines (61 loc) · 1.48 KB
/
banna
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
#!/bin/bash
source ~/Repositories/scripts/essential-functions
dir="$HOME/Misc/diary"
today="$(date +%Y-%m-%d)"
function e {
emacsclient -nw -a emacs "$1"
}
function prepare-file {
file="$dir/$1"
if [[ ! -e "$file" ]] || [[ "$(du "$file" | awk '{print $1}')" -eq 0 ]]
then
echo "$1" >> "$file"
echo "(Writing on $(date +%Y-%m-%d\ %H:%m))" >> "$file"
echo -e "$(for j in $(eza -1f "$dir"); do sed -n 3p "$dir/$j"; done)" | sort | uniq | sed '/^-/d' | fzf >> "$file"
echolor yellow-purple ":: File ““$1”” created."
fi
}
function finished-p {
if [[ "$(tail -n 1 "$dir/$1")" = "Shadi" ]]
then
return 0
else
return 1
fi
}
function journal {
prepare-file "$1"
finished-p "$1" && {
echolor yellow ":: This entry is already finished. Proceed? (Y/n) " 1
continue_p=y
read -r continue_p
[[ "$continue_p" = "n" ]] && return
}
e "$dir/$1"
}
function view-entry {
if [[ -e "$dir/$1" ]]
then
bat "$dir/$1"
else
echolor red ":: File ““$1”” not found."
fi
}
function see-images {
source ~/Repositories/dotfiles/zsh/functions
xt "$(echo "$1" | tr -d '-')" "$HOME/Pictures/camera/"
}
while getopts 'i:v:' OPTION; do
case "$OPTION" in
"v") view-entry "$OPTARG" ;;
"i") see-images "$OPTARG" ;;
*) echolor red ":: Unknown option"; exit ;;
esac
done
(( $OPTIND == 1 )) && {
case "$1" in
"today") journal "$today" ;;
"yesterday") journal "$(date -d yesterday +%Y-%m-%d)" ;;
*) journal "${1:-$today}" ;;
esac
}