Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove "Last login" message for new tabs in terminal

Tags:

terminal

macos

After some search about it I created a ~/.hushlogin file and it worked, but only for new windows. Is there a way to make it work for new tabs too?

like image 599
gibatronic Avatar asked Apr 02 '13 16:04

gibatronic


People also ask

How do I close a terminal tab on a Mac?

In OSX Terminal, hold down the keys ⌘ + Shift while arrowing right or left. This will allow you to switch between active tabs. When on the tab you wish to close, as you noted, ⌘ + w will close that tab.


2 Answers

On Mavericks, creating the empty file ~/.hushlogin removes the line “Last login”, for new windows and new tabs.

On my Mac it works.

like image 168
Nicolas Barbulesco Avatar answered Oct 19 '22 04:10

Nicolas Barbulesco


Solution

This is running OS X 10.8.3. I haven't tested it on other versions, but so long as Terminal has the above option, then it should work.

  1. In Terminal.app, go to Preferences->Settings and select the profile you're using. Go to the 'Shell' tab and under the 'Startup' heading, check 'Run command:' and enter into the box:

    login -fpql your-username /bin/bash
    

    Substitute your-username with your actual Unix username. If you use a shell other than the default bash shell, replace /bin/bash with the full path to that shell (yes, even if you've already set it in Preferences->Startup.)

  2. Make sure 'Run inside shell' is unchecked.

  3. If you have the "Prompt before closing: Only if there are processes other than login shell and:" option selected, add "login" and "bash" to the list of processes it will not prompt for.

  4. Make sure you have a ~/.bashrc file, since this will be the file bash uses on startup from now on rather than ~/.bash_profile. I just have one file reference the other using this method. You also need to be sure it sources /etc/profile.

Explanation

We want to run login with the -q option to tell it to supress the "Last login" message, even in the absence of a .hushlogin file. (As noted above, login will only look in cwd for that file, not your home directory, so you'd need a .hushlogin file in every directory you'd open a shell to, for that method to work.)

The problem is Terminal runs something like login -pfl your-username /bin/bash -c exec -la bash /usr/local/bin/bash when you create a new shell (I'm using homebrew's version of bash, hence the weird bash path at the end,) which lacks the -q flag.

Unfortunately, there's no way to directly change the arguments Terminal uses, so we just trampoline a new login session with login -pfql from Terminal's default login -pfl session. Inelegant, but it works.

We need to have the -q option and the path to bash to keep the "New windows/tabs open with: Same Working Directory" option working. If you don't care about that option, you can remove that flag and argument, and probably avoid the .bashrc stuff above.

like image 56
2 revs Avatar answered Oct 19 '22 05:10

2 revs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!