Multi-Search3

Power Up Puppy Lucid510 Linux.Part2-US Holidays In System Prompt And Four More Tips!


Puppy Lucid510 Linux Desktop


In the last article, we discussed start menu customization and LHS taskbar tray customization. Let us continue with four more important tasks here - setting the System Prompt, Aliases, Rightclick-Open/With and Default Programs - four tasks that are useful to any Puppy Lucid510 Linux user at any time whether used at logon or after it.


1. SETTING THE SYSTEM PROMPT 
When useful? At logon or anytime 

Start a terminal [Startmenu-Utility-Urxvt terminal emulator].
See the pound sign[#]?
Now type
#export PS1=''
What happened? Pound's gone. Vanished. We are poor now, too bad, wait a second. Now type
ls
See the file list? Type
df
See the used, free space allocation display?

Hey, stop stop, where do you think are we going with this now?

Easy! Cool down! We just saw the effects of setting the system prompt to null a minute ago with
export PS1='' and got impoverished. Let us reset the system prompt with a better prompt. Type
export PS1="\h"
Got the hostname!
export PS1="\h-\u"
Hostname and the username!
export PS1="\h-\u-\w"
Hostname, username and the current working directory!
export PS1="\h-\u-\w-#"
At last! This code gave us the hostname, userid, current working directory and our pound back! We are rich again now! But why is everything in black and white? Let's add some color to it and also thank a reference site on the net for sharing a variant of the line of code below we are building upon.
export PS1="\[\033[07;35m\]\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w-\[\033[00;31m\]#\[\e[m\]"
Now, we can add our own string[HelloWorld] to display at the very beginning of the system prompt.
export PS1="\[\033[07;34m\]HelloWorld-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w-\[\033[00;31m\]#\[\e[m\]"


While this is okay for this session, we need to do more to get it into the startup configuration file so it will run at every logon.

Steps to change the system prompt

Let's say this is the code for our system prompt.
export PS1="\[\033[07;34m\]HelloWorld-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w-\[\033[00;31m\]#\[\e[m\]"

Changing the system prompt for all users

1.Open a terminal as the root user and type
#cd /etc
2.Type
#geany profile & [Now put the above code at the end of the file, save and exit]
3.Run the command below
#. profile

Changing the system prompt for individual users only

1.Open a terminal as the user and type
$cd [user's home dir]
2.Type
$geany .profile & [Now put the above code at the end of the file, save and exit]
3.Run the command below
$. .profile


Note: In general, in any system where the user logs on using the bash, bourne and korn shells, the .profile file in the user's home directory is run first. In my Puppy Lucid510 Linux system, as I am the ONLY user on my system, I used the /etc/profile file to put this code in there even though it is a system-wide file. On bigger systems with many users, the individual .profile files in each user's home directory must be used instead!


JWhat's Bonus - Display US Holidays In The System Prompt!


Here's a little code block I came up with that you can append to your startup file [user's .profile or system's /etc/profile] to display the month, date and major US holidays in the system prompt. Thanks to a little oneliner I found on a reference site or forum on the net, we also get to colorize the system prompt and to display the hostname, username, and current working directory too!

What? Holidays in system prompt? Who'd want that? Everyone'll be home anyway!

Yeah, but for those who mess with their Linux systems all the time, it may make sense. Again you can add birthdays, anniversaries and important days to make it really useful even on regular days!!!

Requirement
The holiday prompt is refreshed only when the .profile or /etc/profile is run which is at every login/relogin or bootup/reboot. So, remember to put this line of code in a script and run it first thing everyday with cron.

For individual users run this line from a cron-scheduled script everyday at 00:01am
. .profile

For all users run this line from a cron-scheduled script everyday at 00:01am
. /etc/profile

Anyway, here is the code block
#========================================================
#Display major US holidays and more in the system prompt 
#========================================================
dat=`date +"%e,%b"`
if [ "$dat" == " 1,Jan" ]; then 
export PS1="\[\033[07;34m\]$dat-NewYear'sDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == " 6,Jan" ]; then 
export PS1="\[\033[07;34m\]$dat-Epiphany-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == " 2,Feb" ]; then 
export PS1="\[\033[07;34m\]$dat-GroundHogDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == "14,Feb" ]; then 
export PS1="\[\033[07;34m\]$dat-Valentine'sDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == " 8,Mar" ]; then 
export PS1="\[\033[07;34m\]$dat-Women'sDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == " 1,Apr" ]; then 
export PS1="\[\033[07;34m\]$dat-AprilFool'sDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == "14,Jun" ]; then 
export PS1="\[\033[07;34m\]$dat-FlagDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == " 4,Jul" ]; then 
export PS1="\[\033[07;34m\]$dat-4thOfJuly-IndependenceDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == "31,Oct" ]; then 
export PS1="\[\033[07;34m\]$dat-Halloween-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == "11,Nov" ]; then 
export PS1="\[\033[07;34m\]$dat-Veteran'sDay-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == " 8,Dec" ]; then 
export PS1="\[\033[07;34m\]$dat-ImmaculateConceptionOfBVM-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == "24,Dec" ]; then 
export PS1="\[\033[07;34m\]$dat-ChristmasEve-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
elif [ "$dat" == "31,Dec" ]; then 
export PS1="\[\033[07;34m\]$dat-NewYear'sEve-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
else 
export PS1="\[\033[07;34m\]$dat-HelloWorld!-\[\033[07;31m\]\h-\[\033[07;35m\]\u-\[\033[32;40m\]\w\[\033[00;31m\]#\[\e[m\]"
fi
#========================================================


Now, let's make sure that the code block above works correctly!

1.Open the /etc/profile file. Copy the code block above and paste it at the end. Save it.
2.Open a terminal.
3.Set the date to January 1.
Press [Start menu], then [Desktop] and then [Set date and time]. Use arrows by the left and right of the month to go to [January] and set the date to [1]. Press [Ok].
4.In the next window [Set time tool], press [Ok].
5.In the next window [info], press [Ok] and wait for a few seconds.
6.Now, in the terminal, type
# . /etc/profile

If everything's fine we should be seeing "1,Jan-NewYear'sDay..." in the system prompt.

Here's the fun part!
You can accomplish lots of different things other than displaying the dull boring [#] or [$] symbol in the system prompt by modifying the code block above. For example, you can
* Birth days/Anniversaries: 
 Add your own birth day or important family or friends' anniversaries etc.
 [Eg. 3,Mar-Musa'sBirthDay!-puppypc-root-~-#]
* Holidays: 
 Change the holiday list by adding, deleting or changing the holidays.
 [Eg. 1,Jan-NewYear'sDay!-puppypc-root-~-#]
* Reminders[Yoga]: 
 Set aside a week or two and practice one yoga pose per day! 
 It's really fun.[Mountain, Cat, Cow, DFDog, Sphinx...]
 [Eg. 3,Mar-MountainPose!-puppypc-root-~-#]
* Reminders[Todo]: 
 Display a todo item till it is completed.
 [Eg. 3,Mar-CompleteHomePageRedesign!-puppypc-root-~-#]
* Affirmations: 
 Use a one-word affirmation from the list below. Many of these come from 
 a squidoo lens here
 Believe.Smile.Relax.Easy.Think.Practice.Exercise.Learn.Amaze.Build.
 Create.Nurture.Hope.Live.Peace.Listen.Improve.Forgive.Encourage.Dare.Act.
 Excel.
 [Eg. 3,Mar-Smile!-puppypc-root-~-#]
* Favorite Text: 
 Add your name or your favorite person's name or any text at the beginning 
 of the prompt by changing the [HelloWorld!] in the last export statement 
 before the [fi] at the very end if you'd like to. The possibilities are endless.
 [Eg. 3,Mar-Believe!-puppypc-root-~-#]

That's it for the system prompt configuration, let us move to aliases.

2. SETTING COMMAND SHORTCUTS WITH ALIAS
When useful? At logon or anytime

Consider the Linux command "ls". Let us type the following at the system prompt.
#ls -lstrh
This command displays a time sorted, human-readable listing of files in the current directory with the latest files at the end. It would be great if instead of typing
ls -lstrh
every time everywhere we create a shortcut like
l
wouldn't it? We can then type
#l
at the command prompt easily every time! That's what we did in the first line of the alias command list above [See image above]. For a one-time run, we can create a session-expiring alias like this. [Note: My system also allowed me to use single quotes instead of double quotes!]
#alias l="ls -lstrh" 
If we want to be more enterprising, we can put this shortcut into a persistent file that is run by default at every login. In Puppy Lucid510, this persistent config file /root/.bashrc has only one line pointing to
#. /etc/profile
and /etc/profile in turn is used to store all default login configuration parameters. So, let us open the /etc/profile file and put these lines at the end of the file. Since /etc/profile is run every time the /root/.bashrc file is run, which is at every logon, we're all set! [Note: Bigger systems with many users must use the .profile file at the user's home directory instead] Let's test it out real quick. First open /etc/profile with geany text editor.
#geany /etc/profile & 
Let's type this line at the end of this file.
alias l="ls -lstrh"
Let's save this file and run /root/.bashrc for our changes to take effect immediately.
#. /root/.bashrc
Once we have done the above we can then simply type 'l' at the dollar prompt from a terminal in any directory to view a neat, time-sorted and human-readable listing!
#l
Did you see the listing as we expected? I did!


3. CREATING SOFTLINKS FOR THE ROX-FILER RIGHTCLICK OPENWITH/SENDTO 
When useful? At logon or anytime

It's easy to customize the way we want to open different file types with different programs of our choice in Puppy Lucid510. For example, assume we want to rightclick on a html file and open it with Chromium, Firefox or Opera. This is what we need to do.

ln -s /usr/bin/chromium-browser /root/.config/rox.sourceforge.net/SendTo/chrome 
ln -s /usr/bin/firefox /root/.config/rox.sourceforge.net/SendTo/firefox 
ln -s /usr/bin/opera /root/.config/rox.sourceforge.net/SendTo/opera 

We have just created three softlinks for these three programs at the 
[/root/.config/rox.sourceforge.net/SendTo] folder. Changes take place immediately
so we can rightclick on a html file and select [OpenWith] to make sure we can open it with any of the
three browsers mentioned above.

NOTE: The information below comes from the window that opens when we rightclick on a file or folder and choose [File] or [Dir] menu, then select [Openwith] and then select [Customize] at the bottom.

The [Send To] menu provides a quick way to send some files to an application. 
The applications listed are those in the following directories:

/root/.config/rox.sourceforge.net/SendTo
/etc/xdg/rox.sourceforge.net/SendTo

I'll show you your SendTo directory now; you should symlink (Ctrl+Shift drag) 
any applications you want into it. The 'Send To' menu may be opened by Shift+Menu clicking over a file.

Advanced use:
You can also create subdirectories called '.text_html', '.text', etc which will 
only be shown for files of that type. '.group' is shown only when multiple files 
are selected.


4. SETTING DEFAULT PROGRAMS FOR DIFFERENT FILE TYPES
When useful? At logon or anytime 

What, you are not satisfied with a [Rightclick-Open/With] strategy? We can also easily configure a program to open a filetype by default whenever we click on it. Just run these lines from the commandline or from within a script
#browser-chromium
echo '#!/bin/sh
exec chromium-browser "$@" '> /usr/local/bin/defaultbrowser
Now whenever we click on ANY html file it will be opened by Chromium. Just change it to Firefox or Opera if required.


5. BONUS TIP: INFINITE LOOP TO CHECK STATUS OF FILE COPY OR FILE DOWNLOAD

Whether we are copying a giant 1gb or bigger file locally, or downloading stuff over slow internet, there is an easy way to check progress from the commandline.
while true; do du /your-folder/your-giant-file ; sleep 20; date; done
First note the size of the source file before copying/download begins. Then run this command and see how it keeps updating the terminal with the latest file size every 20 seconds and so if the file size is the same several times, the download probably stopped with success or errors. We can press [Ctrl-C] to break out of the loop and check if the file has been downloaded successfully or copied fully and/or rerun the loop command if needed. The [date] command gives a timestamp to tie up the [file size] to. Change the [time interval] to repeat as needed.


Bye! Bye! Woof! Woof!

This completes part2 and also concludes the PowerUp Puppy Lucid510 Linux-Tips To Customize The Startup Sequence Series. There are tons of Linux distributions out there but we need to pick and choose the best one for our needs and requirements. Puppy Linux is a great choice especially if you want a Linux Live CD distribution in the 100-200 MB category that comes with a great working base image and also has a host of pets and other utilities to build up on.

That's really great, isn't it?

Last Updated: 11/3/2013.

BlogCollage


Blog Collage - Top Random Posts In No Particular Order

Mouseover the images for title and comments

Most Recent Posts