From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23946 invoked from network); 6 Oct 2006 14:52:53 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.6 (2006-10-03) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.6 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 Oct 2006 14:52:53 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 98638 invoked from network); 6 Oct 2006 14:52:46 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Oct 2006 14:52:46 -0000 Received: (qmail 2164 invoked by alias); 6 Oct 2006 14:52:37 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10792 Received: (qmail 2153 invoked from network); 6 Oct 2006 14:52:37 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 6 Oct 2006 14:52:37 -0000 Received: (qmail 97426 invoked from network); 6 Oct 2006 14:52:37 -0000 Received: from ka.cs.utk.edu (160.36.56.221) by a.mx.sunsite.dk with SMTP; 6 Oct 2006 14:52:32 -0000 Received: from localhost (localhost [127.0.0.1]) by ka.cs.utk.edu (Postfix) with ESMTP id A60962F241 for ; Fri, 6 Oct 2006 10:53:22 -0400 (EDT) X-Virus-Scanned: by amavisd-new with ClamAV and SpamAssasin at cs.utk.edu Received: from ka.cs.utk.edu ([127.0.0.1]) by localhost (ka.cs.utk.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cpmOyfrTI+2o for ; Fri, 6 Oct 2006 10:53:15 -0400 (EDT) Received: from namib.cs.utk.edu (namib.cs.utk.edu [160.36.59.92]) by ka.cs.utk.edu (Postfix) with ESMTP id 4B3212F245 for ; Fri, 6 Oct 2006 10:53:15 -0400 (EDT) Received: by namib.cs.utk.edu (Postfix, from userid 10605) id 0C06536F14; Fri, 6 Oct 2006 10:52:22 -0400 (EDT) Date: Fri, 6 Oct 2006 10:52:22 -0400 From: Chris Johnson To: zsh-users@sunsite.dk Subject: ZLE widget to run gdb on command line Message-ID: <20061006145222.GA32307@namib.cs.utk.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i Hi. I just thought I'd share a widget that I find helpful. Invoking gdb is something I need to do a lot lately, it seems, and I often think I can pass the program's arguments as arguments to gdb: gdb myprog arg1 arg2 arg3 But gdb doesn't accept this because it expects other unnamed arguments. Treating the whole command as a single argument to gdb also fails: gdb "myprog arg1 arg2 arg3" The single argument is treated as a single executable name. The only way I know of to pass arguments to the executable is with gdb's run command at the interpreter. So, the following widget effectively transforms the line myprog arg1 arg2 arg3 into gdb myprog gdb-prompt> run arg1 arg2 arg3 . Any comments or alternative solutions are quite welcome. I don't know zle or history expansion very well. -------------------------- run-in-gdb() { # This function is ZLE widget that runs the current command in gdb. # Since gdb doesn't take the program's arguments as arguments to gdb # itself but rather through the interpreter, a "run" command is # printed # out to a temporary file which is invoked as script for gdb to grab # commands from at startup. # Commit current command line to history, inset its words in a gdb # command, expand history to bypass HIST_VERIFY, and run it. print -s ${(z)BUFFER} BUFFER="gdb !!0 -x =(echo run !!1*)" zle expand-history zle accept-line } zle -N run-in-gdb bindkey "^X^G" run-in-gdb -------------------------- -- Chris Johnson cjohnson@cs.utk.edu http://www.cs.utk.edu/~cjohnson