zsh-users
 help / color / mirror / code / Atom feed
* problems about zsh as file manager
@ 2013-08-29  1:48 vinurs
  2013-08-29  9:11 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: vinurs @ 2013-08-29  1:48 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 779 bytes --]

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:
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
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.

Thanks all.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: problems about zsh as file manager
  2013-08-29  1:48 problems about zsh as file manager vinurs
@ 2013-08-29  9:11 ` Peter Stephenson
  2013-08-29 13:25   ` vinurs
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2013-08-29  9:11 UTC (permalink / raw)
  To: zsh-users

On Thu, 29 Aug 2013 09:48:19 +0800
vinurs <haiyuan.vinurs@gmail.com> 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?

> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: problems about zsh as file manager
  2013-08-29  9:11 ` Peter Stephenson
@ 2013-08-29 13:25   ` vinurs
  0 siblings, 0 replies; 3+ messages in thread
From: vinurs @ 2013-08-29 13:25 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 4021 bytes --]

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

> On Thu, 29 Aug 2013 09:48:19 +0800
> vinurs <haiyuan.vinurs@gmail.com> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-29 13:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-29  1:48 problems about zsh as file manager vinurs
2013-08-29  9:11 ` Peter Stephenson
2013-08-29 13:25   ` vinurs

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).