Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
--------

## Usage
lock the screen and show a random dad joke
lock the screen and show a random dad joke or default message (depends on setting)
```
ilock
```
Expand Down
38 changes: 23 additions & 15 deletions ilock
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
#!/bin/sh

fetchjoke() {
curl -sH "Accept: text/plain" https://icanhazdadjoke.com/ |
sed 's/\? /\?\n/' | sed 's/\. /\.\n/' >~/.cache/dadjoke
}

if iconf -i dadjoke; then
# fetch random dad joke
if ! [ -e ~/.cache/dadjoke ]; then
fetchjoke
fi
(sleep 2 && fetchjoke &)

MESSAGE="$(cat ~/.cache/dadjoke)"
elif [ "$1" = "message" ]; then
if [ "$1" = "message" ]; then
# manual message
MESSAGE="$(imenu -i "enter lock screen message")"
[ -z "$MESSAGE" ] && exit
shift
if [ -z "$2" ]; then
MESSAGE="$(imenu -i "enter lock screen message")"
[ -z "$MESSAGE" ] && exit
shift
else
MESSAGE=$2
if [ "$MESSAGE" == "null" ]; then
MESSAGE=""
shift
fi
shift
fi
else
# default
MESSAGE="locked, enter password for $(whoami)"
if iconf -i dadjoke; then
# fetch random dad joke
if ! [ -e ~/.cache/dadjoke ]; then
fetchjoke
fi
(sleep 2 && fetchjoke &)
MESSAGE="$(cat ~/.cache/dadjoke)"
else
MESSAGE="locked, enter password for $(whoami)"
fi
fi

if [ "$1" = '-o' ]; then
Expand Down