Showing posts with label Bash. Show all posts
Showing posts with label Bash. Show all posts

03 May, 2014

Colors and more... in the Terminal

Screenshot of a sample Bash session, taken on ...
Screenshot of a sample Bash session, taken on an old release of Gentoo Linux. (Photo credit: Wikipedia)
03-May-2014


I am one who is comfortable using the Terminal, having used the computer since the DOS days, and while Windows with all its graphical interfaces is very much welcome, as it brings with its GUI tons of changes, I would find myself still at ease doing command lines.

And I would consider sprucing up the Terminal the pinnacle of a die hard's declaration... finding comfort in typing text and cryptic commands, also find comfort at least in seeing different colors in the texts and backgrounds. That's it!

So, I am one like that. I have worked on PROMIS since 1996, and DOS since time immemorial, all command-line systems, and I was very much satisfied just seeing the colors come alive on prompts and errors(!) and all.

And now that I am doing Linux, I craved for the same thing, and fortunately, there was help - from the Community.

I would just put a reference to the article, so I don't duplicate anything.

Here's the link: Customizing Bash Prompt

I hope you enjoy tweaking your prompt, to your own liking, etc., etc.

Till then!

Enhanced by Zemanta

02 May, 2014

And to indicate in terminal prompt if I am a root user

Sample of BASH through a shell in GNOME. Scree...
Sample of BASH through a shell in GNOME. Screenshot taken in Arch Linux (Photo credit: Wikipedia)
02-May-2014


I would have to say that knowing that I am a root user, or that I activated my being a root user, at least in the prompt, to be a big help. Fortunately, somebody has already thought of this, and has also done it, and has shared it.

So either you are the root user, or you can switch between a normal user and a root user, it would be very beneficial to know when a user mode or privelege is active and available.

That being said, I searched the web, and I found one that worked.

It is editing .bashrc and appending these:

# Turn the prompt symbol red if the user is root
if [ $(id -u) -eq 0 ];
then # you are root, make the prompt red
    PS1="[\e[01;34m\u @ \h\e[00m]----[\e[01;34m$(pwd)\e[00m]\n\e[01;31m#\e[00m "
else
    PS1="[\e[01;34m\u @ \h\e[00m]----[\e[01;34m$(pwd)\e[00m]\n$ "
fi

So the .bashrc could be in your /home/username directory.

Or when you invoke superuser by sudo -i (or sudo su), it would be in /root directory.

By employing this, I am able to know when I am a normal user, and when I am a super user. It may be what you need, for all I know. Try it!

Here's the reference: Changing behavior of bash prompt when functioning as root

Till then!


Enhanced by Zemanta

Making terminal(s) remember commands

English: Sample of Bash in GNOME Terminal. Scr...
English: Sample of Bash in GNOME Terminal. Screenshot taken in Fedora Linux. Results of ping, pwd, cd, yum and ls command. فارسی: نمونه‌ای از محیط متنی لینوکس (بش) در نرم‌افزار گنوم ترمینال، توزیع فدورا. خروجی دستورهای ping، pwd، cd، ls، و yum. (Photo credit: Wikipedia)
02-May-2014


Here is another trick that I did, and now I had to re-do, so I am recording it, so I can go back to it anytime.

Edit bashrc: gedit/vi ~/.bashrc
Add at last line: export PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND"

-a switch is to make terminal record the commands
-n is to record the command history from all terminals (so this is an option)

Save and exit, and voila!

To look at command history, just type history and press [Enter]
To run (again) a command, type !number (on the left of the command) and press [Enter]

Here's the reference: [SOLVED] Terminal doesn't remember last commands

Till then!
Enhanced by Zemanta

And... shortening my command line bash prompt

English: Sample of Bash in GNOME Terminal. Scr...
English: Sample of Bash in GNOME Terminal. Screenshot taken in Fedora Linux. Results of ping, pwd, cd, yum and ls command. فارسی: نمونه‌ای از محیط متنی لینوکس (بش) در نرم‌افزار گنوم ترمینال، توزیع فدورا. خروجی دستورهای ping، pwd، cd، ls، و yum. (Photo credit: Wikipedia)
02-May-2014


This may be considered insignificant, but if you are one who sticks to the terminal, or the command line, it would be one sensible action.

Originally, the prompt would show the username and the box manufacturer and model, etc., etc. And this is what I consider 'unsightly'... ugh!

Well, no offense to others, I am just speaking for myself.

But I needed to shorten it, as it tend to fill up the line, without even typing anything.

I just followed what is indicated here, and it worked like a charm. So again, I am keeping a record, so I can go back to it when the need arises.

Edit .bashrc file and make some changes:
1. gedit/vi ~/.bashrc
2. Remove @\h
3. Replace \w with \W (lower case w to capital W)
4. Save and exit terminal.

Upon opening a new terminal window, the change should be effected already.

Reference is here: How can I shorten my command line (bash) prompt?

Till then!

Enhanced by Zemanta