Merge pull request #538 from dylanaraps/birthday
Birthday: Remove 'date' usage and calclulate date manually
This commit is contained in:
commit
2878b2a85c
4 changed files with 86 additions and 74 deletions
|
@ -39,7 +39,7 @@ print_info() {
|
||||||
# info "Local IP" local_ip
|
# info "Local IP" local_ip
|
||||||
# info "Public IP" public_ip
|
# info "Public IP" public_ip
|
||||||
# info "Users" users
|
# info "Users" users
|
||||||
# info "Birthday" birthday
|
# info "Install Date" install_date
|
||||||
|
|
||||||
info line_break
|
info line_break
|
||||||
info cols
|
info cols
|
||||||
|
@ -292,38 +292,19 @@ public_ip_host="http://ident.me"
|
||||||
song_shorthand="off"
|
song_shorthand="off"
|
||||||
|
|
||||||
|
|
||||||
# Birthday
|
# Install Date
|
||||||
|
|
||||||
|
|
||||||
# Shorten the output of the Birthday functon.
|
|
||||||
#
|
|
||||||
# Default: 'off'
|
|
||||||
# Values: 'on', 'off'
|
|
||||||
# Flag: --birthday_shorthand
|
|
||||||
# Supports: 'off' doesn't work on OpenBSD and NetBSD.
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
# on: 'Thu 14 Apr 2016 11:50 PM'
|
|
||||||
# off: '2016-04-14 23:50:55'
|
|
||||||
birthday_shorthand="off"
|
|
||||||
|
|
||||||
# Whether to show the time in the output
|
# Whether to show the time in the output
|
||||||
#
|
#
|
||||||
# Default: 'on'
|
# Default: 'on'
|
||||||
# Values: 'on', 'off'
|
# Values: 'on', 'off'
|
||||||
# Flag: --birthday_time
|
# Flag: --install_time
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# on: 'Thu 14 Apr 2016 11:50 PM'
|
# on: 'Thu 14 Apr 2016 11:50 PM'
|
||||||
# off: 'Thu 14 Apr 2016'
|
# off: 'Thu 14 Apr 2016'
|
||||||
birthday_time="on"
|
install_time="on"
|
||||||
|
|
||||||
# Date format to use when printing birthday
|
|
||||||
#
|
|
||||||
# Default: '+%a %d %b %Y %l:%M %p'
|
|
||||||
# Values: 'date format'
|
|
||||||
# Flag: --birthday_format
|
|
||||||
birthday_format="+%a %d %b %Y %l:%M %p"
|
|
||||||
|
|
||||||
|
|
||||||
# Text Colors
|
# Text Colors
|
||||||
|
|
|
@ -33,7 +33,7 @@ print_info() {
|
||||||
info "Local IP" local_ip
|
info "Local IP" local_ip
|
||||||
info "Public IP" public_ip
|
info "Public IP" public_ip
|
||||||
info "Users" users
|
info "Users" users
|
||||||
info "Birthday" birthday
|
info "Install Date" install_date
|
||||||
|
|
||||||
info line_break
|
info line_break
|
||||||
info cols
|
info cols
|
||||||
|
|
122
neofetch
122
neofetch
|
@ -1726,73 +1726,51 @@ get_users() {
|
||||||
users="${users%\,*}"
|
users="${users%\,*}"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_birthday() {
|
get_install_date() {
|
||||||
case "$os" in
|
case "$os" in
|
||||||
"Linux" | "GNU" | "iPhone OS")
|
"Linux" | "GNU" | "iPhone OS")
|
||||||
birthday="$(ls -alct --full-time / | awk '/lost\+found|private/ {printf $6 " " $7}')"
|
install_date="$(ls -alct --full-time / | awk '/lost\+found|private/ {printf $6 " " $7}')"
|
||||||
date_cmd="$(date -d"$birthday" "$birthday_format")"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"Mac OS X")
|
"Mac OS X")
|
||||||
birthday="$(ls -lUT /var/log/install.log | awk '{printf $6 " " $7 " " $9 " " $8}')"
|
install_date="$(ls -lUT /var/log/install.log | awk '{printf $9 " " $6 " " $7 " " $8}')"
|
||||||
|
|
||||||
# Split the string into Date + time
|
|
||||||
time="${birthday/*???? }"
|
|
||||||
birthday="${birthday/$time}"
|
|
||||||
|
|
||||||
case "${time/:*}" in
|
|
||||||
0? | 10 | 11) time+=" AM" ;;
|
|
||||||
*) time+=" PM" ;;
|
|
||||||
esac
|
|
||||||
birthday+="$time"
|
|
||||||
birthday_shorthand="on"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"BSD")
|
"BSD")
|
||||||
case "$kernel_name" in
|
case "$kernel_name" in
|
||||||
"OpenBSD"* | "Bitrig"*)
|
"OpenBSD"* | "Bitrig"*)
|
||||||
birthday="$(ls -alctT / | awk '/lost\+found/ {printf $6 " " $7 " " $9 " " $8}')"
|
install_file="/"
|
||||||
birthday_shorthand="on"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"FreeBSD"*)
|
"FreeBSD"*)
|
||||||
birthday="$(ls -alctT /etc/hostid | awk '{printf $6 " " $7 " " $9 " " $8}')"
|
install_file="/etc/hostid"
|
||||||
date_cmd="$(date -j -f "%b %d %Y" "$birthday" "$birthday_format")"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"NetBSD"* | "DragonFly"*)
|
"NetBSD"* | "DragonFly"*)
|
||||||
birthday="$(ls -alctT /etc/defaults/rc.conf | awk '{printf $6 " " $7 " " $9 " " $8}')"
|
install_file="/etc/defaults/rc.conf"
|
||||||
birthday_shorthand="on"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
install_date="$(ls -alctT "$install_file" | awk '{printf $9 " " $6 " " $7 " " $8 " "}')"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"Windows")
|
"Windows")
|
||||||
birthday="$(ls -alct --full-time /cygdrive/c/Windows/explorer.exe | awk '{printf $8 " " $9}')"
|
install_date="$(ls -alct --full-time /cygdrive/c/Windows/explorer.exe | awk '{printf $8 " " $9}')"
|
||||||
date_cmd="$(date -d"$birthday" "$birthday_format")"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"Solaris")
|
"Solaris")
|
||||||
birthday="$(ls -alct --full-time /var/sadm/system/logs/install_log | awk '{printf $6 " " $7}')"
|
install_date="$(ls -alct --full-time /var/sadm/system/logs/install_log | awk '{printf $6 " " $7}')"
|
||||||
date_cmd="$(date -d"$birthday" "$birthday_format")"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"Haiku")
|
"Haiku")
|
||||||
birthday="$(ls -alctd --full-time /boot | awk '{printf $6 " " $7}')"
|
install_date="$(ls -alctd --full-time /boot | awk '{printf $6 " " $7}')"
|
||||||
date_cmd="$(date -d"$birthday" "$birthday_format")"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Strip seconds from time output
|
install_date="${install_date//-/ }"
|
||||||
birthday="${birthday/:?? / }"
|
install_date="${install_date%:*}"
|
||||||
|
install_date=($install_date)
|
||||||
# Pretty output
|
install_date="$(convert_time "${install_date[@]}")"
|
||||||
[[ "$birthday_shorthand" == "off" ]] && \
|
|
||||||
birthday="${date_cmd//+( )/ }"
|
|
||||||
|
|
||||||
# Toggle showing the time
|
|
||||||
[[ "$birthday_time" == "off" ]] && \
|
|
||||||
birthday="${birthday/??:??*}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_cols() {
|
get_cols() {
|
||||||
|
@ -2904,6 +2882,8 @@ old_functions() {
|
||||||
get_publicip() { get_public_ip; publicip="$public_ip"; }
|
get_publicip() { get_public_ip; publicip="$public_ip"; }
|
||||||
get_linebreak() { get_line_break; linebreak="$line_break"; }
|
get_linebreak() { get_line_break; linebreak="$line_break"; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
get_birthday() { get_install_date; birthday="$install_date"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
old_options() {
|
old_options() {
|
||||||
|
@ -2937,6 +2917,66 @@ cache_uname() {
|
||||||
machine_arch="${uname[2]}"
|
machine_arch="${uname[2]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convert_time() {
|
||||||
|
# Convert ls timestamp to 'Tue 06 Dec 2016 4:58 PM' format.
|
||||||
|
year="$1"
|
||||||
|
day="$3"
|
||||||
|
|
||||||
|
# Split time into hours/minutes
|
||||||
|
hour="${4/:*}"
|
||||||
|
min="${4/${hour}}"
|
||||||
|
|
||||||
|
# Get month. (Month code is used for day of week)
|
||||||
|
# Due to different versions of 'ls', the month can be 1, 01 or Jan.
|
||||||
|
case "$2" in
|
||||||
|
1 | 01 | "Jan") month="Jan"; month_code="0" ;;
|
||||||
|
2 | 02 | "Feb") month="Feb"; month_code="3" ;;
|
||||||
|
3 | 03 | "Mar") month="Mar"; month_code="3" ;;
|
||||||
|
4 | 04 | "Apr") month="Apr"; month_code="6" ;;
|
||||||
|
5 | 05 | "May") month="May"; month_code="1" ;;
|
||||||
|
6 | 06 | "Jun") month="Jun"; month_code="4" ;;
|
||||||
|
7 | 07 | "Jul") month="Jul"; month_code="6" ;;
|
||||||
|
8 | 08 | "Aug") month="Aug"; month_code="2" ;;
|
||||||
|
9 | 09 | "Sep") month="Sep"; month_code="5" ;;
|
||||||
|
10 | "Oct") month="Oct"; month_code="0" ;;
|
||||||
|
11 | "Nov") month="Nov"; month_code="3" ;;
|
||||||
|
12 | "Dec") month="Dec"; month_code="5" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Get leap year.
|
||||||
|
# Source: http://stackoverflow.com/questions/725098/leap-year-calculation
|
||||||
|
[[ "$((year % 4))" == 0 && "$((year % 100))" != 0 || "$((year % 400))" == 0 ]] && \
|
||||||
|
[[ "$month" =~ (Jan|Feb) ]] && \
|
||||||
|
leap_code="1"
|
||||||
|
|
||||||
|
# Calculate day of week.
|
||||||
|
# Source: http://blog.artofmemory.com/how-to-calculate-the-day-of-the-week-4203.html
|
||||||
|
year_code="$((${year/??} + $((${year/??} / 4)) % 7))"
|
||||||
|
week_day="$(($((year_code + month_code + 6 + day - ${leap_code:-0})) % 7))"
|
||||||
|
|
||||||
|
case "$week_day" in
|
||||||
|
0) week_day="Sun" ;;
|
||||||
|
1) week_day="Mon" ;;
|
||||||
|
2) week_day="Tue" ;;
|
||||||
|
3) week_day="Wed" ;;
|
||||||
|
4) week_day="Thu" ;;
|
||||||
|
5) week_day="Fri" ;;
|
||||||
|
6) week_day="Sat" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Convert 24 hour time to 12 hour time + AM/PM
|
||||||
|
case "$hour" in
|
||||||
|
[0-9] | 0[0-9] | 1[0-1]) time="${hour/00/12}${min} AM" ;;
|
||||||
|
*) time="$((hour - 12))${min} PM" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Toggle showing the time
|
||||||
|
[[ "$install_time" == "off" ]] && unset time
|
||||||
|
|
||||||
|
# Print the install date.
|
||||||
|
printf "%s" "$week_day $day $month $year $time"
|
||||||
|
}
|
||||||
|
|
||||||
# FINISH UP
|
# FINISH UP
|
||||||
|
|
||||||
usage() { printf "%s" "\
|
usage() { printf "%s" "\
|
||||||
|
@ -2995,9 +3035,7 @@ INFO
|
||||||
--shell_version on/off Enable/Disable showing \$SHELL version
|
--shell_version on/off Enable/Disable showing \$SHELL version
|
||||||
--ip_host url URL to query for public IP
|
--ip_host url URL to query for public IP
|
||||||
--song_shorthand on/off Print the Artist/Title on seperate lines
|
--song_shorthand on/off Print the Artist/Title on seperate lines
|
||||||
--birthday_shorthand on/off Shorten the output of birthday
|
--install_time on/off Enable/Disable showing the time in Install Date output.
|
||||||
--birthday_time on/off Enable/Disable showing the time in birthday output
|
|
||||||
--birthday_format format Format the birthday output. (Uses 'date' cmd format)
|
|
||||||
|
|
||||||
TEXT FORMATTING
|
TEXT FORMATTING
|
||||||
|
|
||||||
|
@ -3156,9 +3194,7 @@ get_args() {
|
||||||
"--shell_version") shell_version="$2" ;;
|
"--shell_version") shell_version="$2" ;;
|
||||||
"--ip_host") public_ip_host="$2" ;;
|
"--ip_host") public_ip_host="$2" ;;
|
||||||
"--song_shorthand") song_shorthand="$2" ;;
|
"--song_shorthand") song_shorthand="$2" ;;
|
||||||
"--birthday_shorthand") birthday_shorthand="$2" ;;
|
"--install_time") install_time="$2" ;;
|
||||||
"--birthday_time") birthday_time="$2" ;;
|
|
||||||
"--birthday_format") birthday_format="$2" ;;
|
|
||||||
"--disable")
|
"--disable")
|
||||||
for func in "$@"; do
|
for func in "$@"; do
|
||||||
case "$func" in
|
case "$func" in
|
||||||
|
|
|
@ -88,14 +88,9 @@ URL to query for public IP
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-song_shorthand\fR on/off
|
\fB\-\-song_shorthand\fR on/off
|
||||||
Print the Artist/Title on seperate lines
|
Print the Artist/Title on seperate lines
|
||||||
.HP
|
|
||||||
\fB\-\-birthday_shorthand\fR on/off Shorten the output of birthday
|
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-birthday_time\fR on/off
|
\fB\-\-install_time\fR on/off
|
||||||
Enable/Disable showing the time in birthday output
|
Enable/Disable showing the time in Install Date output.
|
||||||
.TP
|
|
||||||
\fB\-\-birthday_format\fR format
|
|
||||||
Format the birthday output. (Uses 'date' cmd format)
|
|
||||||
.PP
|
.PP
|
||||||
TEXT FORMATTING
|
TEXT FORMATTING
|
||||||
.TP
|
.TP
|
||||||
|
|
Loading…
Reference in a new issue