Category Archives: Linux

Linux related.

Show current database on mysql console

I’m sure everyone has at least once deleted something on the wrong database…

In an attempt to avoid that you can rewrite mysql’s PS1 value in order to display the current database you’re on.

Just edit your ~/.bashrc:

1
export MYSQL_PS1="mysql@\d > "

Don’t forget to relaunch it:

1
source ~/.bashrc

Et voila, the old “mysql>” is now replaced with “mysql@current_database>

Sweet :)

Ubuntu inverted scrolling (aka max os x lion style – natural scrolling

Either you hate it, or love it.

I love it, so in order to invert your scrolling follow this steps provided by akosidexter:

1
2
3
4
5
6
7
8
9
10
11
12
tix@adclick-desktop1:~$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Microsoft Comfort Curve Keyboard 2000 id=9 [slave pointer (2)]
⎜ ↳ Microsoft Microsoft 3-Button Mouse with IntelliEye(TM) id=10 [slave pointer (2)]
⎜ ↳ Macintosh mouse button emulation id=11 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Power Button id=7 [slave keyboard (3)]
↳ Microsoft Comfort Curve Keyboard 2000 id=8 [slave keyboard (3)]
tix@adclick-desktop1:~$ xinput set-button-map "Microsoft Microsoft 3-Button Mouse with IntelliEye(TM)" 1 2 3 5 4 6 7 8 9 10 11 12 13 14 15 16

In order to make this effect permanent you got to add the command to:

System > Preferences > Startup Applications.

.bash_profile vs .bashrc

When working with Linux, Unix, and Mac OS X, I always forget which bash config file to edit when I want to set my PATH and other environmental variables for my shell. Should you edit .bash_profile or .bashrc in your home directory?

You can put configurations in either file, and you can create either if it doesn’t exist. But why two different files? What is the difference?

According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
What is a login or non-login shell?

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.
Why two different files?

Say, you’d like to print some lengthy diagnostic information about your machine each time you login (load average, memory usage, current users, etc). You only want to see it on login, so you only want to place this in your .bash_profile. If you put it in your .bashrc, you’d see it every time you open a new terminal window.
Mac OS X — an exception

An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.
Recommendation

Most of the time you don’t want to maintain two separate config files for login and non-login shells — when you set a PATH, you want it to apply to both. You can fix this by sourcing .bashrc from your .bash_profile file, then putting PATH and common settings in .bashrc.

To do this, add the following lines to .bash_profile:

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

Now when you login to your machine from a console .bashrc will be called.

Original post on http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html