4

I want to be able to type atom . in WSL and open Atom with the current directory.

I tried adding alias atom='/mnt/c/Users/Leo/AppData/Local/atom/atom.exe' to my .bashrc. It opens Atom, but just not in the current directory.

It works if I add alias atom='/mnt/c/Users/Leo/AppData/Local/atom/app-1.14.4/atom.exe', but I have to update it every time Atom updates.

Is there a better way?

3
  • If I use the WSL unix version of atom /usr/bin/atom: line 129: 1356 Aborted (core dumped ) nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$ATOM_HOME/nohup.out" 2>&1 Assertion 'pthread_mutex_unlock(&m->mutex) == 0' failed at pulsecore/mutex-posix.c:108, function pa_mu tex_unlock(). Aborting. – Jonathan Apr 6 '18 at 23:18
  • Also, if you run the windows version of atom within WSL, doesn't that violate WSL requirements? Writing to files on a unix filesystem from a windows app corrupts them, I hear – Jonathan Apr 6 '18 at 23:19
  • @Leo Jiang Both methods just open Atom with an empty folder view. – Răzvan Flavius Panda Aug 21 '19 at 12:27
1

I manadged to open (Windows version of) Atom from my WSL using Josh Brobst's suggestion and improving it a bit.

I was able to come up with 2 different aproaches.


  1. Make Atom open your current working directory

I did this by upgrading mentioned Josh Brobst's sugestion a little:

alias atom='/mnt/c/Windows/System32/cmd.exe /c "atom /PathToYourWSLRootFs/$PWD"'

this will make Atom to go through windows file system to your WLS directory, containing root file system

after that you put /$PWD which will expand into full path to your current directory (inside your WSL system) and append it to the path to directory containing your WLS file system

like that Atom will be given full path to your current working directory as argument and open it as folder


  1. Make Atom open specific file

To do this I wrote a simple bash script called atom you can create an alias in WSL that will run this script instead of going through windows binaries in your PATH.

#!/bin/bash

/mnt/c/Windows/System32/cmd.exe /c "atom ./rootfs$PWD/$1"

where "./rootfs" is path (in windows fs) to my ArchLinux root file system. Of course you need to put yours like this: "atom /pathToYourWslRootFs/$PWD/$1"

$PWD will once again append path to you current working directory (inside WSL)

$1 will then append argument you launched your script with

Usage: of this script is then following:

1) cd to directory containing desired file

2) run: atom desired_file_name

Note: to make step 2) work, you need to set up alias for your script, put it in a directory contained in your $PATH, or run it by giving full path to your script


These two aproaches are both working for me. I don't claim, the script couldn't be written better, its just that I don't need it better. However I think it should give everyone a basic idea of solving this problem and oportunity to make their scripts exactly to their liking.

I hope this was helpfull to someone.

1

I created a short script to handle the three atom commands I use most (I use Ubuntu with WSL):

  1. atom
  2. atom .
  3. atom RELATIVE_PATH_FILE

This script is not optimized, and I'm sure many people will find edge cases, but it gets the job done for me. To use it, simply placed it in ~/.local/bin/atom and make it executable by running chmod +x ~/.local/bin/atom. You may need to restart your shell for ~/.local/bin to be added to your path. In order to simplify things a bit, I mapped the WSL network drive for my ubuntu installation to U:, so you'll either want to do the same or modify the script accordingly on line 9.

#!/bin/bash

if [ -z $1 ]; then
  pushd /mnt/c > /dev/null
  /mnt/c/Windows/System32/cmd.exe /c "atom"
else
  [[ $1 = "." ]] && path=$(pwd) || path=$(realpath $1)

  winPath=$(echo "U:$path" | sed -e 's/\//\\/g')

  pushd /mnt/c > /dev/null
  /mnt/c/Windows/System32/cmd.exe /c "atom $winPath"
fi

popd > /dev/null

The script performs a few simple steps. First, if there is no command line argument, it simply calls atom using cmd.exe without arguments. If the command line argument is ., it gets the path to the current directory, otherwise, it gets the absolute path to the given file using realpath. The path is converted from POSIX to Windows format using sed before calling atom using cmd.exe as before, but with the path argument.

The pushd and popd commands are just there to get rid of the annoying warning message about UNC paths not being supported:

...
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory
0

Try this:

alias atom='/mnt/c/Windows/System32/cmd.exe /c "atom ."'

In order to make the atom cli available to cmd, cygwin, and msys, atom puts C:\Users\<name>\AppData\Local\atom\bin into your Windows local user's PATH environment variable. So, this alias should run atom.cmd from that location using your current bash directory. Of course if its not in the windows PATH for some reason just replace atom with the windows absolute path of atom.cmd.

I'm not 100% sure that . as seen by cmd will be the current directory from windows bash and unfortunately can't test it (not on insider build), but this line from the interop blog post makes me think it should work (provided in bash you're somewhere in /mnt/<drive letter>/):

Current working directory of launched NT processes will be inherited by NT processes if it is somewhere inside a DrvFs mount.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.