Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
My own run dialog. Almost done! =P
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
ingemar
Tux's lil' helper
Tux's lil' helper


Joined: 21 May 2005
Posts: 83
Location: Gothenburg, Sweden

PostPosted: Wed Oct 25, 2006 11:50 pm    Post subject: My own run dialog. Almost done! =P Reply with quote

Hi.
So, I'm running openbox, and some of my friends run pekwm. And I've noticed a kind of nice thing with pekwm that openbox didn't have: a run dialog! There are stuff around like bbrun and fbrun, but I didn't know of any more, so I thought that "hmm.. maybe this is possible with bash and my regular terminal?"

So I started thinking, and I've come a long way.
I start my "run dialog" with:
Code:
urxvtc -g 50x1+450+500 -bl -b 6 -e bash --init-file ~/.bashrunbox

And in ~/.bashrunbox I've set PS1 to "" and also added the line
Code:
set -o onecmd
which causes the terminal to quit after executing the command. And the result is really nice!

Although, I've still got one problem, and that is that the terminal still hangs around when I start an application that doesn't terminate immediately. Is there some way to add something to ~/.bashrunbox that makes the terminal quit after the command being run?

As an example, the line 'nohup ' could be added before the command written, and then '&' after. But I know of no way to do this. Any Ideas?
_________________
iBook G4 12" & AMD X2 4200+
Back to top
View user's profile Send private message
Dlareh
Advocate
Advocate


Joined: 06 Aug 2005
Posts: 2102

PostPosted: Thu Oct 26, 2006 12:09 am    Post subject: Reply with quote

edit: nevermind, new version below
_________________
"Mr Thomas Edison has been up on the two previous nights discovering 'a bug' in his phonograph." --Pall Mall Gazette (1889)
Are we THERE yet?


Last edited by Dlareh on Sat Oct 28, 2006 1:10 am; edited 1 time in total
Back to top
View user's profile Send private message
ingemar
Tux's lil' helper
Tux's lil' helper


Joined: 21 May 2005
Posts: 83
Location: Gothenburg, Sweden

PostPosted: Thu Oct 26, 2006 12:22 am    Post subject: Reply with quote

That produces the same result as what I have tried. When running an app like grip the run dialog is still left running...
_________________
iBook G4 12" & AMD X2 4200+
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Thu Oct 26, 2006 12:48 am    Post subject: Reply with quote

Nice, then you will like this one, it is a post that I wrote some time ago, my launcher for fvwm ;)

https://forums.gentoo.org/viewtopic-t-394486-highlight-rxvt.html

That is about rxvt, but with a bit of tweaking it can work exactly the same under rxvt-unicode (urxvt). The key is in the keysyms, for example:

Code:

#!/bin/sh
export PS1="[Exec]: "
export HISTCONTROL="ignorespace"

urxvt +sb -fn "9x15" \
  -name "run"  -title "run" -g 40x3 \
  -fg lightsteelblue -bg '#336699' -cr white \
  --keysym.0xFF0D: " &\n exit\n" \
  --keysym.0xFF1B: " &\ ^C exit\n" \
  -e sh -s


That output a nice shinny blue thing to run commands into (you can configure your wm to automatically make it gain the focus when you launch it, the name of the app and the tittle will be "run" in this example). A nice thing is not only this

Code:
   --keysym.0xFF0D: " &\n exit\n" \

That binds enter to \n + an exit command + another \n (\n is enter).

But this other one
Code:

  --keysym.0xFF1B: " &\ ^C exit\n" \

Which binds ESC to "simulate a control+c and then write "exit" and then press enter". That closes the term when you press ESC, which is what we all expect from a run dialog, dont we? + being based in bash, it has a good history and completion support, the best run dialog ever! :D

EDIT, I forgot one detail that you might have already discovered yourself, the first & in front of the keysym strings is vital for the command to be launched in background, otherwise the term would still be locked until the program is closed.
Back to top
View user's profile Send private message
ingemar
Tux's lil' helper
Tux's lil' helper


Joined: 21 May 2005
Posts: 83
Location: Gothenburg, Sweden

PostPosted: Thu Oct 26, 2006 1:07 am    Post subject: Reply with quote

Smart thinking with --keysum! I've never figured that out...

Now I've got a very nice run dialog, and no unneccasary software was installed.. Hehe..
Thank's a lot!
_________________
iBook G4 12" & AMD X2 4200+
Back to top
View user's profile Send private message
nom de plume
Tux's lil' helper
Tux's lil' helper


Joined: 01 Jun 2006
Posts: 104

PostPosted: Thu Oct 26, 2006 2:48 am    Post subject: Reply with quote

Is there a way to get this to work with xterm? It barfs on "--keysum"

[edit] Okay, urxvt/rxvt is fine, I'll just stick with that. I think we can improve on this, though. How about:

(1) tab-completion cycles through options instead of giving a newline. I think I can get this to work with zsh but I can't get zsh to accept a nonstandard init file so I'm trying to persuade bash to do it.
done: see post below.

(2) A third execute key sequence (in addition to enter/esc) that executes the command in a new terminal window. Say you want to run 'emerge' or some other command from this run dialog.

(3) smart-launching: if you enter a web address pop open a browser, etc.

Any other ideas? Remember you also have the power of aliases and all the other features of a shell so be creative! :)


Last edited by nom de plume on Thu Oct 26, 2006 4:35 am; edited 1 time in total
Back to top
View user's profile Send private message
nom de plume
Tux's lil' helper
Tux's lil' helper


Joined: 01 Jun 2006
Posts: 104

PostPosted: Thu Oct 26, 2006 4:34 am    Post subject: Reply with quote

Alright, here's mine for now, might add some stuff later. My prompt is so small because I changed <tab> to cycle options instead of listing them.

The script (not much changed here). Be sure to place the config file where you want it:
Code:
#!/bin/sh                                                                     
urxvt +sb -fn "9x15" \                                                         
  -title "Run Dialog" -g 60x1 \                                                 
  -fg white -bg gray10 -cr white \                                             
  -fn "xft:Bitstream Vera Sans Mono:pixelsize=10" \                             
  --keysym.0xFF0D: " &\n exit\n" \                                             
  --keysym.0xFF1B: " &\ ^C exit\n" \                                           
  -e bash --init-file ~/config/rundiag -s


My bash configuration for the script. I am loading my zsh aliases but they are bash compatible:
Code:
# Environment
PS1="[\e[1;36mrun\e[0m]: "                                                     
HISTCONTROL="ignoreboth"                                                       
HISTFILE=~/.rundiag_history                                               
HISTSIZE=100                                                                   

# Cycle when using tab-completion                                                                               
bind '"\t":menu-complete'

# Load aliases
. ~/config/zsh/aliases


Optionally, you can use devilspie for further tweaking. I took away decorations and centered the window. The "application_name" option must match the -title option used in the script:
Code:
(if                                                                             
 (matches (application_name) "Run Dialog")                                     
 (begin                                                                         
   (undecorate)                                                                 
   (center)                                                                     
   (skip_pager)))
Back to top
View user's profile Send private message
ingemar
Tux's lil' helper
Tux's lil' helper


Joined: 21 May 2005
Posts: 83
Location: Gothenburg, Sweden

PostPosted: Thu Oct 26, 2006 9:46 am    Post subject: Reply with quote

I like your ideas! Especially to open a command in a new terminal, and the web address stuff =)
Tab completion works okay if I use bash. Although I've been thinking about trying on zsh, and then it would probably get kind of wierd when it shows the alternatives on a newline. But it seems that you've solved that nicely.

My script lookes like this:
Code:
#!/bin/sh
urxvtc -g 50x1+450+500 -bl -b 6 \
  --keysym.0xFF0D: " &\n exit\n" \
  --keysym.0xFF1B: " &\ ^C exit\n" \
  -e bash --init-file ~/.bashrunbox


No window decoration, and the run dialog always pops up in the center of the screen =)

But (2) and (3) would mean that something must be added in front of the line that have been entered in the terminal when you press return, or the other key sequence used for this. (Say Ctrl-Return och Alt-Return?) I think this would be impossible while only tweaking rxvt* parameters, so this should either a whole new solution or some magic in ~/.bashrunbox
_________________
iBook G4 12" & AMD X2 4200+
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Thu Oct 26, 2006 11:58 am    Post subject: Reply with quote

ingemar wrote:
I like your ideas! Especially to open a command in a new terminal, and the web address stuff =)
Tab completion works okay if I use bash. Although I've been thinking about trying on zsh, and then it would probably get kind of wierd when it shows the alternatives on a newline. But it seems that you've solved that nicely.


Well, I suppose here it's all about tastes, I preffer seeing all the options, that way to use tab completion seems a bit hard to me when there are more than 4-5 results. I just became comfortable with bash, you push a couple of keys, tab, if needed, press any other key and tab again. To each his/her own, I suppose :)

Quote:

But (2) and (3) would mean that something must be added in front of the line that have been entered in the terminal when you press return, or the other key sequence used for this. (Say Ctrl-Return och Alt-Return?) I think this would be impossible while only tweaking rxvt* parameters, so this should either a whole new solution or some magic in ~/.bashrunbox


Im interested in the "launch in a new terminal" feature, and im am looking into it. Control-Enter sounds like a fair combo for this to me. I am surprised that I never thought of this before... I've got some ideas, but I want anticipate anything since I dont know if this is possible in a simple way or would require a bit more of work.

About the url thingie, do you know about the url clicking feature in urxvt? Just put this into .Xdefaults

Code:
URxvt*perl-ext-common:      default,mark-urls
URxvt*urlLauncher:      <your web browser here>


Then, your urls should be marked in the urxvt windows (underlined and coloured if applicable), and if you middle click them the browser of your choice runs the url. Im not a perl gurú, but I bet that for anyone with some skills in perl should not be too hard to edit /usr/lib/urxvt/perl/mark-urls to accomplish the same just pressing enter, this way we would not need any special code in our little snippet and the feature would be globally available in urxvt, which is nice. I will look into this too, but, as said, my perl skills are a bit lacky :P

EDIT, forget about the perl thingie, I made a total mistake there. That is not like searching the text for urls and marking them, but, actually, pressing enter after writing them, and launching them. I just messed my brain up :P


Last edited by i92guboj on Thu Oct 26, 2006 12:24 pm; edited 1 time in total
Back to top
View user's profile Send private message
nom de plume
Tux's lil' helper
Tux's lil' helper


Joined: 01 Jun 2006
Posts: 104

PostPosted: Thu Oct 26, 2006 12:22 pm    Post subject: Reply with quote

6thpink wrote:
ingemar wrote:
I like your ideas! Especially to open a command in a new terminal, and the web address stuff =)
Tab completion works okay if I use bash. Although I've been thinking about trying on zsh, and then it would probably get kind of wierd when it shows the alternatives on a newline. But it seems that you've solved that nicely.


Well, I suppose here it's all about tastes, I preffer seeing all the options, that way to use tab completion seems a bit hard to me when there are more than 4-5 results. I just became comfortable with bash, you push a couple of keys, tab, if needed, press any other key and tab again. To each his/her own, I suppose :)

My original goal was to do both: press tab once and it displays a list, each subsequent time you press tab it cycles through the list. I can do this in zsh, but like I said earlier, zsh does not have an --init-file option that I am aware of. I'll look to see if I can find some more info on tweaking bash completion.
Back to top
View user's profile Send private message
ThomasAdam
Guru
Guru


Joined: 20 Mar 2005
Posts: 448
Location: England

PostPosted: Thu Oct 26, 2006 6:45 pm    Post subject: Reply with quote

nom de plume wrote:
My original goal was to do both: press tab once and it displays a list, each subsequent time you press tab it cycles through the list. I can do this in zsh, but like I said earlier, zsh does not have an --init-file option that I am aware of. I'll look to see if I can find some more info on tweaking bash completion.


So pretty much like what 'gmrun' does, then.

-- Thomas Adam
Back to top
View user's profile Send private message
ingemar
Tux's lil' helper
Tux's lil' helper


Joined: 21 May 2005
Posts: 83
Location: Gothenburg, Sweden

PostPosted: Fri Oct 27, 2006 9:29 pm    Post subject: Reply with quote

Now I've got it working!
Pressing Ctrl-Return causes the application entered to start in a new terminal, and alt-enter tries to open it in firefox. My script currenty looks like this:

Code:
#!/bin/sh
urxvtc -g 50x1+350+400 -bl -b 6 \
  --keysym.C-0xFF0D: "\ ^A urxvtc -e \ ^E &\n exit\n" \
  --keysym.M-0xFF0D: "\ ^A /usr/bin/firefox \ ^E &\n exit\n" \
  --keysym.0xFF0D: " &\n exit\n" \
  --keysym.0xFF1B: " &\ ^C exit\n" \
  -e bash --init-file ~/.bashrunbox


The solution was actually quite simple, and the approach to solve it was similar to just pressing enter.
Pressing Ctrl-Return makes the pointer jump to the beginning of the line (\ ^A). Then "urxvtc -e " is written, and then, the pointer is jumped back to the end, where "&\n exit\n" is written. It's about the same for opening a web address...

To automatically parse the entered command and check if it is a web address is probably impossible with a solution as clean as this...
_________________
iBook G4 12" & AMD X2 4200+
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Fri Oct 27, 2006 11:52 pm    Post subject: Reply with quote

ingemar wrote:
Now I've got it working!
Pressing Ctrl-Return causes the application entered to start in a new terminal, and alt-enter tries to open it in firefox. My script currenty looks like this:

Code:
#!/bin/sh
urxvtc -g 50x1+350+400 -bl -b 6 \
  --keysym.C-0xFF0D: "\ ^A urxvtc -e \ ^E &\n exit\n" \
  --keysym.M-0xFF0D: "\ ^A /usr/bin/firefox \ ^E &\n exit\n" \
  --keysym.0xFF0D: " &\n exit\n" \
  --keysym.0xFF1B: " &\ ^C exit\n" \
  -e bash --init-file ~/.bashrunbox


The solution was actually quite simple, and the approach to solve it was similar to just pressing enter.
Pressing Ctrl-Return makes the pointer jump to the beginning of the line (\ ^A). Then "urxvtc -e " is written, and then, the pointer is jumped back to the end, where "&\n exit\n" is written. It's about the same for opening a web address...

To automatically parse the entered command and check if it is a web address is probably impossible with a solution as clean as this...


Nice you got it working.

About the autoexec for urls, you are right. I think the easier aproach would actually be to patch bash to do so, that way, urls would be recognised like some kind of internal command and then parsed and launched. The browser could be configured thru a var easily.

Regards ;)
Back to top
View user's profile Send private message
Dlareh
Advocate
Advocate


Joined: 06 Aug 2005
Posts: 2102

PostPosted: Sat Oct 28, 2006 12:52 am    Post subject: Reply with quote

Nice ideas. Here's my version that accepts URLs with just enter.

It passes any params to urxvt, so run it with '-bl' if you want a borderless run box.

CTRL+enter will still run the command in a new terminal, so adjust first TERMINAL= line to taste.

Note that the ^A and ^E trick will only work with bash's default emacs readline mode. It will not work if you e.g. have 'set editor-mode vi' in ~/.inputrc , which gets read AFTER --init-file (took me forever to figure out why a `shopt' after PS1= was insufficient)
_________________
"Mr Thomas Edison has been up on the two previous nights discovering 'a bug' in his phonograph." --Pall Mall Gazette (1889)
Are we THERE yet?


Last edited by Dlareh on Sun Oct 29, 2006 11:30 am; edited 3 times in total
Back to top
View user's profile Send private message
nom de plume
Tux's lil' helper
Tux's lil' helper


Joined: 01 Jun 2006
Posts: 104

PostPosted: Sat Oct 28, 2006 7:13 am    Post subject: Reply with quote

Dlareh wrote:
Nice ideas. Here's my version that accepts URLs with just enter...

Very good! Also got rid of devilspie and my extra config file.
Back to top
View user's profile Send private message
nom de plume
Tux's lil' helper
Tux's lil' helper


Joined: 01 Jun 2006
Posts: 104

PostPosted: Sun Oct 29, 2006 11:01 am    Post subject: Reply with quote

Dlareh wrote:
Nice ideas. Here's my version that accepts URLs with just enter <snip>

Any ideas on how to fix the history? It ends up looking like this:
Code:
 parsecmd  xterm  &
 exit
 parsecmd  rox  &
 exit

so it's kind of useless; it would be calling parsecmd too many times, also.
Back to top
View user's profile Send private message
Netfeed
n00b
n00b


Joined: 24 Jan 2004
Posts: 19

PostPosted: Sun Oct 29, 2006 11:31 am    Post subject: Reply with quote

nice nice, i took Dlareh:s code and than added "-bl -b 6" from ingemar:s code and removed the parse-function to get it as i want :)

works perfect(for me at least) thanks
_________________
tie me up, spank me hard and call me virgin mary
Back to top
View user's profile Send private message
Dlareh
Advocate
Advocate


Joined: 06 Aug 2005
Posts: 2102

PostPosted: Sun Oct 29, 2006 11:47 am    Post subject: Reply with quote

parsecmd won't show up in the history now
_________________
"Mr Thomas Edison has been up on the two previous nights discovering 'a bug' in his phonograph." --Pall Mall Gazette (1889)
Are we THERE yet?
Back to top
View user's profile Send private message
nom de plume
Tux's lil' helper
Tux's lil' helper


Joined: 01 Jun 2006
Posts: 104

PostPosted: Sun Oct 29, 2006 12:27 pm    Post subject: Reply with quote

Dlareh wrote:
parsecmd won't show up in the history now

Simple enough.

Code:
HISTCONTROL="ignoreboth"
is going to be ignored since you are manually inserting the commands into the history file.
Back to top
View user's profile Send private message
Dlareh
Advocate
Advocate


Joined: 06 Aug 2005
Posts: 2102

PostPosted: Sun Oct 29, 2006 10:49 pm    Post subject: Reply with quote

There's still CTRL+enter, which I guess ignoreboth causes it to not write anything because of the leading space.
_________________
"Mr Thomas Edison has been up on the two previous nights discovering 'a bug' in his phonograph." --Pall Mall Gazette (1889)
Are we THERE yet?
Back to top
View user's profile Send private message
liDEL
n00b
n00b


Joined: 23 Jul 2004
Posts: 9
Location: Poland, Lublin

PostPosted: Thu Nov 29, 2007 11:39 pm    Post subject: Reply with quote

nom de plume wrote:
Code:
                 
  --keysym.0xFF0D: " &\n exit\n" \                                             
  --keysym.0xFF1B: " &\ ^C exit\n" \   

those keysyms do not work anymore (rxvt-unicode-8.4). any ideas?
_________________
last chance to evacuate planet earth before it is recycled
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum