Sinisterly
Make your terminal greet you - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Computers (https://sinister.ly/Forum-Computers)
+--- Forum: Operating Systems (https://sinister.ly/Forum-Operating-Systems)
+--- Thread: Make your terminal greet you (/Thread-Make-your-terminal-greet-you)

Pages: 1 2 3


Make your terminal greet you - Deque - 05-17-2013

This is simple, but effective. I just got the idea, because of @MrGeek's terminal thread.
You can make your terminal greet you the right way depending on the daytime plus saying a random quote for your amusal. It might look like this:

[Image: 2sxoxytn.png]

Or this:

[Image: 3dzysp5f.png]

And this is how you do it:

1. Install cowsay and fortune

If you are on Ubuntu:

Code:
sudo apt-get install cowsay sudo apt-get install fortune-mod

2. Put the following python script into your home


Open a text editor of your choice, copy my code into it and save it as welcome.py

Code:
import getpass from datetime import datetime from subprocess import call, Popen, PIPE user = getpass.getuser() hour = datetime.time(datetime.now()).hour if hour >= 22: str = "Sleep Well, " + user + "!" elif hour >= 18: str = "Good Evening, " + user + "!" elif hour >= 14: str = "Good Afternoon, " + user + "!" elif hour >= 12: str = "Enjoy Your Meal, " + user + "!" else: str = "Good Morning, " + user + "!" fortune = Popen(["fortune"], stdout=PIPE).communicate()[0] call(["cowsay", "-f", "tux", str + "\n\n" + fortune])

3. Edit the .bashrc

Add the following line:

Code:
python welcome.py

Now everytime you open your terminal you get an appropriate greeting.

4. Customizing

If you want another ascii picture than tux, you have to edit the last line of the python code and replace tux with i.e.: dragon, cock, snowman, elephant, milk, cow, pony, kiss, koala, gnu, skeleton, ren, moose, sheep ... (see /usr/share/cowsay/cows for the files available)
I.e. to have the dragon you will have to write:

Code:
call(["cowsay", "-f", "dragon", str + "\n\n" + fortune])

Alternatively you can use the randomized welcome.py (shows a random ascii, if you don't like a picture, add it to the blacklist):

Code:
import getpass import random from datetime import datetime from subprocess import call, Popen, PIPE from os import listdir from os.path import isfile, join blacklist = ["beavis.zen", "ghostbusters", "elephant-in-snake", "unipony", "daemon", "sodomized-sheep", "eyes", "kosh", "calvin", "gnu", "kiss", "turkey", "turtle", "pony", "mutilated", "head-in"] #put your unwanted cows in here cowpath = "/usr/share/cowsay/cows" cows = [ f[:-4] for f in listdir(cowpath) if isfile(join(cowpath,f)) and f.endswith(".cow") and f[:-4] not in blacklist ] user = getpass.getuser() hour = datetime.time(datetime.now()).hour random_cow = random.choice(cows) say_or_think = random.choice(["say", "think"]) if hour >= 22: str = "Sleep Well, " + user + "!" elif hour >= 18: str = "Good Evening, " + user + "!" elif hour >= 14: str = "Good Afternoon, " + user + "!" elif hour >= 12: str = "Enjoy Your Meal, " + user + "!" else: str = "Good Morning, " + user + "!" fortune = Popen(["fortune"], stdout=PIPE).communicate()[0] call(["cow" + say_or_think, "-f", random_cow, str + "\n\n" + fortune])



Make your terminal greet you - Deque - 05-17-2013

This is simple, but effective. I just got the idea, because of @MrGeek's terminal thread.
You can make your terminal greet you the right way depending on the daytime plus saying a random quote for your amusal. It might look like this:

[Image: 2sxoxytn.png]

Or this:

[Image: 3dzysp5f.png]

And this is how you do it:

1. Install cowsay and fortune

If you are on Ubuntu:

Code:
sudo apt-get install cowsay sudo apt-get install fortune-mod

2. Put the following python script into your home


Open a text editor of your choice, copy my code into it and save it as welcome.py

Code:
import getpass from datetime import datetime from subprocess import call, Popen, PIPE user = getpass.getuser() hour = datetime.time(datetime.now()).hour if hour >= 22: str = "Sleep Well, " + user + "!" elif hour >= 18: str = "Good Evening, " + user + "!" elif hour >= 14: str = "Good Afternoon, " + user + "!" elif hour >= 12: str = "Enjoy Your Meal, " + user + "!" else: str = "Good Morning, " + user + "!" fortune = Popen(["fortune"], stdout=PIPE).communicate()[0] call(["cowsay", "-f", "tux", str + "\n\n" + fortune])

3. Edit the .bashrc

Add the following line:

Code:
python welcome.py

Now everytime you open your terminal you get an appropriate greeting.

4. Customizing

If you want another ascii picture than tux, you have to edit the last line of the python code and replace tux with i.e.: dragon, cock, snowman, elephant, milk, cow, pony, kiss, koala, gnu, skeleton, ren, moose, sheep ... (see /usr/share/cowsay/cows for the files available)
I.e. to have the dragon you will have to write:

Code:
call(["cowsay", "-f", "dragon", str + "\n\n" + fortune])

Alternatively you can use the randomized welcome.py (shows a random ascii, if you don't like a picture, add it to the blacklist):

Code:
import getpass import random from datetime import datetime from subprocess import call, Popen, PIPE from os import listdir from os.path import isfile, join blacklist = ["beavis.zen", "ghostbusters", "elephant-in-snake", "unipony", "daemon", "sodomized-sheep", "eyes", "kosh", "calvin", "gnu", "kiss", "turkey", "turtle", "pony", "mutilated", "head-in"] #put your unwanted cows in here cowpath = "/usr/share/cowsay/cows" cows = [ f[:-4] for f in listdir(cowpath) if isfile(join(cowpath,f)) and f.endswith(".cow") and f[:-4] not in blacklist ] user = getpass.getuser() hour = datetime.time(datetime.now()).hour random_cow = random.choice(cows) say_or_think = random.choice(["say", "think"]) if hour >= 22: str = "Sleep Well, " + user + "!" elif hour >= 18: str = "Good Evening, " + user + "!" elif hour >= 14: str = "Good Afternoon, " + user + "!" elif hour >= 12: str = "Enjoy Your Meal, " + user + "!" else: str = "Good Morning, " + user + "!" fortune = Popen(["fortune"], stdout=PIPE).communicate()[0] call(["cow" + say_or_think, "-f", random_cow, str + "\n\n" + fortune])



RE: Make your terminal greet you - Psycho_Coder - 05-17-2013

I use ubuntu I'll try it out. Thank you Confusedmiling:

One more thing Can we use ASCII art that we make by ourselves ?


RE: Make your terminal greet you - Psycho_Coder - 05-17-2013

I use ubuntu I'll try it out. Thank you Confusedmiling:

One more thing Can we use ASCII art that we make by ourselves ?


RE: Make your terminal greet you - Deque - 05-17-2013

If you edit it this way, yes.
Either create the ascii art within the python file or add a new cowsay file.


RE: Make your terminal greet you - Deque - 05-17-2013

If you edit it this way, yes.
Either create the ascii art within the python file or add a new cowsay file.


RE: Make your terminal greet you - RogueCoder - 05-17-2013

I got the following error

Code:
File ".bashgreet", line 11 SyntaxError: Non-ASCII character '\xc2' in file .bashgreet on line 11, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Update: Fixed it. Had to re-indent all "str =" lines Wink

Another update: Sorry, forgot to say thanks for this @Deque Smile So, thanks! I like nerdy stuff like this Smile


RE: Make your terminal greet you - RogueCoder - 05-17-2013

I got the following error

Code:
File ".bashgreet", line 11 SyntaxError: Non-ASCII character '\xc2' in file .bashgreet on line 11, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Update: Fixed it. Had to re-indent all "str =" lines Wink

Another update: Sorry, forgot to say thanks for this @Deque Smile So, thanks! I like nerdy stuff like this Smile


RE: Make your terminal greet you - Linuxephus™ - 05-17-2013

I used to love how Clement Lefebvre used to incorporate a similar method into the default terminal setup of LinuxMint in the bygone days of Gnome2.


RE: Make your terminal greet you - Linuxephus™ - 05-17-2013

I used to love how Clement Lefebvre used to incorporate a similar method into the default terminal setup of LinuxMint in the bygone days of Gnome2.