-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from lfkeitel/master
Formatting, compatibility, and simplification
- Loading branch information
Showing
3 changed files
with
42 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
water_time=10800 # Set time interval in seconds | ||
#!/bin/sh | ||
|
||
WATER_TIME=${WATER_TIME:-10800} # Set time interval in seconds | ||
DRINK_WATER_CONF="$HOME/.water" | ||
|
||
drink_water() { | ||
thirsty=`cat $HOME/.water` | ||
last_time=`cat $HOME/.water_last_time` | ||
# If the file doesn't exist, create it | ||
if [ ! -f $DRINK_WATER_CONF ]; then | ||
not_thirsty | ||
fi | ||
|
||
if [[ $thirsty == false ]]; then | ||
echo "$[$(date +%s) + $water_time]" > $HOME/.water_last_time | ||
echo "true" > $HOME/.water | ||
echo -n " Water is essential " | ||
thirsty=$(head -1 $DRINK_WATER_CONF) | ||
last_time=$(tail -1 $DRINK_WATER_CONF) | ||
|
||
elif [[ $[last_time] -lt $(date +%s) ]]; then | ||
if [ $thirsty = 'false' ]; then | ||
echo "true" > $DRINK_WATER_CONF | ||
echo "$(($(date +%s) + $WATER_TIME))" >> $DRINK_WATER_CONF | ||
echo -n "Water is essential " | ||
elif [ $last_time -lt $(date +%s) ]; then | ||
echo -n "💧 You're thirsty" | ||
fi | ||
} | ||
|
||
not_thirsty() { | ||
echo "false" > $HOME/.water | ||
echo "0" > $HOME/.water_last_time | ||
echo "false" > $DRINK_WATER_CONF | ||
echo "0" >> $DRINK_WATER_CONF | ||
} | ||
|
||
# Username. | ||
# If user is root, then pain it in red. Otherwise, just print in yellow. | ||
# If user is root, then print it in red. Otherwise, just print in yellow. | ||
spaceship_user() { | ||
if [[ $USER == 'root' ]]; then | ||
if [ $USER = 'root' ]; then | ||
echo -n "%{$fg_bold[red]%}" | ||
else | ||
echo -n "%{$fg_bold[yellow]%}" | ||
fi | ||
echo -n "%n" | ||
echo -n "%{$reset_color%}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
# Override default water time | ||
WATER_TIME=5 | ||
|
||
. ./thirsty.sh | ||
|
||
echo "Water time: $WATER_TIME" | ||
|
||
drink_water | ||
echo | ||
not_thirsty | ||
drink_water | ||
echo | ||
sleep $(($WATER_TIME + 1)) | ||
drink_water | ||
echo |