Ignore CVS and svn directories in bash autocompletion.

2012-07-07 1 min read Bash Linux

CVS and SVN directories are something that really cause lot of un-necessary nuisance. So, simple solution just ignore them 🙂

export FIGNORE=CVS:~:.o:.svn
bind 'set match-hidden-files off'
Enhanced by Zemanta

Filename completion in Linux with mixed case and ignored case.

2010-06-23 1 min read Bash Linux

This is one of my favourites, alwahs keep it handy. Linux is case sensitive by nature but you will always find filenames jumbled up in the case. So what is the solution:

bind ”set completion-ignore-case on”

Just execute the above in your bash command and file/dir name will behave like Windows. Remember that this is per session setting and thus the names do not get changed internally, it only changes the way to access it (specifically completion only). So if you want this behaviour in all your sessions put this in the appropriate profile file.

Continue reading

Verify all the paths in the PATH directory

2010-06-08 1 min read Bash Learning Linux

Here is the command to test that all the directories in your path actually exist.

(<a class="zem_slink freebase/en/internal_field_separator" title="Internal field separator" rel="wikipedia" href="http://en.wikipedia.org/wiki/Internal_field_separator">IFS=:;for p in $PATH; do test -d $p || echo $p; done)

And the explanation :

Set the IFS to &#8221;:&#8221;

now we loop through the PATH variable

and test all the directories with &#8221;test -d&#8221;

Here is another version without IFS:

for i in ${PATH//:/ };do test  -d $i || echo $i;done

Continue reading

colors in bash -- script to display all the possible colors.

2010-06-06 3 min read Bash Fedora Linux

If you wanted to have colors in the bash output (including the colors in PS1-4), don&#8217;t you keep wondering how the color code would look on the terminal. So, I wrote this small script to show the complete color codes. This is how the output would look:

\"Bash

And here is the script:

  <td>
    <div class="text codecolorer">
      #!/bin/bash -<br /> #===============================================================================<br /> #<br /> # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE: &nbsp;colors.sh<br /> #<br /> # &nbsp; &nbsp; &nbsp; &nbsp; USAGE: &nbsp;./colors.sh<br /> #<br /> # &nbsp; DESCRIPTION: &nbsp;Bash colors<br /> #<br /> # &nbsp; &nbsp; &nbsp; OPTIONS: &nbsp;---<br /> # &nbsp;REQUIREMENTS: &nbsp;---<br /> # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BUGS: &nbsp;---<br /> # &nbsp; &nbsp; &nbsp; &nbsp; NOTES: &nbsp;---<br /> # &nbsp; &nbsp; &nbsp; &nbsp;AUTHOR: &nbsp;Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in<br /> # &nbsp; &nbsp; &nbsp; COMPANY: &nbsp;Individual<br /> # &nbsp; &nbsp; &nbsp; VERSION: &nbsp;1.0<br /> # &nbsp; &nbsp; &nbsp; CREATED: &nbsp;09/21/2009 06:12:07 PM IST<br /> # &nbsp; &nbsp; &nbsp;REVISION: &nbsp;---<br /> #===============================================================================<br /> <br /> for c in `seq 0 255`;<br /> do<br /> t=5;<br /> [[ $c -lt 108 ]]&&t=0;<br /> for i in `seq $t 5`;<br /> do<br /> #Display the codes also for easier lookup in terminal<br /> <!--loginview start-->echo $i;${c}<!--loginview end--><br /> echo -e "<a class="zem_slink" title="Path (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Path_%28computing%29">\\</a>\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d \'[0-9]\'`\\e[0m";<br /> done;<br /> done<br /> <br /> # setup_colors - Adds colors to array CC for global use<br /> # 30 - Black, 31 - Red, 32 - Green, 33 - Yellow, 34 - Blue,<br /> # 35 - Magenta, 36 - Blue/Green, 37 - White,<br /> # 30/42 - Black on Green \'30\\;42\'<br /> <!--loginview start-->function setup_colors(){<br /> declare -a CC;<br /> for i in `seq 0 7`;<br /> do<br /> ii=$(($i+7));<br /> CC[$i]="\\033[1;3${i}m";<br /> CC[$ii]="\\033[0;3${i}m";<br /> done;<br /> CC[15]="\\033[30;42m";<br /> R=$\'\\033[0;00m\';<br /> X=$\'\\033[1;37m\';<br /> export R X;<br /> }<br /> function display_colors(){<br /> for i in $(seq 0 $((${#CC[@]} - 1))); do echo -e "${CC[$i]}[$i]\\n$R"; done<br /> }
    </div>
  </td>
</tr>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
\"Reblog
Enhanced by Zemanta

Modifying the <dot>bashrc or bash startup files.

2010-06-03 20 min read Linux

Find the article <a href="http://blog.infinitered.com/entries/show/4">here.

Copy here:<div class="entrybody">

If you&#8217;ve been learning the <a set="yes" linkindex="8" href="http://en.wikipedia.org/wiki/Command_line_interface" title="Wikipedia Entry: Command line interface">command-line and you have the basics down (you should be, as the most effective way to use a computer is a combination of a GUI and command-line), the next step is to customize your environment.<div class="info_box">

<span class="info_box_title">Beginner&#8217;s Tip: &#8221;command-line&#8221; and &#8221;shell&#8221; are often used synonymously. In unix, technically speaking, the shell is what processes the command-line, but usually, they mean the same thing

The ability to fully customize your <a set="yes" linkindex="9" href="http://en.wikipedia.org/wiki/Unix_shell" title="Wikipedia Entry: Unix Shell (computing)">shell is one of the most powerful things about the command-line. It&#8217;s a dry subject, and mastering it won&#8217;t get you favors from the opposite sex (although it should), but it can be very useful.

There are many ways to customize your shell, but the first one you should learn is modifying your <a linkindex="10" href="http://en.wikipedia.org/wiki/bash" title="Wikipedia Entry: bash">Bash startup files (assuming your shell is Bash, which is the default in OS X, Linux, and many other unices).

When I first learned how to customize bash, I found an overwhelming amount of information and opinion, which made it difficult. This article is intended to give you the fundamental concepts so that you can create your own startup files, and understand how they work. To give you an example, I go through a subset of my own files, section by section.

Let&#8217;s install the example startup files<div class="info_box">

<span class="info_box_title">Beginner&#8217;s Tip: Directory and folder are synonymous. Often folder is used in Windows and OS X and directory is used in Linux, however even Linux represents a directory as a folder graphically

Below are the two example startup files: .bashrc and .bash_profile.

If you would like to use these as your startup files, follow the following directions for your OS.

OS X:

  1. If you want a backup of your existing files, use the following commands (if the files don&#8217;t already exist, you will get an error. The files will be named .bashrc_ORIGINAL and .bash_profile_ORIGINAL in your home folder):<pre class="textmate-source">cp ~/.bashrc ~/.bashrc_ORIGINAL ; cp ~/.bash_profile ~/.bash_profile_ORIGINAL

  2. Copy <a linkindex="11" href="http://www.infinitered.com/settings/dotfiles/osx/.bash_profile">.bash_profile and <a linkindex="12" href="http://www.infinitered.com/settings/dotfiles/osx/.bashrc">.bashrc to your home folder.
    There are a variety of ways to do this, but the simplest is to use the <a linkindex="13" href="http://en.wikipedia.org/wiki/cURL" title="Wikipedia Entry: cURL">curl command:<pre class="textmate-source">curl -o ~/.bash#1 "http://www.infinitered.com/settings/dotfiles/osx/.bash{rc,_profile}"

  3. You do not need to log out, just create a new window or tab in iTerm, or a new window in Terminal.

Linux and other unices:

  1. If you want a backup of your existing files, use the following commands (if the files don&#8217;t already exist, you will get an error. The files will be named .bashrc_ORIGINAL and .bash_profile_ORIGINAL in your home folder):<pre class="textmate-source">cp ~/.bashrc ~/.bashrc_ORIGINAL ; cp ~/.bash_profile ~/.bash_profile_ORIGINAL

  2. Copy <a linkindex="14" href="http://www.infinitered.com/settings/dotfiles/generic/.bash_profile">.bash_profile and <a linkindex="15" href="http://www.infinitered.com/settings/dotfiles/generic/.bashrc">.bashrc to your home directory.
    There are a variety of ways to do this, but the simplest is to use the <a linkindex="16" href="http://en.wikipedia.org/wiki/Wget" title="Wikipedia Entry: Wget">wget (or curl for BSD and others) commands:<pre class="textmate-source">wget -O ~/.bashrc "http://www.infinitered.com/settings/dotfiles/generic/.bashrc"

wget -O ~/.bash\_profile \"http://www.infinitered.com/settings/dotfiles/generic/.bash\_profile\"</pre> 
**or** <pre class=\"textmate-source\">curl -o ~/.bash#1 \"http://www.infinitered.com/settings/dotfiles/generic/.bash{rc,_profile}\"</pre> 
  1. Log out then log back in in order to load .bash_profile. Alternatively, you can do a source ~/.bash_profile to run the files.

What the heck are bash Startup Files?<div class="info_box">

<span class="info_box_title">Beginner&#8217;s Tip: ~ represents your home folder, it is short-hand notation so that you don&#8217;t have to type the whole thing; it is also used when you don&#8217;t know the home folder; for example, my code above works, no matter where your home folder/directory is.

<a linkindex="17" href="http://en.wikipedia.org/wiki/bash" title="Wikipedia Entry: bash">Bash, as well as other <a linkindex="18" href="http://en.wikipedia.org/wiki/Unix_shell" title="Wikipedia Entry: Unix shell">unix shells, have files that run when they start. You can modify these files to set preferences, create aliases and functions (a kind of micro-script), and other such fun.

When you start an interactive shell (log into the console, open terminal/xterm/iTerm, or create a new tab in iTerm) the following files are read and run, in this order:

  1. /etc/profile
  2. /etc/bashrc
  3. ~/.bash_profile
  4. ~/.bashrc (Note: only if you call it in .bash_profile or somewhere else)

When an interactive shell, that is not a login shell, is started (when you call &#8221;bash&#8221; from inside a login shell, or open a new tab in Linux) the following files are read and executed, in this order:

  1. /etc/bashrc
  2. ~/.bashrc<div class="info_box"><span class="info_box_title">Beginner&#8217;s Tip: Normally you can&#8217;t see the . files (files that start with a period) because they are hidden. Depending on your OS, you can simply turn on hidden files. Another option is to open the file in the command-line. Here are a few examples:

In shell: pico .bashrc
In shell: vi .bashrc
In OS X: open .bashrc
In GNOME: gedit .bashrc

/etc/profile and /etc/bashrc are run for all users on the system. Often on your workstation, there is only one user, you. But in systems with more than one user, these files can be used to set generic settings for all users. The files in your home folder, ~/.bashrc and ~/.bash_profile, are only for your particular user (since /etc/bashrc is run before ~/.bashrc, you can override anything in /etc/bashrc by simply setting it again in ~/.bashrc). Normally I only change these, since they are in your home folder, and only you have rights to them, you can change them without worry of affecting anyone else.

When your session starts, these files are run, just as if you typed the commands in yourself. Anything that normally works in the shell works in these files. Since .bash_profile only runs when you first login, you set very little there; the only important thing is your <a linkindex="19" href="http://www.linfo.org/path_env_var.html" title="Path definition">PATH. bashrc is where the meat goes, and will be where you spend all your time.

Continue reading

Bash histoy – common history in different terminals

2010-03-04 1 min read Bash Linux

I have been looking to do this for sometime. The bash history is per
session basis and the last session to quit overwrites the bash_history
file and thus all other terminals started between the time last terminal
lasted does not get to write the commands in the history file. Secondly
the history gets cluttered with lot of duplicate entries and entries
with ls and cd commands. So finally I added these to the bashrc file:

Continue reading
Older posts