-
Notifications
You must be signed in to change notification settings - Fork 0
/
promptfessional_component_datetime.fish
68 lines (64 loc) · 2.32 KB
/
promptfessional_component_datetime.fish
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
58
59
60
61
62
63
64
65
66
67
# Prompt Component: Datetime
# Displays the current date and time.
#
# Options:
# --pattern :: The pattern to use. (default: "{color}{extra_color}{wday} {date_color}{mnth_name} {day} {time_color}{24hour}:{minute}:{second}")
#
# Colors:
# component.datetime :: The color of the component.
# component.datetime.extra :: The color for extra information such as the weekday.
# component.datetime.date :: The color for the date.
# component.datetime.time :: The color for the time.
function promptfessional_component_datetime
argparse 'pattern=' -- $argv
[ -n "$_flag_pattern" ] || set _flag_pattern '{color}{extra_color}{wday} {date_color}{mnth_name} {day} {time_color}{24hour}:{minute}:{second}'
# Get the date and time.
date +"%A:%a:%B:%b:%d:%e:%G:%g:%H:%I:%k:%l:%m:%M:%S:%Z:%z:%p" | \
read --function --delimiter=':' \
weekday_name_full weekday_name_short \
month_name_full month_name_short \
day_of_month_padded day_of_month \
year_long year_short \
hour_24_padded hour_12_padded \
hour_24 hour_12 \
month_padded \
minute_padded second_padded \
timezone_name timezone_offset \
ampm
set ampm_lower (string lower -- "$ampm")
set ampm_upper (string upper -- "$ampm")
# Render the date and time.
set -l color (promptfessional color "component.datetime")
set -l color_date (promptfessional color "component.datetime.date")
set -l color_time (promptfessional color "component.datetime.time")
set -l color_extra (promptfessional color "component.datetime.extra")
promptfessional util template "$_flag_pattern" -- \
"color" "$color" \
"date_color" "$color_date" \
"time_color" "$color_time" \
"extra_color" "$color_extra" \
"weekday" "$weekday_name_full" \
"wday" "$weekday_name_short" \
"month_name" "$month_name_full" \
"mnth_name" "$month_name_short" \
"day" "$day_of_month_padded" \
"day_nopad" "$day_of_month" \
"year" "$year_long" \
"yr" "$year_short" \
"24hour" "$hour_24_padded" \
"12hour" "$hour_12_padded" \
"24hr" "$hour_24" \
"12hr" "$hour_12" \
"month" "$month_padded" \
"mnth" "$month_padded" \
"minute" "$minute_padded" \
"min" "$minute_padded" \
"second" "$second_padded" \
"sec" "$second_padded" \
"tz_name" "$timezone_name" \
"tz_offset" "$timezone_offset" \
"AM" "$ampm_upper" \
"am" "$ampm_lower" \
"PM" "$ampm_upper" \
"pm" "$ampm_lower"
end