-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_random_note.bash
More file actions
executable file
·57 lines (40 loc) · 1.22 KB
/
Copy pathshow_random_note.bash
File metadata and controls
executable file
·57 lines (40 loc) · 1.22 KB
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
#!/usr/bin/bash
# Show one random note, default behavior
# Arguments:
# $1 - number of notes to show(option)
dir=`dirname $0`
. $dir/colors.bash
. $dir/interactive.bash
what_show=$(echo 'markdown' 'markdown' 'markdown' 'markdown' 'markdown' 'man' | xargs shuf -n1 -e)
function get_random_note
{
if [[ $what_show = 'markdown' ]]; then
local files=$(find $dir/content/ -name '*.md')
local randomfile=$(echo $files | xargs shuf -n1 -e)
echo -e "${yellow}`make_link $randomfile '[ NOTE ]' ` $randomfile ${reset}"
cat $randomfile | fold -w 80 -s | $dir/render_markdown.bash
fi
if [[ $what_show = 'man' ]]; then
local man_pages=$(ls -1 /usr/share/man/man1 /usr/share/man/man7 | cut -d. -f1)
local randomfile=$(echo $man_pages | xargs shuf -n1 -e)
echo -e "${yellow}[ MAN PAGE ] $randomfile ${reset}"
man $randomfile
fi
}
function show_random_note
{
if [[ -n $1 ]]; then
local re='^[0-9]+$'
if ! [[ $1 =~ $re ]]; then
echo "Enter the number"
exit
fi
for ((i=1; i<=$1; i++))
do
get_random_note
done
exit
fi
get_random_note
}
show_random_note $1