Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: problems about zsh as file manager



2013/8/29 Peter Stephenson <p.stephenson@xxxxxxxxxxx>

> On Thu, 29 Aug 2013 09:48:19 +0800
> vinurs <haiyuan.vinurs@xxxxxxxxx> wrote:
>
> > Hi,
> > I want to use zsh as my file manager, then I found mailcap and I
> configured
> > my .mailcap files in my $HOME, here is an example:
> >
> > # pdf
> > application/pdf; evince %s ;
> >
> > Now, I can open pdf files in zsh,  but  I have the following questions:
>
> I presume you are using zsh-mime-setup to set this up?
>

Yes, I use zsh-mime-setup.

>
> > 1. when I use evince openning pdf files , it outputs many error messages,
> > but the pdf can also be opened correctly; Is there a method can make the
> > error message disappear,
> >     for example: using >/dev/null,
> >     I have tried this method ,but it can't work in .mailcap
>
> I use a shell script to start the handler and make .mailcap point at
> that.  Here's my simple equivalent for okular, okular_no_output.
>
>
> #!/bin/sh
>
> exec okular "$@" >/dev/null 2>&1
>
>
> > 2. when I opened a pdf file from zsh, then if I want close this zsh, it
> > shows that :
> >     zsh: you have running jobs.
> >     Is there a method can deattach it from zsh, in zsh I using ( ) to
> reach
> > this purpose, but It seems that this can't work in .mailcap file.
>
> It doesn't look like I made this configurable.  You can do the tricks
> you always can with job control, such as disowning the job by hand, but
> there's no way of automatically removing just MIME jobs from job
> control.
>
> It's easy to add this as an option.  With the following patch,
>
> zstyle ':mime:*' disown true
>
> will make MIME handlers put into the background not subject to job
> control.
>
> pws
>
>
> diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
> index 06e7ed0..1c388f1 100644
> --- a/Doc/Zsh/contrib.yo
> +++ b/Doc/Zsh/contrib.yo
> @@ -2861,6 +2861,14 @@ question is run using the tt(eval) builtin instead
> of by starting a new
>  tt(sh) process.  This is more efficient, but may not work in the
> occasional
>  cases where the mailcap handler uses strict POSIX syntax.
>  )
> +kindex(disown, MIME style)
> +item(tt(disown))(
> +If this boolean style is true, mailcap handlers started in the
> +background will be disowned, i.e. not subject to job control within
> +the parent shell.  Such handlers nearly always produce their own
> +windows, so the only likely harmful side effect of setting the style is
> +that it becomes harder to kill jobs from within the shell.
> +)
>  kindex(execute-as-is, MIME style)
>  item(tt(execute-as-is))(
>  This style gives a list of patterns to be matched against files
> diff --git a/Functions/MIME/zsh-mime-handler
> b/Functions/MIME/zsh-mime-handler
> index abaf0b6..7245c20 100644
> --- a/Functions/MIME/zsh-mime-handler
> +++ b/Functions/MIME/zsh-mime-handler
> @@ -74,7 +74,7 @@ if [[ $suffix != *.* ]]; then
>  fi
>  suffix=${suffix#*.}
>
> -local handler flags no_sh no_bg arg
> +local handler flags no_sh no_bg arg bg_flag="&"
>  integer i
>  local -a exec_asis hand_nonex
>
> @@ -89,6 +89,9 @@ zsh-mime-contexts -a $suffix execute-as-is exec_asis ||
> exec_asis=('*(*)' '*(/)'
>  zsh-mime-contexts -a $suffix handle-nonexistent hand_nonex ||
>    hand_nonex=('[[:alpha:]]#:/*')
>
> +# Set to true if the job should be disowned.
> +zsh-mime-contexts -t $suffix disown && bg_flag="&!"
> +
>  local pattern
>  local -a files
>
> @@ -309,8 +312,8 @@ else
>    # Otherwise it's equivalent to removing the eval and all the quotes,
>    # including the (q) flags.
>    if [[ -n $stdin ]]; then
> -    eval cat ${(q)argv} "|" ${(q)execargs} "&"
> +    eval cat ${(q)argv} "|" ${(q)execargs} $bg_flag
>    else
> -    eval ${(q)execargs} "&"
> +    eval ${(q)execargs} $bg_flag
>    fi
>  fi
>

According to the tips of yours, I wrote the function in .zshrc like this:
# open pdf
function vinurs-pdf ()
{
    (evince $* >/dev/null 2>&1 &)
}
then, in .mailcap:
# pdf
application/pdf; vinurs-pdf %s ;

Now, it works well. the function above solved the questions 1 and 2.
Thanks very much.


Messages sorted by: Reverse Date, Date, Thread, Author