Skip to content

Commit

Permalink
Fixed AM/PM detection, added custom time format option
Browse files Browse the repository at this point in the history
AM/PM detection was broken by default on some locales, like
en_GB, this should fix it for most cases.
  • Loading branch information
avalonwilliams committed May 30, 2022
1 parent 2e9c62e commit d7626ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ based on your locale. To enable it, use the following in your config file:
DRACULA_DISPLAY_TIME=1
```

If you want to set the time format, you can set this using the
[strftime(3)](https://manpage.me/?q=strftime) format. For example to use a 24
hour format:

```
DRACULA_TIME_FORMAT="%-H:%M"
```

### Context Segment

The context segment shows the username, and, if the user is root or logged in via
Expand Down
23 changes: 12 additions & 11 deletions dracula.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ dracula_test_git_optional_lock() {

# use --no-optional-locks flag on git
DRACULA_GIT_NOLOCK=${DRACULA_GIT_NOLOCK:-$(dracula_test_git_optional_lock)}

# time format string
if [[ -z "$DRACULA_TIME_FORMAT" ]]; then
DRACULA_TIME_FORMAT="%-H:%M"
# check if locale uses AM and PM
if locale -ck LC_TIME 2>/dev/null | grep -q '^t_fmt="%r"$'; then
DRACULA_TIME_FORMAT="%-I:%M%p"
fi
fi
# }}}

# Status segment {{{
Expand All @@ -78,15 +87,7 @@ fi
# Time segment {{{
dracula_time_segment() {
if (( DRACULA_DISPLAY_TIME )); then
if [[ -z "$TIME_FORMAT" ]]; then
TIME_FORMAT="%-H:%M"
# check if locale uses AM and PM
if ! locale -ck LC_TIME | grep 'am_pm=";"' > /dev/null; then
TIME_FORMAT="%-I:%M%p"
fi
fi

print -P "%D{$TIME_FORMAT} "
print -P "%D{$DRACULA_TIME_FORMAT} "
fi
}

Expand All @@ -111,9 +112,9 @@ PROMPT+='%F{magenta}%B$(dracula_context)'
PROMPT+='%F{blue}%B'

if (( DRACULA_DISPLAY_FULL_CWD )); then
PROMPT+='%~ '
PROMPT+='%~ '
else
PROMPT+='%c '
PROMPT+='%c '
fi
# }}}

Expand Down

0 comments on commit d7626ad

Please sign in to comment.