In my case I upgraded python3.5 to python3.6.
For that workaround run xterm
. Then run the following two commands:
sudo rm /usr/bin/python3
sudo ln -s python3.5 /usr/bin/python3
now
bash script
NOTE: Updated April 28, 2018 for Ubuntu 18.04 LTS
The heavy lifting is the splash component that shows this:
$ now
Weather report: Edmonton March 2018 ┌────────────────────────────┐
Su Mo Tu We Th Fr Sa │ ┏━┓╺┓ ┏━┓┏━┓ ┏━┓┏┳┓ │
\ / Sunny 1 2 3 │ ┃┃┃ ┃ ╹┏━┛┗━┫ ┣━┛┃┃┃ │
.-. -23--14 °C 4 5 6 7 8 9 10 │ ┗━┛╺┻╸╹┗━╸┗━┛ ╹ ╹ ╹ │
― ( ) ― ↘ 22 km/h 11 12 13 14 15 16 17 └────────────────────────────┘
`-’ 14 km 18 19 20 21 22 23 24
/ \ 0.9 mm 25 26 27 28 29 30 31
Yes it really is -14 in Edmonton and feels like -23. A good time to spend the long-weekend inside playing the newly arrived Tomb Raider 2013! Maybe brush up on that Resume to move to Vancouver or Montreal...
Here is the code:
#!/bin/bash
# NAME: now
# PATH: $HOME/bin
# DESC: Display current weather, calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: May 24, 2019.
# UPDT: 2019-05-24 If Weather unavailable nicely formatted error message.
# NOTE: To display all available toilet fonts use this one-liner:
# for i in ${TOILET_FONT_PATH:=/usr/share/figlet}/*.{t,f}lf; do j=${i##*/}; toilet -d "${i%/*}" -f "$j" "${j%.*}"; done
# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for " " " " 61 " " " "
# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3 > /tmp/now-weather
# Timeout #. Increase for slow connection---^
readarray aWeather < /tmp/now-weather
rm -f /tmp/now-weather
# Was valid weather report found or an error message?
if [[ "${aWeather[0]}" == "Weather report:"* ]] ; then
WeatherSuccess=true
echo "${aWeather[@]}"
else
WeatherSuccess=false
echo "+============================+"
echo "| Weather unavailable now!!! |"
echo "| Check reason with command: |"
echo "| |"
echo "| curl wttr.in/Edmonton?0 |" # Replace Edmonton with your city
echo "| --silent --max-time 3 |"
echo "+============================+"
echo " "
fi
echo " " # Pad blank lines for calendar & time to fit
#--------- DATE -------------------------------------------------------------
# calendar current month with today highlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
# 36=cyan, 37=white
tput sc # Save cursor position.
# Move up 9 lines
i=0
while [ $((++i)) -lt 10 ]; do tput cuu1; done
if [[ "$WeatherSuccess" == true ]] ; then
# Depending on length of your city name and country name you will:
# 1. Comment out next three lines of code. Uncomment fourth code line.
# 2. Change subtraction value and set number of print spaces to match
# subtraction value. Then place comment on fourth code line.
Column=$((DateColumn - 10))
tput cuf $Column # Move x column number
# Blank out ", country" with x spaces
printf " "
else
tput cuf $DateColumn # Position to column 27 for date display
fi
# -h needed to turn off formating: https://askubuntu.com/questions/1013954/bash-substring-stringoffsetlength-error/1013960#1013960
cal > /tmp/terminal1
# -h not supported in Ubuntu 18.04. Use second answer: https://askubuntu.com/a/1028566/307523
tr -cd '\11\12\15\40\60-\136\140-\176' < /tmp/terminal1 > /tmp/terminal
CalLineCnt=1
Today=$(date +"%e")
printf "\033[32m" # color green -- see list above.
while IFS= read -r Cal; do
printf "%s" "$Cal"
if [[ $CalLineCnt -gt 2 ]] ; then
# See if today is on current line & invert background
tput cub 22
for (( j=0 ; j <= 18 ; j += 3 )) ; do
Test=${Cal:$j:2} # Current day on calendar line
if [[ "$Test" == "$Today" ]] ; then
printf "\033[7m" # Reverse: [ 7 m
printf "%s" "$Today"
printf "\033[0m" # Normal: [ 0 m
printf "\033[32m" # color green -- see list above.
tput cuf 1
else
tput cuf 3
fi
done
fi
tput cud1 # Down one line
tput cuf $DateColumn # Move 27 columns right
CalLineCnt=$((++CalLineCnt))
done < /tmp/terminal
printf "\033[00m" # color -- bright white (default)
echo ""
tput rc # Restore saved cursor position.
#-------- TIME --------------------------------------------------------------
tput sc # Save cursor position.
# Move up 8 lines
i=0
while [ $((++i)) -lt 9 ]; do tput cuu1; done
tput cuf $TimeColumn # Move 49 columns right
# Do we have the toilet package?
if hash toilet 2>/dev/null; then
echo " $(date +"%I:%M %P") " | \
toilet -f future --filter border > /tmp/terminal
# Do we have the figlet package?
elif hash figlet 2>/dev/null; then
# echo $(date +"%I:%M %P") | figlet > /tmp/terminal
date +"%I:%M %P" | figlet > /tmp/terminal
# else use standard font
else
# echo $(date +"%I:%M %P") > /tmp/terminal
date +"%I:%M %P" > /tmp/terminal
fi
while IFS= read -r Time; do
printf "\033[01;36m" # color cyan
printf "%s" "$Time"
tput cud1 # Up one line
tput cuf $TimeColumn # Move 49 columns right
done < /tmp/terminal
tput rc # Restore saved cursor position.
exit 0
Save the `~/.bashrc" file changes.
To display the Ubuntu information you need screenfetch
:
sudo apt install screenfetch
There are similar display packages to screenfetch
so shop around!
If you want the same command prompt with "─────────" dividing line between commands, change these lines:
if [ "$color_prompt" = yes ]; then
PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
Note the length of the separator line coincides with width of screenfetch
output. In this case it is 92 characters wide and gnome-terminal
preferences are set accordingly.
Best Answer
Improved Version
You can see the improved version here: https://askubuntu.com/a/1020693/307523
It looks like this:
Original Version
You can print an introduction banner when the terminal is opened using the
~/.bashrc
script. If you have figlet (sudo apt install figlet
) you can take advantage of large letters to display the time:In the first instance
figlet
is used to display the time and in the second a regular font is used.Additional screen examples using
toilet
This screen uses fonts from the
toilet
package. The last example usesfuture
font and is used in the code below. Additionally, the calendar is set to cyan color in the code below.The
toilet
package allows additional font types and formatting styles over thefiglet
package which it is forked from. To install the package usesudo apt install toilet
after installingfiglet
as described above.The code
Here is the code you need to make it all work. It's recommended to place this script in your
/home/user/bin
directory as it is automatically added to your path. This script is namednow
but you can use any unique name you like.Mark script as executable
Copy this code into your editor and save it to the file
now
. Next mark it as executable using:Add script to
~./bashrc
Once this is completed you can type
now
in the terminal and you will see the calendar and time. To wrap it all up and have it automatically displayed each time you open the terminal:~/.bashrc
now
Now when opening the terminal you will be greeted with the current day highlighted on current month's calendar followed by the current time.
Dissecting the code
Here we'll briefly look at how the code works without discussing every line.
figlet
andtoilet
packagesThe script first checks if
toilet
is installed with thehash
command. If so that is used to display time. If notfiglet
is used if installed. If neither are installed a regular font is used.In the code above a comment can be copied to your command line and executed to show available
figlet
andtoilet
fonts on your terminal:To change the font used for time display search the code for this line:
and change the font name
future
to the font name you choose. Keep in mind some fonts are too large to fit on the display.Selecting colors
Set the color you want for the calendar and the time separately. In the above code, notice the command:
Change the last two digits to the color code you want to use. From tinkering with the code I found these values:
If you find additional color codes please post a comment below or update this answer.