Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix open_command inside tmux #4520

Closed
wants to merge 1 commit into from

Conversation

eiel
Copy link

@eiel eiel commented Oct 19, 2015

I want to use open_command inside tmux.

$ tmux
$ nohup open .
appending output to nohup.out
$ cat nohup.out
nohup: can't detach from console: No such file or directory

So, I modified open_command what not use nohup command inside tmux.

see also: http://stackoverflow.com/questions/23898623/nohup-cant-detach-from-console#comment36797854_23898623

@ada-u
Copy link

ada-u commented Oct 19, 2015

👍

@mcornella
Copy link
Member

I can't reproduce this. The output of nohup is silenced in the current version of the open_command function. Let me see some diagnostic info, please post the output of:

which -a open
which -a open_command
nohup --version

@eiel
Copy link
Author

eiel commented Oct 20, 2015

$ which -a open
/usr/bin/open
$ which -a open_command
open_command () {
    local open_cmd
    local nohup
    case "$OSTYPE" in
        (darwin*) open_cmd="open"  ;;
        (cygwin*) open_cmd="cygstart"  ;;
        (linux*) open_cmd="xdg-open"  ;;
        (*) echo "Platform $OSTYPE not supported"
            return 1 ;;
    esac

    nohup $open_cmd "$@" &> /dev/null
}
$ nohup --version
nohup: illegal option -- -
usage: nohup [--] utility [arguments]

I did not know how to determine the version of nohup command

Sorry, I was wrong to write an example.
I fixed example

$ tmux
- $ open .
+ $ nohup open .
appending output to nohup.out
$ cat nohup.out
nohup: can't detach from console: No such file or directory

@mcornella
Copy link
Member

Oh, then you're not really using open_command. You should do open_command . which is the platform-agnostic function, or just open . since you're on OSX. The nohup in your case is not necessary.

@@ -28,7 +29,14 @@ function open_command() {
;;
esac

nohup $open_cmd "$@" &>/dev/null
# Use nohup command
if [ ${TMUX:-NOT_USE_TMUX} = "NOT_USE_TMUX" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eiel I think better is:

  if [ ${TMUX:-NOT_USE_TMUX} = "NOT_USE_TMUX" ]; then
    nohup $open_cmd "$@"
  else
    $open_cmd "$@"
  fi &> /dev/null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcornella @apjanke What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is simply not needed. See #4520 (comment). The current version works correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. Thanks for the quicky reply 👍

@eiel
Copy link
Author

eiel commented Oct 20, 2015

This problem is that open_command is not working inside tmux .
open_command the web-search, jira, such as in and have been utilized and node plugin, these plugin uses open_command.
open_command and to open a URL in a web browser is being used.
However , it does not open a web browser and are inside tmux.
I am in the environment remains this open_command does not work , and would like to to move This is the purpose of this Pull Request.

@apjanke
Copy link
Contributor

apjanke commented Oct 20, 2015

I can reproduce, with OS X 10.9.5, zsh 5.0.2, tmux 2.1.

The problem isn't that @eiel is adding an unnecessary nohup: he's just demonstrating the breakage. The problem is that inside tmux, nohup fails, and the open doesn't happen. So the unconditional nohup that open_command is doing means it doesn't work properly when called inside a tmux session.

For example, here's a fresh tmux session I fired up locally inside iTerm2. The open works, opening the text file in BBEdit, my default text editor. The open_command call has no effect.

$ open omz_diagdump_20151008-223116.txt
[~]
$ open_command omz_diagdump_20151008-223116.txt
[✘ ~]
$

I don't know exactly what the semantics of open_command should be, so I'm not sure what the exact change should be, but it does seem that something like this PR is needed.

@mcornella
Copy link
Member

Ok, thanks for chiming in. I see now what he meant.

Weirdly, when I tested this on my setup it worked correctly. I'll see if we need this or there is some other alternative that works everywhere though; I think I added the nohup part to be sure, but maybe it could be replaced by starting the process with &| or &!:

If a job is started with ‘&|’ or ‘&!’, then that job is immediately disowned. After startup, it does not have a place in the job table, and is not subject to the job control features described here.

Try this one-liner instead:

$open_cmd "$@" &>/dev/null &|

@mcornella
Copy link
Member

I've submitted that change in the form of a commit at mcornella@454e89c.

@eiel
Copy link
Author

eiel commented Oct 21, 2015

$open_cmd "$@" &>/dev/null &|

Awesome! 🙇 👍
It was confirmed that it is working well. 😄

@mcornella
Copy link
Member

Ok, I've submitted #4534 to test separately. +1 there if it works for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants