From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20674 invoked by alias); 2 Sep 2013 17:45:47 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17966 Received: (qmail 22329 invoked from network); 2 Sep 2013 17:45:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130902104536.ZM26206@torch.brasslantern.com> Date: Mon, 02 Sep 2013 10:45:36 -0700 In-reply-to: <20130902144601.4930cb81@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: mailcap configuration in zsh can't open .bk files" (Sep 2, 2:46pm) References: <130830101018.ZM26161@torch.brasslantern.com> <201309011711.r81HBEEF002418@pws-pc.ntlworld.com> <20130902144601.4930cb81@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: mailcap configuration in zsh can't open .bk files MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Sep 2, 2:46pm, Peter Stephenson wrote: } } On Mon, 02 Sep 2013 09:28:26 +0800 } vinurs wrote: } > It's not intelligent deciding filetype by suffix only, I'd like to write } > functions to open flles using 'file --mime-type' } } You're on your own here -- the zsh system isn't going to do this --- and } it looks like you've got problems. The shell allows you to define a } command to handle other commands that aren't found, but it doesn't allow } you define a command to handle other errors, in particular "permission } denied", which is what you'd get if you tried to "execute" a } non-executable file that wasn't aliased by one means or another. If "." is not in $path and the filename is relative to $PWD, then the error will in fact be command not found, so there might be some room to address this in the not-found handler. } Your best bet might be to do it in ZLE as a zle-line-finish hook. Note that this doesn't work for complex commands, e.g., loops or "if" constructs, unless you always use newline as the separator so that a ZLE line ends after every simple command within the complex one. In some places the shell syntax makes this impossible, and history recall won't work because the whole complex command is recalled as a single multi-line buffer. You might be better off creating a function or alias with a short name and get in the habit of typing that yourself ahead of any file name you want MIME-interpreted. If the zle-line-finish hook is sufficient, then: } # HERE: cleverness for backgrounding, etc, also similar to } # zsh-mime-handler. } if [[ -n $handler ]]; then } BUFFER="$handler $BUFFER" } fi Another possibility, to avoid inserting $handler into the buffer and thus into the shell history, would be something like alias $fname="unalias $fname && $handler $fname" This would invoke the current $handler every time upon history recall, even if the defined handler changes between calls.