Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Change the qterminal title with an option #1073

Closed
Bluey26 opened this issue Sep 28, 2023 · 6 comments
Closed

[Feature request] Change the qterminal title with an option #1073

Bluey26 opened this issue Sep 28, 2023 · 6 comments

Comments

@Bluey26
Copy link

Bluey26 commented Sep 28, 2023

Is your feature request related to a problem? Please describe.

Hello.

I was wondering if its possible to add in some way, to change the title of a qterminal window.
Lets say i want to open a terminal based program, like newsboat. I would like to change its name from 'Shell No.1' to a more characteristic name like Newsboat or Feeds.
I have found that if i run the following command, the title changes for the current qterminal window:

export PROMPT_COMMAND='echo -ne "\e]2; "$(basename "$(printf "%b \n" "HERE GOES THE TITLE")")" \a"'

Notice the the window name changes to 'HERE GOES THE TITLE'

The problem is that i am not able to run this as a shell script, to automate it in some way that from a '.sh' file qterminal opens with the custom name and the command i would like to run(in my case, newsboat).

It only seems to work if i run manually the command described before, and then what i want to run.
For example, in an open qterminal window,i run the following:

export PROMPT_COMMAND='echo -ne "\e]2; "$(basename "$(printf "%b \n" "HERE GOES THE TITLE")")" \a"' && newboat

What i would expect is a change name and then the program opening.
What i have is that the program opens, then, when i close the program (q) , the title changes.

Describe the solution you'd like

Some 'native' option that allows to change the window title, like qterminal -t Newsboat or the sort, without having to use the command i share up there.

I guess that there should be a way to add that function inside the qterminal options, in a way that lets you change the title with the text added after '-t' , taking it as a string(including the " " around the text, so it respects spaces and special chracters

qterminal -t 'I want this title'

Equals

export PROMPT_COMMAND='echo -ne "\e]2; "$(basename "$(printf "%b \n" "I want this title")")" \a"

I add a .gif showing what i mean, and also the same thing as a video, for a clearer view:

problem

problem.mp4

I have not seen any way to do this, maybe there's already one, but it find it useful.
Thanks.
Bluey.

@yan12125
Copy link
Member

The problem is that i am not able to run this as a shell script, to automate it in some way that from a '.sh' file qterminal opens with the custom name and the command i would like to run(in my case, newsboat).

Maybe this?

echo -ne '\e]2;HERE GOES THE TITLE\a' && newboat

@Bluey26
Copy link
Author

Bluey26 commented Sep 30, 2023

The problem is that i am not able to run this as a shell script, to automate it in some way that from a '.sh' file qterminal opens with the custom name and the command i would like to run(in my case, newsboat).

Maybe this?

echo -ne '\e]2;HERE GOES THE TITLE\a' && newboat

Hello. That seems to work if i add it into the current terminal (its an advance, since it shows the title and then opens the newsboat program).

Unfortunately i am not able to run it as a command ( in a bash script), i even tried to save the command as an alias, but no luck to 'call' it from a .desktop or a .sh file.

I also have tried qterminal && test qterminal | test with no luck

(where test is the alias for the command you provided).

I was planning to run qterminal -p 'myprofile' -e 'This command'
(my profile has different color preferences than my default terminal window).

@yan12125
Copy link
Member

yan12125 commented Oct 9, 2023

Unfortunately i am not able to run it as a command ( in a bash script)

It should work. Could you add more details? For example, actual commands you used, actual file contents you created/modified, and error messages if any.

I was planning to run qterminal -p 'myprofile' -e 'This command'
(my profile has different color preferences than my default terminal window).

If your actual script path includes spaces, make sure qterminal is at least 1.2.0. See #961.

@Bluey26
Copy link
Author

Bluey26 commented Oct 9, 2023

I want to run in a .sh the following:

qterminal -p qterminal-OPACO.ini -e "echo -ne '\e]2;Newsboat\a' && newsboat"

(This should launch a new qterminal tab, with the qterminal-OPACO.ini profile (which has not transparencies) and then
open newsboat. It also should change the terminal title in the process. This does not work, even in an already opened qterminal window (video showing the behavior at the end)

With the command you provided earlier, it is possible to launch, in an already opened qterminal window, Newsboat (my command) and change the window title in the process

echo -ne '\e]2;Newsboat\a' && newboat --> This works, if i have already open a qterminal window.

Since i want to open it from a .sh script, aka a icon in the desktop, i would run:

#!/usr/bin/env bash


qterminal -p "~/.config/qterminal.org/qterminal-OPACO.ini" -e "echo -ne '\e]2;Newsboat\a' && newsboat" 

Which does not worked either.

In the other hand, i am able to run, in a .sh:

#!/usr/bin/env bash

echo -ne '\e]2;Newsboat\a' && newsboat

Which, if i 'run in the terminal', drops me the correct result, but it does not allow me to choose the qterminal profile, it uses the default one.

This one, in the other hand, does load the correct profile, opens the program(if i select 'execute' instead of 'open in terminal' --> I am in LXQt, which has those options in double click into an executable .sh .

#!/usr/bin/env bash
echo -ne '\e]2;Newsboat\a' &&
qterminal -p "~/.config/qterminal.org/qterminal-OPACO.ini" -e "newsboat" 

About qterminal version, i am running qterminal 1.3.0 , which uses Qt 5.15.11


Unrelated:

I have been using qterminal for some quite time, and i noticed that sometimes, the terminal 'prompt' (where you write) behaves strangely when i paste some commands with special characters. For example, those characters used in substitution programs like sed or printf , which sometimes has characters like "% & ' ". Just wanted to mention it, maybe its an already known thing.

I also was wondering if there's such hotkey to delete 'last word' in commands, like text processor programs does with the 'CTRL+ DELETE' , which deletes last word(word until a space) . I have not seen the hotkey in the program keyboard bindings.

PS: i guess that the message shown in the video is unrelated to the problem, it always appears when i lunch qterminal(the one who talks about the font).

testingqterminal.mp4

@yan12125
Copy link
Member

yan12125 commented Oct 9, 2023

Thank you very much for those details. It looks like the issue is from here:

qterminal -p qterminal-OPACO.ini -e "echo -ne '\e]2;Newsboat\a' && newsboat"

qterminal does not parse shell scripts by itself, so you need to use bash to run it:

qterminal -p qterminal-OPACO.ini -e "bash -c \"echo -ne '\e]2;Newsboat\a' && newsboat\""

I have been using qterminal for some quite time, and i noticed that sometimes, the terminal 'prompt' (where you write) behaves strangely when i paste some commands with special characters. For example, those characters used in substitution programs like sed or printf , which sometimes has characters like "% & ' ". Just wanted to mention it, maybe its an already known thing.

Not sure what you mean. Maybe worth another issue or discussion at https://github.com/lxqt/lxqt/discussions.

I also was wondering if there's such hotkey to delete 'last word' in commands, like text processor programs does with the 'CTRL+ DELETE' , which deletes last word(word until a space) . I have not seen the hotkey in the program keyboard bindings.

This is controlled by the shell. For example, I use emacs key bindings in zsh, where Ctrl+W can be used to delete a word.

@Bluey26
Copy link
Author

Bluey26 commented Oct 9, 2023

Awesome, that does work. Thank you very much!! @yan12125

It worked both in a qterminal open tab, and also worked to me in a .sh script.

Inside the .sh , add the shebang, and then the command following the command is provided in previous commentary

--> This is for the record, in case somebody else needs it in the future.


About the 'delete key', i just discovered that it was also CTRL+W in bash. I guess i should check how to change the binding in bash. I thought it was something binded in the terminal, not in the shell variant.

About the strange behavior of the terminal, in where sometimes the 'position' (which is marked by the color bar) is wrong (the bar is in other position, and not in where it should), i think i should find a way to reproduce it, since i do not remember when it was triggered exactly. I only recall it was some kind of 'long command' (several lines) and no more.
Thanks again for your solution, that is what i was looking for.

I guess this issue can be closed.
Bluey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants