Sublime Forum

How to access cwd when starting via the command-line (subl .)

#1

When you start Sublime via the command-line, ala subl . it doesn’t set the python cwd to the current directory (the cwd is the sublime text installation), for example from in a plugin:

import os 

print('cwd=', os.getcwd())

This is perhaps intentional.

Is there any way for a plugin to know what the cwd is when the user opens Sublime via subl .?


Trying to resolve this issue: https://github.com/NeoVintageous/NeoVintageous/issues/421

0 Likes

#2

window.extract_variables()

Returns a dictionary of strings populated with contextual keys:

packages, platform, file, file_path, file_name, file_base_name, file_extension, folder, project, project_path, project_name, project_base_name, project_extension. This dict is suitable for passing to sublime.expand_variables().

1 Like

#3

The current directory used to be the one st was launched in in previous versions and thaz propagated to the python runtime. I’m not aware of this behavior having changed, but it seems there are a variety of oddities reqarding the python runtime In the last build.

Have you verified that you didn’t already have an st process running? should be irrelevant if your doing this at plugin module load

0 Likes

#4

No, there’s no instances open. Sublime always sets the installation directory as the cwd. I think this has always been the case.

Though, every-time you open Sublime via subl . it opens all previously opened windows, meaning ctrl-q (close sublime) then subl . then ctrl-q then subl . and so on… means the number of opened windows will increase exponentially. Very frustrating, There’s a bunch of related issues in the issue tracker.

@idleberg Looks like the “folder” value might be best one to use. Thanks.

1 Like