qterminal icon indicating copy to clipboard operation
qterminal copied to clipboard

Option to start shell as login shell

Open ritzmann opened this issue 10 years ago • 12 comments

I haven't found a way to start bash as login shell other than invoking qterminal with 'qterminal -e "bash --login"'. It would be much more convenient if that could be a configurable option in qterminal instead.

ritzmann avatar Dec 19 '14 08:12 ritzmann

That's not really qterminal's job is it? Just use chsh to change your default shell...

jleclanche avatar Dec 19 '14 18:12 jleclanche

The term login shell is very ambiguous unfortunately. This is an excellent article that explains the whats and whys that I am looking for: http://www.slackwiki.com/Login_Shell

All the terminal emulators I know have an option to start the shell as login shell. /bin/login does it by prepending a - to the shell name and the shell looks for that character when it is started.

Most newer terminal emulators I know have some kind of preference setting where you enable or disable starting the shell as login shell. Older terminal emulators often take the "-ls" command line parameter. A preference setting is more convenient. A command line parameter on the other hand allows to choose the behavior for each terminal instance individually.

ritzmann avatar Dec 19 '14 21:12 ritzmann

Thanks @ritzmann this "fix" works for me. :smile:

AndersonFirmino avatar Jan 20 '17 03:01 AndersonFirmino

Hi there, I'm a bit late, but stumbled across this issue today, too. Is there a way to configure qterminal such that it'll run bash as a login shell? I wasn't able to do so.

I need that to complete my RVM setup, as described in https://rvm.io/integration/gnome-terminal

datenimperator avatar Mar 14 '18 15:03 datenimperator

@datenimperator Currently a login shell is not implemented yet. You may want to add a line source /etc/profile in your ~/.bashrc.

yan12125 avatar Mar 14 '18 15:03 yan12125

@yan12125 can we implement an option to start shells as login shell - to be honest, i'm selfish, i would like this option too :)

agaida avatar Mar 14 '18 17:03 agaida

Why not :) Just that this feature seems to require lots of time on survey behaviors of different shells, so it may take some time.

yan12125 avatar Mar 14 '18 17:03 yan12125

I'm a new user and liking qterminal. I resolved this on my system by editing MainWindow::newTerminalWindow() in src/mainwindow.cpp, replacing:

    MainWindow *w = new MainWindow(cfg, false);
    w->show();

to this:

    QString command = QStringLiteral("qterminal");
    QStringList args = {QStringLiteral("-e"), QStringLiteral("bash --login")};
    if (!QProcess::startDetached(command, args)) 
        qDebug() << "Failed to start command" << command << args;

Thank you, for qterminal.

marioroy avatar Mar 21 '21 05:03 marioroy

The following is my second attempt so that it honors the UseCWD config setting; i.e. Open new terminals in current working directory.

Original newTerminalWindow()

void MainWindow::newTerminalWindow()
{
    TerminalConfig cfg;
    TermWidgetHolder *ch = consoleTabulator->terminalHolder();
    if (ch)
        cfg.provideCurrentDirectory(ch->currentTerminal()->impl()->workingDirectory());

    MainWindow *w = new MainWindow(cfg, false);
    w->show();
}

Modified newTerminalWindow()

void MainWindow::newTerminalWindow()
{
    TermWidgetHolder *ch = consoleTabulator->terminalHolder();
    QString command = QStringLiteral("qterminal");
    QStringList args;

    if (ch && Properties::Instance()->useCWD)
        args << QStringLiteral("-w") << ch->currentTerminal()->impl()->workingDirectory();

    args << QStringLiteral("-e") << QStringLiteral("bash --login");

    if (!QProcess::startDetached(command, args))
        qDebug() << "Failed to start command" << command << args;
}

For new tabs to work similarly, I set SHELL in ~/.bashrc with the --login argument. Code is currently there in termwidget.cpp to extract any arguments from the SHELL environment variable from what I can tell and pass on to shell.

export SHELL="/bin/bash --login"

Log out and back in. New windows and tabs including split horizontally and vertically behave the same with regards to calling bash with --login. Note that bash is hard-coded in the code above and may not be the user's desired shell.

marioroy avatar Mar 22 '21 00:03 marioroy

As an example of how this could be annoying, Ubuntu's set up by default to add $HOME/bin and $/.local/bin to the $PATH in $HME/.profile when such folders exist. However, that file is sourced only for login shells.

wxl avatar May 18 '23 09:05 wxl

As a workaround in Linux, you can set the $SHELL environment variable to any command like this: SHELL="bash -l" qterminal and it will be opened as a shell in every new tab.

niutech avatar Aug 03 '23 07:08 niutech

Since I use qterminal.desktop to launch it, I create another file with the same name in ~/.local/share/applications and change the line Exec=... with Exec=qterminal -e "bash".

Canvis-Me avatar Jun 29 '24 14:06 Canvis-Me