LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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, 04: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, 12:54 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
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, 10: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, 11:08 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
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-19-2006, 12:41 AM   #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, 12:44 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:02 AM
Set the Xterm title to reflect the current time ! Bonch Linux - Newbie 11 10-25-2004 05:50 PM
bash script - open new window running a command zippity Linux - Newbie 1 07-13-2004 12:16 PM
How to set the window title for Eterm dynamically? MiscGeek Linux - Software 4 09-29-2003 10:33 PM
konqueror: how to send current page location and title in uri?? grease Linux - General 2 06-07-2003 11:40 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration