Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

open previous window from command line? #6464

Closed
mark-hahn opened this issue Apr 22, 2015 · 35 comments · Fixed by #6690
Closed

open previous window from command line? #6464

mark-hahn opened this issue Apr 22, 2015 · 35 comments · Fixed by #6690

Comments

@mark-hahn
Copy link
Contributor

Opening Atom without the command line (e.g. using the dock on OSX) now re-opens any previously opened windows

Would it be hard for me to do a PR to add a command-line option to open atom with the previous windows? I know my use-case is rare but I open X11 windows from the command-line and I have no desktop at all.

I know this isn't going to happen but logically using atom would open previous windows and atom . would open the working directory.

@50Wliu
Copy link
Contributor

50Wliu commented Apr 22, 2015

Had a quick discussion with @maxbrunsfeld with this a couple of days back but didn't really have time to go about doing it. This would be great 😄.

@mark-hahn
Copy link
Contributor Author

This would be great

I assume you mean adding a command-line option, not changing what it does
with no options.

If the code is in javascript I'll look into the PR. Is it?

On Tue, Apr 21, 2015 at 6:57 PM, Wliu notifications@github.com wrote:

Had a quick discussion with @maxbrunsfeld
https://github.com/maxbrunsfeld with this a couple of days back but
didn't really have time to go about doing it. This would be great [image:
😄].


Reply to this email directly or view it on GitHub
#6464 (comment).

@50Wliu
Copy link
Contributor

50Wliu commented Apr 22, 2015

The Atom script is a shell script: https://github.com/atom/atom/master/atom.sh.
And yes, a command-line option.

@mark-hahn
Copy link
Contributor Author

That link is a 404 and the only atom.sh I could find was
https://github.com/atom/atom/blob/aad393618ea68c4992c7627fda1f624c31d2d8aa/resources/win/atom.sh
which is windows only.

I only care about linux myself.

On Tue, Apr 21, 2015 at 7:08 PM, Wliu notifications@github.com wrote:

The Atom script is a shell script:
https://github.com/atom/atom/master/atom.sh.
And yes, a command-line option.


Reply to this email directly or view it on GitHub
#6464 (comment).

@50Wliu
Copy link
Contributor

50Wliu commented Apr 22, 2015

Ugh why did I try reformatting the URL...
https://github.com/atom/atom/blob/master/atom.sh

@mark-hahn
Copy link
Contributor Author

That looks like an easy PR, even for me. Does anyone have a preference on
the option letter? Unfortunately w is taken. Maybe r for restart?

On Tue, Apr 21, 2015 at 7:13 PM, Mark Hahn mark@hahnca.com wrote:

That link is a 404 and the only atom.sh I could find was
https://github.com/atom/atom/blob/aad393618ea68c4992c7627fda1f624c31d2d8aa/resources/win/atom.sh
which is windows only.

I only care about linux myself.

On Tue, Apr 21, 2015 at 7:08 PM, Wliu notifications@github.com wrote:

The Atom script is a shell script:
https://github.com/atom/atom/master/atom.sh.
And yes, a command-line option.


Reply to this email directly or view it on GitHub
#6464 (comment).

@mnquintana
Copy link
Contributor

-r is also taken for --resource-path, but I can't think of a better flag than --restore

@mark-hahn
Copy link
Contributor Author

I really want it to be quick and easy. Typing --restore is too hard for my lazy typing. How about -o or --old-windows?

@mehcode
Copy link
Contributor

mehcode commented Apr 22, 2015

I know this isn't going to happen but logically using atom would open previous windows and atom . would open the working directory.

But that makes so much sense. 💯


As for an explicit flag perhaps -R for a shortcut to --restore


On another note; to my (possibly warped mind) -l makes more sense as a shortcut to --resource-path (but that's another thing)

@mark-hahn
Copy link
Contributor Author

I still like -o for --old-windows. It is a good complement to -n for --new-window. Here it is in context...

Options:
  -1, --one             Run in 1.0 API preview mode.                                                         [boolean]
  -d, --dev             Run in development mode.                                                             [boolean]
  -f, --foreground      Keep the browser process in the foreground.                                          [boolean]
  -h, --help            Print this usage message.                                                            [boolean]
  -l, --log-file        Log all output to file.                                                              [string]
  -n, --new-window      Open a new window.                                                                   [boolean]
  -o, --old-windows     Open last-closed windows.                                                            [boolean]
  -r, --resource-path   Set the path to the Atom source directory and enable dev-mode.                       [string]
  -s, --spec-directory  Set the directory from which to run package specs (default: Atom's spec directory).  [string]
  --safe                Do not load packages from ~/.atom/packages or ~/.atom/dev/packages.                  [boolean]
  -t, --test            Run the specified specs and exit with error code on failures.                        [boolean]
  -v, --version         Print the version.                                                                   [boolean]
  -w, --wait            Wait for window to be closed before returning.                                       [boolean]

@brettle
Copy link
Contributor

brettle commented Apr 22, 2015

Based on my experience looking at #6466, I think you can achieve the behavior you desire by running /usr/share/atom/atom instead of /usr/bin/atom.

@mark-hahn
Copy link
Contributor Author

That would be great. Unfortunately /usr/share/atom/atom is giving me this error ...

$ /usr/share/atom/atom
[28516:0422/125255:ERROR:nss_util.cc(94)] Failed to create /home/mark/.pki/nssdb directory.
[28516:0422/125255:ERROR:browser_main_loop.cc(170)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
[28516:0422/125255:ERROR:browser_main_loop.cc(216)] Gtk: cannot open display: 

$ [28518:0422/125255:ERROR:nss_util.cc(94)] Failed to create /home/mark/.pki/nssdb directory.
[28518:0100/000000:ERROR:zygote_linux.cc(585)] write: Broken pipe

What is really weird is that something is causing the bash command line to show some of the error in a second prompt. I didn't know this was even possible.

Is it possible that script only works when there is a desktop?

@maxbrunsfeld
Copy link
Contributor

Is it possible that script only works when there is a desktop?

Yeah, that's possible. In any case, that binary is what the atom command uses, so if you use atom from the command-line, you should be able to use /usr/share/atom/atom.

@mark-hahn
Copy link
Contributor Author

if you use atom from the command-line, you should be able to use
/usr/share/atom/atom.

atom works great from the command line. /usr/share/atom/atom doesn't.

On Wed, Apr 22, 2015 at 1:22 PM, Max Brunsfeld notifications@github.com
wrote:

Is it possible that script only works when there is a desktop?

Yeah, that's possible. In any case, that binary is what the atom command
uses https://github.com/atom/atom/blob/master/atom.sh#L77, so if you
use atom from the command-line, you should be able to use
/usr/share/atom/atom.


Reply to this email directly or view it on GitHub
#6464 (comment).

@brettle
Copy link
Contributor

brettle commented Apr 22, 2015

Looks like your DISPLAY environment variable isn't set in your shell, but is set when running /usr/bin/atom. Do either of these work:

bash -c /usr/share/atom/atom

or:

DISPLAY=:0 /usr/share/atom/atom

@mark-hahn
Copy link
Contributor Author

Unfortunately they are giving the same error.

What do you make of the Failed to create /home/mark/.pki/nssdb directory.
error? That is apparently inside chromium.

I don't see how this could be the same script run by the Atom command.

On Wed, Apr 22, 2015 at 2:27 PM, Dean Brettle notifications@github.com
wrote:

Looks like your DISPLAY environment variable isn't set in your shell, but
is set when running /usr/bin/atom. Do either of these work:

bash -c /usr/share/atom/atom

or:

DISPLAY=:0 /usr/share/atom/atom


Reply to this email directly or view it on GitHub
#6464 (comment).

@mark-hahn
Copy link
Contributor Author

Ah, that is the gnome-keyring. I've had trouble with that before. Now I just need to remember how I fixed it then. There was some variable that overrode it.

@brettle
Copy link
Contributor

brettle commented Apr 22, 2015

I'm not sure what the nssdb error is but I got the same error when I tried running /usr/share/atom/atom without the DISPLAY env var set. With it set, both the gtk error and the nssdb error went away and the atom window opened. Please post the output from:

echo "DISPLAY=$DISPLAY"
DISPLAY=:0 /usr/share/atom/atom

You can also try this:

  1. Copy the atom script locally with cp /usr/bin/atom . and edit ./atom as follows:

  2. Change the line which says:

    USR_DIRECTORY=$(readlink -f $(dirname $SCRIPT)/..)
    

    to say:

    USR_DIRECTORY=/usr
    
  3. Change the line which says:

    nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$ATOM_HOME/nohup.out" 2>&1
    

    to say:

    nohup "$ATOM_PATH" --pid=$$ "$@" > "$ATOM_HOME/nohup.out" 2>&1
    
  4. Run your modified copy with ./atom.

@mark-hahn
Copy link
Contributor Author

First, the results of ...

echo "DISPLAY=$DISPLAY"
DISPLAY=:0 /usr/share/atom/atom
$  echo "DISPLAY=$DISPLAY"
DISPLAY=

$  DISPLAY=:0 /usr/share/atom/atom 
[18702:0422/223935:ERROR:nss_util.cc(94)] Failed to create /home/mark/.pki/nssdb directory.
[18702:0422/223935:ERROR:browser_main_loop.cc(170)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
[18702:0422/223935:ERROR:browser_main_loop.cc(216)] Gtk: cannot open display: :0

$  [18704:0422/223935:ERROR:nss_util.cc(94)] Failed to create /home/mark/.pki/nssdb directory.
[18704:0100/000000:ERROR:zygote_linux.cc(585)] write: Broken pipe

@mark-hahn
Copy link
Contributor Author

I made the two mods and ran the local copy. I got pretty much the same results ...

[20116:0422/224711:ERROR:nss_util.cc(94)] Failed to create /home/mark/.pki/nssdb directory.
[20116:0422/224711:ERROR:browser_main_loop.cc(170)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
[20116:0422/224711:ERROR:browser_main_loop.cc(216)] Gtk: cannot open display: 

Thanks for all the trouble. I would be happy to let you ssh into my machine, if you want.

@brettle
Copy link
Contributor

brettle commented Apr 23, 2015

I suspect you have a more general X-Windows configuration problem since it looks like you can't open display :0. The only thing I don't understand is why running "atom" works. Perhaps it is an alias or isn't actually /usr/bin/atom? What do you get for:

which atom

and what happens when you run:

/usr/bin/atom

? Can you confirm that you can run other X programs from shell where you are trying to launch atom?

@mark-hahn
Copy link
Contributor Author

$  which atom
/usr/bin/atom
$  atom
<Atom opens up in an X window>

When I enter atom the terminal emits about 100 lines of garbage but the window opens.

Can you confirm that you can run other X programs from shell where you are trying to launch atom?

Yes, I also have run xterm, SmartGit and the unity desktop. I have been using Atom and SmartGit in X windows for almost all of my development for weeks.

I suspect you have a more general X-Windows configuration problem since it looks like you can't open display :0.

As I mentioned, I suspect some keyring problem, at least with the first error message. In the past I had to add some env var to fix the keyring. Maybe one script can see the var and another cannot. Unfortunately I can't find the old forum posts for that fix. I'll keep looking.

@brettle
Copy link
Contributor

brettle commented Apr 23, 2015

What Linux distribution/release are you running?

Is SELinux enabled? If so, you could try turning it off temporarily to see if it's the cause. Use sudo setenforce 0 to turn it off, and then see whether /usr/share/atom/atom works. Don't forget to turn it back on with sudo setenforce 1. You might also want to check/fix the permissions on /home/mark/.pki as described here.

FWIW, I'm mystified as to how you are able to run any X programs without having the DISPLAY environment variable set.

@mark-hahn
Copy link
Contributor Author

What Linux distribution/release are you running?

I'm using ubuntu 12.04.5 inside a chroot using crouton on a chromebook pixel. You can run different chroots. I used to use unity desktop but I switched to a stripped chroot that only has xiwi.

Is SELinux enabled?

It is not installed.

check/fix the permissions on /home/mark/.pki as described here.

I changed the owner/group and that fixed my first error. Progress!

I'm left with ...

$  DISPLAY=:0 /usr/share/atom/atom
[9426:0423/080408:ERROR:browser_main_loop.cc(170)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
[9426:0423/080408:ERROR:browser_main_loop.cc(216)] Gtk: cannot open display: :0

$ [9428:0100/000000:ERROR:zygote_linux.cc(585)] write: Broken pipe

Edit: Fixed version ubuntu 12.04.5.

@mark-hahn
Copy link
Contributor Author

Damn, I am so sorry to have wasted your time.

I had forgotten that in the beginning I made an alias for atom that did xiwi atom. xiwi /usr/share/atom/atom loads up just fine. Without xiwi no X env was being loaded at all.

Now I'll try re-opening the multiple windows.

@mark-hahn
Copy link
Contributor Author

After 24 hrs of wasting everyone's time I can verify that /usr/share/atom/atom loads the old windows just fine. So there is no need for a command-line option. This issue is resolved.

Thank you @brettle. Without your persistence I would never have figured this out.

@mnquintana
Copy link
Contributor

After 24 hrs of wasting everyone's time I can verify that /usr/share/atom/atom loads the old windows just fine. So there is no need for a command-line option. This issue is resolved.

Maybe, but I think a command-line option would still prove very useful and would be a lot more useable than remembering to launch from /usr/share/atom/atom every time you want to restore your last session from the command line.

@mark-hahn
Copy link
Contributor Author

You may be right, but I personally have no problem since I'll be using an alias to a script that makes the atom command behave as I want. atom with no args will re-open windows. atom . will open the current directory.

@brettle
Copy link
Contributor

brettle commented Apr 23, 2015

Yay! Glad you figured it out.

@mnquintana, I agree that a command line option would be useful.

@mehcode
Copy link
Contributor

mehcode commented Apr 23, 2015

@mnquintana A command line option would be strange to me the more I think about it. atom should work like subl did (open previous windows). atom . can open up the current directory.

@mnquintana
Copy link
Contributor

@mehcode Ah, I forgot about that option – yeah, I like that one a lot better.

@maxbrunsfeld
Copy link
Contributor

I know this isn't going to happen but logically using atom would open previous windows and atom . would open the working directory.

@mark-hahn @mehcode I think this should happen.

/cc @atom/non-github-maintainers @atom/core

@mnquintana
Copy link
Contributor

@mark-hahn @mehcode I think this should happen.

Definitely 👍 from me

@mark-hahn
Copy link
Contributor Author

I think this should happen.

As I said, a simple script will do it. You already have to install atom and a bunch of packages. Adding the script is easy.

@lock
Copy link

lock bot commented Jan 22, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants