LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2006, 03:00 AM   #1
bforbes
LQ Newbie
 
Registered: Apr 2006
Posts: 27

Rep: Reputation: 15
Bash: set Konsole window title to current command


I've been playing around with bash variables like PROMPT_COMMAND and PS1, trying to get the command being executed to be displayed as the Konsole window title. The problem is, both of the above parameters are printed after the command is finished. If I'm running a program that doesn't finish straight away, I'd like the window title to display some info about it. Can this be done?

This is an example of what I've already tried:
Code:
export PROMPT_COMMAND='_last=`fc -l -1 | cut -f 2`;echo -en "\e]0;${_last}\a"'
It doesn't update the window title until after a subsequent command is executed.

I'm running Suse 9.3, Bash 3.00.16(1)-release-(x86_64-suse-linux).
 
Old 04-18-2006, 11:54 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
This seems to me the expected behaviour.
Your prompt command is retrieving the last command stored in history, but at the time it is retrieved, the command just executed is not yet there.

What you really want is a way for the shell to know the next command to come, which obviously it cannot guess.

You could achieve that by using a wrapper around the real commands.
 
Old 04-18-2006, 09:32 PM   #3
bforbes
LQ Newbie
 
Registered: Apr 2006
Posts: 27

Original Poster
Rep: Reputation: 15
How would I create this wrapper? I assume it would just be a script that is called before every command is executed, but I don't know how to do that.
 
Old 04-18-2006, 10:08 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You should call the wrapper instead of the command, passing it the real command to execute.
One way to achieve that would be to have a custom directory in the PATH, where all commands requiring a feedback present as a link to a shell script that set the window title, clear the PATH prefix and call the real command.

The script itself would be something like this, assuming it is in /wrapper/<commands>
Code:
#!/bin/ksh
PATH=$(print $PATH | sed 's/^\/wrapper://')
print -en "\033]0;$0\a"
exec $0 "$@"
 
Old 04-18-2006, 11:41 PM   #5
bforbes
LQ Newbie
 
Registered: Apr 2006
Posts: 27

Original Poster
Rep: Reputation: 15
Thanks, that solution will probably do the trick for what I need, but can you think of a way to make it work for any arbitrary commands?
 
Old 04-19-2006, 11:44 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You'll need to patch the shell for that, and the tricky part would be to make sure only the topmost command is catch, and not all the internal sub commands.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Konsole title bar LocoMojo Linux - Software 2 01-22-2006 10:02 AM
Set the Xterm title to reflect the current time ! Bonch Linux - Newbie 11 10-25-2004 04:50 PM
bash script - open new window running a command zippity Linux - Newbie 1 07-13-2004 11:16 AM
How to set the window title for Eterm dynamically? MiscGeek Linux - Software 4 09-29-2003 09:33 PM
konqueror: how to send current page location and title in uri?? grease Linux - General 2 06-07-2003 10:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration