You are not logged in.

#1 2013-03-23 22:29:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Interrobang: a tiny menu packing a big bang (syntax)

I've just put together a working version of my latest project: Interrobang.  It is a very lightweight (~350 lines of C) launcher menu.

It works a little like dmenu_run.  It does not, however, read lists from the stdin, and it cannot be scripted the same way dmenu can[1].  It is a launcher, and only a launcher.  But it does have two powerful features (and a very small size) that set it apart.

  1. Tab Completion

    • Interrobang leverages the power of bash shell completion (requires bash, sorry zsh'ers) instead of using an odd cache/list system like dmenu.  This tool does not display options like dmenu, rather you can type whatever letters you want, then hit tab for shell-style tab completion.  If there is more than one possible completion for what you've put you can hit tab repeatedly to cycle through the options.

    • Tab completion will also work for filenames passed to commands!  For example, if you type "mup<TAB>" mupdf will come up as an option (assumming it's installed), then you hit space and type "~/docs/co<TAB>" and "~/docs/coolButLongNamed.pdf" could come up (assuming you have such an odd file).

    • Tab completion is completely customizable, as all the processing is offloaded to other tools (bash's compgen by default).  You can write your own completion scripts, or get creative to make interrobang do other things.

  2. Interobang has "bang" syntax inspired by duckduckgo.  You can define your own bangs in ~/.interobangrc.  Four default bangs are included in the rc file on github:

    • !term <command>
          Launch <command> in your favorite terminal emulator.  For example !term htop, or !term vim.

    • !pdf <pdfname>
          Open a pdf in your favorit pdf-viewer (mine is mupdf)

    • !web <url or html file>
          Do you see the pattern ...

    • !man <man page / app name>
          Opens the man page in a terminal

    • Also a bang "!" with no recognized keyword after it will default to the first bang, which in the default set is a terminal - so you could do "!htop" or "!vim".

EDIT: note [1]: As noted here aparently interrobang has a very accidental and 'organically' developed ability to have it's own powerful script interaction.

Last edited by Trilby (2013-05-14 13:26:36)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#2 2013-03-24 07:28:43

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

Re: Interrobang: a tiny menu packing a big bang (syntax)

That's a nice project you are working on. I already did some experiments with it and I changed "!" to ":" because it's easier for me to type. I usually don't want to focus browser just to type url so I did this. : o url..

{ "o",					"dwb" },

For some reason interobang spawns in the left monitor and goes all the way through my main monitor but it doesn't really matter that much right now smile

Last edited by Shinryuu (2013-03-24 07:45:41)

Offline

#3 2013-03-24 11:25:58

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Hmm, I could have it detect multimonitors and stay to just one.  Currently it just accepts whatever X11 reports as the screen width.   The placement, however, is at (0,0) which should be your main moniotr.  It sounds like your left monitor must be your main and the other is to the right of it.

Good idea for changing the ! to :, I should be able to make this an option too. (edit: done)

Last edited by Trilby (2013-03-24 12:56:50)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2013-03-24 13:56:07

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

Re: Interrobang: a tiny menu packing a big bang (syntax)

My main monitor is set as primary in the settings. I wonder if nvidia's twinview have anything to do with things thing? Well time to bang things further!

Offline

#5 2013-03-24 16:09:14

ngzhian
Member
Registered: 2012-12-09
Posts: 10

Re: Interrobang: a tiny menu packing a big bang (syntax)

Hi there! I noticed line 30:

rc = fopen(".interobangrc", "r")

this reads from the file ~/.interobangrc, but by default such a file does not exist, and is not created on make.
Is this the behavior intended?
Thanks!

Offline

#6 2013-03-24 16:27:16

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,095
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Oooooh, interesting. I can probably see this replacing dmenu for me on TTWM (I don't really do any of the fancy stuff that dmenu offers).

Tell me, would it be possible for you to allow ^u to clear the line? Also, I'm extremely tempted to port this to zsh…

All the best,

-HG

Offline

#7 2013-03-24 17:04:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

I'd be happy to help with a zsh version - I just don't know zsh ... does it have a command like bash's compgen?

At the very least, I'd like to figure out if I can link against bash so this will run if bash is installed by not the default shell.  As is, completion will not work at all on a system where bash is not /bin/sh.  (edit) Wait, I know how to do this much.  I just need to call "/bin/bash -c compgen ...'.  This will allow this to work on systems with zsh (or any other shell) as the default shell - but bash will still be a depenency.  I can see a potential new option for different command completion systems - as long as they can work like compgen: when given a fragment they generate a list of possible options.

I just added ^u.  This openned the possibility for other control keys - let me know what would be useful.

Last edited by Trilby (2013-03-24 17:11:07)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2013-03-24 17:23:01

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,095
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Trilby wrote:

I'd be happy to help with a zsh version - I just don't know zsh ... does it have a command like bash's compgen?

Well, I'm not quite sure how you need to use it (I have yet to look at the source code, but the zshcomp{sys,wid} commands are likely what you'd be using.

Trilby wrote:

I just added ^u.  This openned the possibility for other control keys - let me know what would be useful.

You're my hero! I'll let you know if I think of other helpful ^ sequences.

All the best,

-HG

Last edited by HalosGhost (2013-03-24 17:24:32)

Offline

#9 2013-03-24 21:36:52

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,095
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Hey Trilby, I have another couple of feature requests for you. The only thing stopping me from switching from dmenu would be something like dmenu's "-b" flag so that interobang appears at the bottom of the screen rather than the top.

The second one, which would likely have more utility for more people would be shift-tab to step backward in the tab-completion list.

All the best,

-HG

Last edited by HalosGhost (2013-03-24 22:21:44)

Offline

#10 2013-03-24 22:36:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Did that, and one better: there is now a "geometry" keyword in the rc file.  This can be set to "geometry top" which is the default anyway, or "geometry bottom", or even to "geometry WxH+X+Y" using an xterm-style geometry string to place the menu anywhere on the screen.

I've also added an optional border and border color.  I think it looks best with a border when floating in the middle of the screen, but best without when on the top or bottom - but you may configure to your hearts content.

I did notice I introduced a bug in tab completion along the way.  Program names still seem to be completed, but filename parameters are not. (edit: fixed)

As a preview, I think the bangs will be expanded to not just be prefix commands, but to be full format strings.  In otherwords, as is the default bang will open luakit to google when you type "!web google.com", but you would not be able to have a bang to do "!archbbs interobang" to get to this thread.  I plan to implement bangs like the following (not done yet) which will allow this behavior:

!archbbs      luakit https://www.google.com/search?&q=%s+site%%3Abbs.archlinux.org

This can then be used as the format string to insert the search keyword following the bang into the url.

Last edited by Trilby (2013-03-24 23:04:01)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#11 2013-03-24 23:35:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

I just finished implementing the format strings for bangs.  Now, have fun creating and sharing useful bangs.  I also just noticed I've been spelling interrobang wrong ... oops.  See the updated github name and PKGBUILD.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#12 2013-03-25 10:14:11

nifty
Member
Registered: 2013-03-25
Posts: 4

Re: Interrobang: a tiny menu packing a big bang (syntax)

I've tried to run this on debian unstable. Works fine. But when I try to put a command into ~/.interobangrc, e. g.

!web     firefox

I get an

sh: 1: Syntax error: "(" unexpected

Sorry for bad english. smile

Edit: Is this maybe a problem because on debian /bin/sh is a symlink to /bin/dash and on arch to . . . /bin/bash (?!)?

Last edited by nifty (2013-03-25 10:58:33)

Offline

#13 2013-03-25 11:01:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

First, make sure you have the most recent git code - I was working on this over night and made a handfuly of changes and fixes.

Second, the entry should be in ~/.interrobangrc (two r's now that I started spelling it right), and the entry in ~/interrobangrc should be

!web    firefox %s

This has the %s placeholder for whatever you put after "web" when you run the program.

This does remind me, though, that a bang without a string (eg url in this case) may fail.  I'll fix that. edit: no, I guess it doesn't fail, it just produces odd results - which is fine as it is an odd thing to do.  If I run interrobang and enter "!web" and hit enter, I get my web browser trying to open "web" as a url.

Edit: also, interrobang should work fine with sh linked to dash - it just may not do proper tab completion - but even this will be fixed soon as long as /bin/bash is available/installed.

Last edited by Trilby (2013-03-25 11:07:46)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#14 2013-03-25 11:26:35

nifty
Member
Registered: 2013-03-25
Posts: 4

Re: Interrobang: a tiny menu packing a big bang (syntax)

Now tried it with latest git and it works. Thanks! smile

Offline

#15 2013-03-25 16:27:52

irtigor
Member
Registered: 2011-01-21
Posts: 44

Re: Interrobang: a tiny menu packing a big bang (syntax)

Zsh has a function called bashcompinit that provides 'complete' and 'compgen', so it should be possible to use it with bash completion files, but I never tried.

Offline

#16 2013-03-25 17:32:04

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,095
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

I would still advocate for the implementation of compatibility for zsh completion, as it is far more powerful than bash-completion, in my experience.

However, Trilby, have you given thought to adding a shift+tab for back-step?

Also, any thoughts on why this bang doesn't work?

:archbbs       dwb https://bbs.archlinux.org/search.php?action=search&show_as=topics&keywords=%s

I managed to get a direct ArchWiki search using:

:archwiki       dwb https://wiki.archlinux.org/index.php?search=%s

But, I seem to be unable to get that BBS search function to work properly.

I forgot that quotes is a pretty cool guy and doesn't afraid of anything. The corrected bang is as follows:

:archbbs       dwb "https://bbs.archlinux.org/search.php?action=search&show_as=topics&sort_dir=DESC&keywords=%s"

All the best,

-HG

Last edited by HalosGhost (2013-03-25 17:39:00)

Offline

#17 2013-03-25 17:56:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Zsh ("native" zsh) completion should be easy to implement, if someone can provide the equivalent command and invocation form to compgen.  It would be a command that would accept a single 'word' and produce a list of candidates for completion.  To be easily integrated, though, it would also need a 'prefix' flag like compgen's -P.

In fact, I'm going to make this simlpy an external tool that is specified like the bangs are with a format string.  The format string will accept two strings: the search word, and the prefix string.  Any (yes *any*) command/executable/script that can take these two inputs and generate suitable output could then be used.  You can write your own completion scripts if you want.  Once this is done, there will be a new line in the rc file which will specify the default bash-completion - below is how this will look:

completion        compgen -P "%s" -cf %s

EDIT: well, that was ridiculously easy.  Interrobang now can use *any* completion system that can be invoked with a prefix and a search term and produce a (newline separated) list of candidates.  I leave it up to the zsh'ers to come up with the right invocation for their shell.

Later today I'll move the bash dependencies in the PKGBUILD to optdeps.

Last edited by Trilby (2013-03-25 18:08:49)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#18 2013-03-25 18:13:04

ngzhian
Member
Registered: 2012-12-09
Posts: 10

Re: Interrobang: a tiny menu packing a big bang (syntax)

HalosGhost wrote:

However, Trilby, have you given thought to adding a shift+tab for back-step?

I went ahead to hack on that, here's a patch smile

http://sprunge.us/HWCP

diff --git a/interrobang.c b/interrobang.c
index b8ef5d3..b1fd731 100644
--- a/interrobang.c
+++ b/interrobang.c
@@ -153,6 +153,14 @@ static int main_loop() {
 		if (mod & ControlMask) {
 			if (key == 'u') line[0] = '\0';
 		}
+                else if (mod & ShiftMask && key == XK_Tab) {
+                        if (complist) {
+                            compcheck = True;
+                                if ( (--compcur) < 0 ) compcur = compcount - 1;
+                                strcpy(line,complist[compcur]);
+                                strcat(line," ");
+                        }
+                }
 		else if (key == XK_Return) breakcode = 1;
 		else if (key == XK_Escape) breakcode = -1;
 		else if (key == XK_BackSpace) line[strlen(line) - 1] = '\0';
@@ -200,7 +208,7 @@ static int main_loop() {
 			strncat(line,buf,len);
 			compcheck = False;
 		}
-		if (key != XK_Tab) compcheck = False;
+		if (key != XK_Tab && !(mod & ShiftMask)) compcheck = False;
 		/* draw */
 		XFillRectangle(dpy,buf,bgc,0,0,w,h);
 		XDrawString(dpy,buf,gc,5,fh,line,strlen(line));

Offline

#19 2013-03-25 19:20:06

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,095
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Trilby wrote:

Interrobang now can use *any* completion system that can be invoked with a prefix and a search term and produce a (newline separated) list of candidates.  I leave it up to the zsh'ers to come up with the right invocation for their shell.

ngzhain wrote:

I went ahead to hack on that, here's a patch smile

You two are my favorite people in the world right now!

All the best,

-HG

Offline

#20 2013-03-25 21:27:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

I just added a shift-tab option on github.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#21 2013-03-26 05:58:55

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

Re: Interrobang: a tiny menu packing a big bang (syntax)

Hey, I just updated and for some odd reason I can't change the font at all. No matter what font I use I get this. Everything else seems to work just fine cool

[ ~]$ interrobang
unrecognized configuration entry "font		-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-*
"

Offline

#22 2013-03-26 11:08:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Hmm, it works here - and that error suggests that the line from your interrobangrc is not being parsed at all, but rather just being taken as a full line.  Have you tried without an ~/.interrobangrc?

Can you post your ~/.interrobangrc?

FYI: the rc file parsing function isn't very "smart" any oddities in formatting can break it.  However, I've been walking through it, and I have no idea how the string provided in the error message could have been saved into the font variable.

EDIT: OOPS.  That's not an error message from the font loader - that's an error message from the rc parser.  It simply does not recognize that line ... and I bet I know why.  Are the first five characters 'f', 'o', 'n', 't', <TAB>?  If so, this would currently be expected.  I'll fix this, but right now it would only work with 'f' 'o' 'n' 't' ' ' (space).  You can fill with tabs or spaces after that, but the first character after the 't' must be a space.  Again, I'll fix this as it is rather silly.

I put a tab immediately after the word font, then was able to replicate the error.  I patched and pushed the code, and it now works for me.  Let me know if the last git push solved this.

Last edited by Trilby (2013-03-26 11:27:05)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#23 2013-03-27 08:15:18

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

Re: Interrobang: a tiny menu packing a big bang (syntax)

That problem indeed was with the tab line(s).. well I tend to use tabs all the way. I just edited it to use spaces and it's working again.

EDIT1. Oh you already patched it. Your latest git push is working just fine with tabbed lines as well. Thanks big_smile

Offline

#24 2013-03-27 09:24:54

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,095
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Hey Trilby, this has now completely replaced dmenu for me. Have you any plans to post interrobang-git up to the AUR?

All the best,

-HG

Offline

#25 2013-03-27 11:07:53

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Interrobang: a tiny menu packing a big bang (syntax)

Done. Aur package.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB