When terminal is opened can I get current calendar and time displayed? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Terminal splash screen with Weather, Calendar, Time & Sysinfo?I'm looking for a command to flash screens (if possible in colors)How do you start-up in the login screen with Num Lock on?Blank Terminal?Use tty without login every timeHow can I start Linux screen automatically when I open a new terminal window?terminal won't lauch (ubuntu 16.04)How to input chinese character in bash console?How to make a counting prompt in bashTerminal stops working after I run a commandDisplay error when using top with the memory bar or block graphTerminal splash screen with Weather, Calendar, Time & Sysinfo?
Test print coming out spongy
How do living politicians protect their readily obtainable signatures from misuse?
What does Turing mean by this statement?
Should a wizard buy fine inks every time he want to copy spells into his spellbook?
Delete free apps from library
Sally's older brother
Why is a lens darker than other ones when applying the same settings?
What is the chair depicted in Cesare Maccari's 1889 painting "Cicerone denuncia Catilina"?
Is there hard evidence that the grant peer review system performs significantly better than random?
Why datecode is SO IMPORTANT to chip manufacturers?
Tips to organize LaTeX presentations for a semester
Trying to understand entropy as a novice in thermodynamics
Is there public access to the Meteor Crater in Arizona?
Does the Black Tentacles spell do damage twice at the start of turn to an already restrained creature?
Can you force honesty by using the Speak with Dead and Zone of Truth spells together?
Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?
Universal covering space of the real projective line?
If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?
Is openssl rand command cryptographically secure?
Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?
Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?
Would color changing eyes affect vision?
What is the origin of 落第?
White walkers, cemeteries and wights
When terminal is opened can I get current calendar and time displayed?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Terminal splash screen with Weather, Calendar, Time & Sysinfo?I'm looking for a command to flash screens (if possible in colors)How do you start-up in the login screen with Num Lock on?Blank Terminal?Use tty without login every timeHow can I start Linux screen automatically when I open a new terminal window?terminal won't lauch (ubuntu 16.04)How to input chinese character in bash console?How to make a counting prompt in bashTerminal stops working after I run a commandDisplay error when using top with the memory bar or block graphTerminal splash screen with Weather, Calendar, Time & Sysinfo?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When pressing Ctrl+Alt+T to open the terminal I get a blank screen with a simplistic input prompt.
Is it possible (by modifying ~/.bashrc
perhaps) to display the current calendar with today highlighted and the current time?
If the time can be displayed in large numbers (using figlet?) that would be a bonus.
command-line bash bashrc
add a comment |
When pressing Ctrl+Alt+T to open the terminal I get a blank screen with a simplistic input prompt.
Is it possible (by modifying ~/.bashrc
perhaps) to display the current calendar with today highlighted and the current time?
If the time can be displayed in large numbers (using figlet?) that would be a bonus.
command-line bash bashrc
add a comment |
When pressing Ctrl+Alt+T to open the terminal I get a blank screen with a simplistic input prompt.
Is it possible (by modifying ~/.bashrc
perhaps) to display the current calendar with today highlighted and the current time?
If the time can be displayed in large numbers (using figlet?) that would be a bonus.
command-line bash bashrc
When pressing Ctrl+Alt+T to open the terminal I get a blank screen with a simplistic input prompt.
Is it possible (by modifying ~/.bashrc
perhaps) to display the current calendar with today highlighted and the current time?
If the time can be displayed in large numbers (using figlet?) that would be a bonus.
command-line bash bashrc
command-line bash bashrc
edited Apr 12 '17 at 21:53
WinEunuuchs2Unix
asked Apr 8 '17 at 0:02
WinEunuuchs2UnixWinEunuuchs2Unix
48.3k1197187
48.3k1197187
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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 uses future
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 the figlet
package which it is forked from. To install the package use sudo apt install toilet
after installing figlet
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 named now
but you can use any unique name you like.
#!/bin/bash
# NAME: now
# PATH: $HOME/bin
# DESC: Display current calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Apr 10, 2017.
# NOTE: To display all available toilet fonts use this one-liner:
# for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
# calendar current month with today higlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
# 36=cyan, 37=white
printf "33[36m" # color 36=cyan
echo ""; cal;
printf "33[00m" # color bright white (default)
echo ""
tput sc # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf 25 # Move 25 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
# else use standard font
else
echo $(date +"%I:%M %P") > /tmp/terminal
fi
while IFS= read -r Time; do
printf "33[01;32m" # color green
printf "$Time"
tput cud1 # Up one line
tput cuf 25 # Move 25 columns right
done < /tmp/terminal
tput rc # Restore saved cursor position.
exit 0
Mark script as executable
Copy this code into your editor and save it to the file now
. Next mark it as executable using:
sudo chmod +x now
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:
- Edit the file
~/.bashrc
- Go to the end and insert a new line containing
now
- Save the file
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
and toilet
packages
The script first checks if toilet
is installed with the hash
command. If so that is used to display time. If not figlet
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
and toilet
fonts on your terminal:
for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
To change the font used for time display search the code for this line:
toilet -f future --filter border > /tmp/terminal
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:
printf "33[36m" # color 36=cyan
Change the last two digits to the color code you want to use. From tinkering with the code I found these values:
00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple, 36=cyan, 37=white
If you find additional color codes please post a comment below or update this answer.
The bashrc shouldn't produce any output (though I can't remember the reason why). So instead of justnow
, it may be better to put this line in it:PROMPT_COMMAND='[[ $now_already_run != yes ]] && now_already_run=yes && now'
– wjandrea
Apr 8 '17 at 17:53
@wjandrea The closest I could find is this: stackoverflow.com/questions/12440287/… however it has a different solution. Let's leave our comments here until someone reports a problem that can be reproduced and then fix it?
– WinEunuuchs2Unix
Apr 9 '17 at 0:10
There's certainly a niche case where running a command withbash -ic <command>
produces unexpected output, but I can't think of a situation where that would be a problem.
– wjandrea
Apr 9 '17 at 2:06
Colors are ANSI escape sequences. More info and a list here: misc.flogisoft.com/bash/tip_colors_and_formatting
– wjandrea
Apr 12 '17 at 21:22
add a comment |
If you just want a simple time and date you can add these to the end of your .bashrc:
echo -e "Welcome to [$(hostname)] You are logged in as user [$USER]"
echo -e "Local time: [$(date)]"
which will display the following when you login:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
I have a python script I wrote that will add local weather and your WAN and LAN IPs to your .bashrc file as well. Set a cronjob to update the weather. It comes with a sample .bashrc also
It will display:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
[Local weather]: 68.68 F with few clouds
[Your public IP is]: 1.2.3.4 [Local IP]: 192.168.2.6
If you want to take it a step further you can add extra colors and formatting to make your values match your profile
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f901393%2fwhen-terminal-is-opened-can-i-get-current-calendar-and-time-displayed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 uses future
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 the figlet
package which it is forked from. To install the package use sudo apt install toilet
after installing figlet
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 named now
but you can use any unique name you like.
#!/bin/bash
# NAME: now
# PATH: $HOME/bin
# DESC: Display current calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Apr 10, 2017.
# NOTE: To display all available toilet fonts use this one-liner:
# for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
# calendar current month with today higlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
# 36=cyan, 37=white
printf "33[36m" # color 36=cyan
echo ""; cal;
printf "33[00m" # color bright white (default)
echo ""
tput sc # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf 25 # Move 25 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
# else use standard font
else
echo $(date +"%I:%M %P") > /tmp/terminal
fi
while IFS= read -r Time; do
printf "33[01;32m" # color green
printf "$Time"
tput cud1 # Up one line
tput cuf 25 # Move 25 columns right
done < /tmp/terminal
tput rc # Restore saved cursor position.
exit 0
Mark script as executable
Copy this code into your editor and save it to the file now
. Next mark it as executable using:
sudo chmod +x now
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:
- Edit the file
~/.bashrc
- Go to the end and insert a new line containing
now
- Save the file
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
and toilet
packages
The script first checks if toilet
is installed with the hash
command. If so that is used to display time. If not figlet
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
and toilet
fonts on your terminal:
for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
To change the font used for time display search the code for this line:
toilet -f future --filter border > /tmp/terminal
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:
printf "33[36m" # color 36=cyan
Change the last two digits to the color code you want to use. From tinkering with the code I found these values:
00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple, 36=cyan, 37=white
If you find additional color codes please post a comment below or update this answer.
The bashrc shouldn't produce any output (though I can't remember the reason why). So instead of justnow
, it may be better to put this line in it:PROMPT_COMMAND='[[ $now_already_run != yes ]] && now_already_run=yes && now'
– wjandrea
Apr 8 '17 at 17:53
@wjandrea The closest I could find is this: stackoverflow.com/questions/12440287/… however it has a different solution. Let's leave our comments here until someone reports a problem that can be reproduced and then fix it?
– WinEunuuchs2Unix
Apr 9 '17 at 0:10
There's certainly a niche case where running a command withbash -ic <command>
produces unexpected output, but I can't think of a situation where that would be a problem.
– wjandrea
Apr 9 '17 at 2:06
Colors are ANSI escape sequences. More info and a list here: misc.flogisoft.com/bash/tip_colors_and_formatting
– wjandrea
Apr 12 '17 at 21:22
add a comment |
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 uses future
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 the figlet
package which it is forked from. To install the package use sudo apt install toilet
after installing figlet
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 named now
but you can use any unique name you like.
#!/bin/bash
# NAME: now
# PATH: $HOME/bin
# DESC: Display current calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Apr 10, 2017.
# NOTE: To display all available toilet fonts use this one-liner:
# for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
# calendar current month with today higlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
# 36=cyan, 37=white
printf "33[36m" # color 36=cyan
echo ""; cal;
printf "33[00m" # color bright white (default)
echo ""
tput sc # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf 25 # Move 25 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
# else use standard font
else
echo $(date +"%I:%M %P") > /tmp/terminal
fi
while IFS= read -r Time; do
printf "33[01;32m" # color green
printf "$Time"
tput cud1 # Up one line
tput cuf 25 # Move 25 columns right
done < /tmp/terminal
tput rc # Restore saved cursor position.
exit 0
Mark script as executable
Copy this code into your editor and save it to the file now
. Next mark it as executable using:
sudo chmod +x now
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:
- Edit the file
~/.bashrc
- Go to the end and insert a new line containing
now
- Save the file
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
and toilet
packages
The script first checks if toilet
is installed with the hash
command. If so that is used to display time. If not figlet
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
and toilet
fonts on your terminal:
for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
To change the font used for time display search the code for this line:
toilet -f future --filter border > /tmp/terminal
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:
printf "33[36m" # color 36=cyan
Change the last two digits to the color code you want to use. From tinkering with the code I found these values:
00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple, 36=cyan, 37=white
If you find additional color codes please post a comment below or update this answer.
The bashrc shouldn't produce any output (though I can't remember the reason why). So instead of justnow
, it may be better to put this line in it:PROMPT_COMMAND='[[ $now_already_run != yes ]] && now_already_run=yes && now'
– wjandrea
Apr 8 '17 at 17:53
@wjandrea The closest I could find is this: stackoverflow.com/questions/12440287/… however it has a different solution. Let's leave our comments here until someone reports a problem that can be reproduced and then fix it?
– WinEunuuchs2Unix
Apr 9 '17 at 0:10
There's certainly a niche case where running a command withbash -ic <command>
produces unexpected output, but I can't think of a situation where that would be a problem.
– wjandrea
Apr 9 '17 at 2:06
Colors are ANSI escape sequences. More info and a list here: misc.flogisoft.com/bash/tip_colors_and_formatting
– wjandrea
Apr 12 '17 at 21:22
add a comment |
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 uses future
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 the figlet
package which it is forked from. To install the package use sudo apt install toilet
after installing figlet
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 named now
but you can use any unique name you like.
#!/bin/bash
# NAME: now
# PATH: $HOME/bin
# DESC: Display current calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Apr 10, 2017.
# NOTE: To display all available toilet fonts use this one-liner:
# for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
# calendar current month with today higlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
# 36=cyan, 37=white
printf "33[36m" # color 36=cyan
echo ""; cal;
printf "33[00m" # color bright white (default)
echo ""
tput sc # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf 25 # Move 25 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
# else use standard font
else
echo $(date +"%I:%M %P") > /tmp/terminal
fi
while IFS= read -r Time; do
printf "33[01;32m" # color green
printf "$Time"
tput cud1 # Up one line
tput cuf 25 # Move 25 columns right
done < /tmp/terminal
tput rc # Restore saved cursor position.
exit 0
Mark script as executable
Copy this code into your editor and save it to the file now
. Next mark it as executable using:
sudo chmod +x now
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:
- Edit the file
~/.bashrc
- Go to the end and insert a new line containing
now
- Save the file
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
and toilet
packages
The script first checks if toilet
is installed with the hash
command. If so that is used to display time. If not figlet
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
and toilet
fonts on your terminal:
for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
To change the font used for time display search the code for this line:
toilet -f future --filter border > /tmp/terminal
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:
printf "33[36m" # color 36=cyan
Change the last two digits to the color code you want to use. From tinkering with the code I found these values:
00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple, 36=cyan, 37=white
If you find additional color codes please post a comment below or update this 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 uses future
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 the figlet
package which it is forked from. To install the package use sudo apt install toilet
after installing figlet
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 named now
but you can use any unique name you like.
#!/bin/bash
# NAME: now
# PATH: $HOME/bin
# DESC: Display current calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Apr 10, 2017.
# NOTE: To display all available toilet fonts use this one-liner:
# for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
# calendar current month with today higlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
# 36=cyan, 37=white
printf "33[36m" # color 36=cyan
echo ""; cal;
printf "33[00m" # color bright white (default)
echo ""
tput sc # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf 25 # Move 25 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
# else use standard font
else
echo $(date +"%I:%M %P") > /tmp/terminal
fi
while IFS= read -r Time; do
printf "33[01;32m" # color green
printf "$Time"
tput cud1 # Up one line
tput cuf 25 # Move 25 columns right
done < /tmp/terminal
tput rc # Restore saved cursor position.
exit 0
Mark script as executable
Copy this code into your editor and save it to the file now
. Next mark it as executable using:
sudo chmod +x now
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:
- Edit the file
~/.bashrc
- Go to the end and insert a new line containing
now
- Save the file
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
and toilet
packages
The script first checks if toilet
is installed with the hash
command. If so that is used to display time. If not figlet
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
and toilet
fonts on your terminal:
for i in $TOILET_FONT_PATH:=/usr/share/figlet/*.t,flf; do j=$i##*/; toilet -d "$i%/*" -f "$j" "$j%.*"; done
To change the font used for time display search the code for this line:
toilet -f future --filter border > /tmp/terminal
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:
printf "33[36m" # color 36=cyan
Change the last two digits to the color code you want to use. From tinkering with the code I found these values:
00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple, 36=cyan, 37=white
If you find additional color codes please post a comment below or update this answer.
edited 7 mins ago
answered Apr 8 '17 at 0:02
WinEunuuchs2UnixWinEunuuchs2Unix
48.3k1197187
48.3k1197187
The bashrc shouldn't produce any output (though I can't remember the reason why). So instead of justnow
, it may be better to put this line in it:PROMPT_COMMAND='[[ $now_already_run != yes ]] && now_already_run=yes && now'
– wjandrea
Apr 8 '17 at 17:53
@wjandrea The closest I could find is this: stackoverflow.com/questions/12440287/… however it has a different solution. Let's leave our comments here until someone reports a problem that can be reproduced and then fix it?
– WinEunuuchs2Unix
Apr 9 '17 at 0:10
There's certainly a niche case where running a command withbash -ic <command>
produces unexpected output, but I can't think of a situation where that would be a problem.
– wjandrea
Apr 9 '17 at 2:06
Colors are ANSI escape sequences. More info and a list here: misc.flogisoft.com/bash/tip_colors_and_formatting
– wjandrea
Apr 12 '17 at 21:22
add a comment |
The bashrc shouldn't produce any output (though I can't remember the reason why). So instead of justnow
, it may be better to put this line in it:PROMPT_COMMAND='[[ $now_already_run != yes ]] && now_already_run=yes && now'
– wjandrea
Apr 8 '17 at 17:53
@wjandrea The closest I could find is this: stackoverflow.com/questions/12440287/… however it has a different solution. Let's leave our comments here until someone reports a problem that can be reproduced and then fix it?
– WinEunuuchs2Unix
Apr 9 '17 at 0:10
There's certainly a niche case where running a command withbash -ic <command>
produces unexpected output, but I can't think of a situation where that would be a problem.
– wjandrea
Apr 9 '17 at 2:06
Colors are ANSI escape sequences. More info and a list here: misc.flogisoft.com/bash/tip_colors_and_formatting
– wjandrea
Apr 12 '17 at 21:22
The bashrc shouldn't produce any output (though I can't remember the reason why). So instead of just
now
, it may be better to put this line in it: PROMPT_COMMAND='[[ $now_already_run != yes ]] && now_already_run=yes && now'
– wjandrea
Apr 8 '17 at 17:53
The bashrc shouldn't produce any output (though I can't remember the reason why). So instead of just
now
, it may be better to put this line in it: PROMPT_COMMAND='[[ $now_already_run != yes ]] && now_already_run=yes && now'
– wjandrea
Apr 8 '17 at 17:53
@wjandrea The closest I could find is this: stackoverflow.com/questions/12440287/… however it has a different solution. Let's leave our comments here until someone reports a problem that can be reproduced and then fix it?
– WinEunuuchs2Unix
Apr 9 '17 at 0:10
@wjandrea The closest I could find is this: stackoverflow.com/questions/12440287/… however it has a different solution. Let's leave our comments here until someone reports a problem that can be reproduced and then fix it?
– WinEunuuchs2Unix
Apr 9 '17 at 0:10
There's certainly a niche case where running a command with
bash -ic <command>
produces unexpected output, but I can't think of a situation where that would be a problem.– wjandrea
Apr 9 '17 at 2:06
There's certainly a niche case where running a command with
bash -ic <command>
produces unexpected output, but I can't think of a situation where that would be a problem.– wjandrea
Apr 9 '17 at 2:06
Colors are ANSI escape sequences. More info and a list here: misc.flogisoft.com/bash/tip_colors_and_formatting
– wjandrea
Apr 12 '17 at 21:22
Colors are ANSI escape sequences. More info and a list here: misc.flogisoft.com/bash/tip_colors_and_formatting
– wjandrea
Apr 12 '17 at 21:22
add a comment |
If you just want a simple time and date you can add these to the end of your .bashrc:
echo -e "Welcome to [$(hostname)] You are logged in as user [$USER]"
echo -e "Local time: [$(date)]"
which will display the following when you login:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
I have a python script I wrote that will add local weather and your WAN and LAN IPs to your .bashrc file as well. Set a cronjob to update the weather. It comes with a sample .bashrc also
It will display:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
[Local weather]: 68.68 F with few clouds
[Your public IP is]: 1.2.3.4 [Local IP]: 192.168.2.6
If you want to take it a step further you can add extra colors and formatting to make your values match your profile
add a comment |
If you just want a simple time and date you can add these to the end of your .bashrc:
echo -e "Welcome to [$(hostname)] You are logged in as user [$USER]"
echo -e "Local time: [$(date)]"
which will display the following when you login:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
I have a python script I wrote that will add local weather and your WAN and LAN IPs to your .bashrc file as well. Set a cronjob to update the weather. It comes with a sample .bashrc also
It will display:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
[Local weather]: 68.68 F with few clouds
[Your public IP is]: 1.2.3.4 [Local IP]: 192.168.2.6
If you want to take it a step further you can add extra colors and formatting to make your values match your profile
add a comment |
If you just want a simple time and date you can add these to the end of your .bashrc:
echo -e "Welcome to [$(hostname)] You are logged in as user [$USER]"
echo -e "Local time: [$(date)]"
which will display the following when you login:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
I have a python script I wrote that will add local weather and your WAN and LAN IPs to your .bashrc file as well. Set a cronjob to update the weather. It comes with a sample .bashrc also
It will display:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
[Local weather]: 68.68 F with few clouds
[Your public IP is]: 1.2.3.4 [Local IP]: 192.168.2.6
If you want to take it a step further you can add extra colors and formatting to make your values match your profile
If you just want a simple time and date you can add these to the end of your .bashrc:
echo -e "Welcome to [$(hostname)] You are logged in as user [$USER]"
echo -e "Local time: [$(date)]"
which will display the following when you login:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
I have a python script I wrote that will add local weather and your WAN and LAN IPs to your .bashrc file as well. Set a cronjob to update the weather. It comes with a sample .bashrc also
It will display:
Welcome to [deathstar] You are logged in as user [skywalker]
[Local time]: Sun Apr 9 10:18:11 CDT 2017.
[Local weather]: 68.68 F with few clouds
[Your public IP is]: 1.2.3.4 [Local IP]: 192.168.2.6
If you want to take it a step further you can add extra colors and formatting to make your values match your profile
edited Apr 10 '17 at 2:37
muru
1
1
answered Apr 10 '17 at 2:27
Aaron NelsonAaron Nelson
213
213
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f901393%2fwhen-terminal-is-opened-can-i-get-current-calendar-and-time-displayed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown