summaryrefslogtreecommitdiff
path: root/home/scripts/greet.sh
blob: 00b6be5c89b8159fb1c3ba8258b12132d69f803f (plain)
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
#!/bin/bash
source log.sh "greet.sh"

pick_greeting() {
	path="$1"
	greetings=("$1"/*)
	greeting="${greetings[$RANDOM % ${#greetings[@]}]}"
	echo "$greeting"
}

GREETINGS_LIST="$XDG_CONFIG_HOME/zsh/greetings"
if [ ! -d "$GREETINGS_LIST" ]; then 
	log DEBUG "no such file $GREETINGS_LIST"
	exit 0
fi

for greetings in $(ls "$GREETINGS_LIST" | sort); do
	echo
	log DEBUG "greeting $greetings"

	path="$GREETINGS_LIST/$greetings"
	if [ ! -d "$path" ]; then
		log DEBUG "greetings $path is not a directory"
		continue
	fi

	greeting=$(pick_greeting "$path")
	cat "$greeting"
done