-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsr
executable file
·117 lines (105 loc) · 2.73 KB
/
sr
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
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
## scratchpad retriever
## author: belaja-akacija
## description: retrieves your scratchpads by date lol
## TODO: filter scratchpads and concat them, then display the full months scratchpads in one document.
## Should it open open in vim or just use cat? :THONK:
VERSION="1.0"
DIR="$HOME/.local/share/scratchpad"
OpenDate()
{
# check if the input is a date by number, or is one of the 12 months
# Should be able to be shortened. e.g. instead of "December", "dec" is sufficient
# if it's just a month, open vim in Explorer mode inside of the current year's month directory
# elseif it's a month and a date, open the current year's day of that month in vim with Goyo
# if a full date is provided, with a year, obv open that exact file
# If there are no matches quietly fail, but if it's an invalid format, give error.
# TODO: add years
# if argument one contains a word character, then treat that as the month
YEAR=$(echo $3)
if [[ ! "$1" =~ [[:digit:]] ]]; then
MONTH=$(echo "$1")
else
DAY=$(echo "$1")
MONTH=$(echo "$2")
fi
case $MONTH in
jan)
OpenDir "January" "$DAY" "$YEAR"
;;
feb)
OpenDir "February" "$DAY" "$YEAR"
;;
mar)
OpenDir "March" "$DAY" "$YEAR"
;;
apr)
OpenDir "April" "$DAY" "$YEAR"
;;
may)
OpenDir "May" "$DAY" "$YEAR"
;;
jun)
OpenDir "June" "$DAY" "$YEAR"
;;
jul)
OpenDir "July" "$DAY" "$YEAR"
;;
aug)
OpenDir "August" "$DAY" "$YEAR"
;;
sep)
OpenDir "September" "$DAY" "$YEAR"
;;
nov)
OpenDir "November" "$DAY" "$YEAR"
;;
dec)
OpenDir "December" "$DAY" "$YEAR"
;;
esac
}
OpenDir()
{
# if the year is not present, then assume the current year
if [[ -z "$3" ]]; then
# open the year's dir, then check the rest of the dates
CURR_YEAR=$(date +"%Y")
if [[ -z "$DAY" ]]; then
cd "$DIR/$CURR_YEAR/$1"
exec zsh
else
nvim -c "Goyo" "$DIR/$CURR_YEAR/$1/$2"*
fi
elif [[ $3 =~ [[:digit:]] ]]; then
# Do the previous logic, but with the specified year
if [[ -z "$DAY" ]]; then
cd "$DIR/$3/$1"
exec zsh
else
nvim -c "Goyo" "$DIR/$3/$1/$2"*
fi
fi
}
Help()
{
echo -e "\n\tScratchpad Retriever -- ($VERSION)\n\t Author: Belaja-akacija\n\t\t 2021"
echo
echo -e " Usage: sr [ OPTION ] [[ DAY ] [ MONTH ] [ YEAR ]]"
echo -e " Month should be written in latin letters. E.x. 'January' --> 'jan'
"
echo " + -d #-----------> retrieve by date"
echo " + -h #-----------> this help"
echo
}
while getopts "d:h" flag
do
case "${flag}" in
d)
OpenDate "$2" "$3" "$4"
;;
h) Help ;;
*) echo "Invalid option: -$flag"
exit ;;
esac
done