删除“上次登录"终端中新选项卡的消息 [英] Remove "last login" message for new tabs in terminal
问题描述
经过一些搜索后,我创建了一个~/.hushlogin
文件,该文件可以工作,但仅适用于新窗口.有没有办法使其也适用于新标签页?
解决方案
这正在运行OS X 10.8.3.我尚未在其他版本上进行过测试,但是只要Terminal具有上述选项,它就应该可以工作.
-
在Terminal.app中,转到首选项"->设置",然后选择您正在使用的配置文件.转到外壳"标签,然后在启动"标题下,选中运行命令:",然后输入框:
login -fpql your-username /bin/bash
用您的实际Unix用户名替换
your-username
.如果您使用的不是默认bash shell,则将/bin/bash
替换为该shell的完整路径(是的,即使您已经在Preferences-> Startup中对其进行了设置.) -
确保未选中在外壳内运行" .
-
如果选择了关闭前提示:仅选择了登录外壳程序和:以外的进程"选项,请将"login"和"bash"添加到不会提示的进程列表中./p>
-
请确保您有一个
~/.bashrc
文件,因为这将是bash从现在开始在启动时使用的文件,而不是~/.bash_profile
.我只是使用此方法引用了另一个文件.您还需要确保其来源为/etc/profile.
说明
即使没有.hushlogin
文件,我们也要使用-q
选项运行login
以告诉它禁止上次登录"消息. (如上所述,login
将仅在cwd中查找该文件,而不是您的主目录,因此,要打开该方法,您需要在每个打开外壳程序的目录中都包含一个.hushlogin
文件.)
问题在于,当您创建一个缺少-q
标志的新外壳程序(我使用的是自制软件的bash版本,因此末尾的怪异bash路径)时,终端会运行类似login -pfl your-username /bin/bash -c exec -la bash /usr/local/bin/bash
的内容.
不幸的是,无法直接更改终端使用的参数,因此我们只是使用终端默认的login -pfl
会话中的login -pfql
来蹦蹦一个新的登录会话.不雅致,但有效.
我们需要具有-q
选项和bash的路径,以使使用以下控件打开的新窗口/标签页:Same Working Directory"选项起作用.如果您不关心该选项,则可以删除该标志和参数,并避免使用上面的.bashrc
内容.
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?
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.
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.)Make sure 'Run inside shell' is unchecked.
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.
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.
这篇关于删除“上次登录"终端中新选项卡的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!