Standard Way to Open a Folder Window in Linux

Standard way to open a folder window in linux?

os.system('xdg-open "%s"' % foldername)

xdg-open can be used for files/urls also

How to open current working directory (OS X/Linux/Win)

You can use subprocess to open up a file explorer for a given path.

import subprocess
import sys

def open_folder(path):
if sys.platform == 'darwin':
subprocess.check_call(['open', '--', path])
elif sys.platform == 'linux2':
subprocess.check_call(['gnome-open', '--', path])
elif sys.platform == 'win32':
subprocess.check_call(['explorer', path])

open_folder(path=".") # open current directory

Opening directory in file explorer from WSL2

Answer is in post, but I will type it here again.
Put this function in your ~/.bashrc

start(){
path=$(wslpath -w "$1")
/mnt/c/Windows/explorer.exe "$path"
}

Now when you type start "Some Path" you will open it in file explorer. You can also remove /mnt/c/Windows/ from /mnt/c/Windows/explorer.exe if you want.

PTH (Path to here): Basically what my problem was that I was trying to read user input for the path to recreate the start command from cmd and powershell, but in wsl2 that was a lot harder because it doesn't have GUI so it doesn't know how to open it using xdg-open or other tools. Using read command from bash was not good enough because of the newline it always gives the user to type, but this uses arguments and takes the next thing you type in bash instantly which is awesome. Functions in bash work with arguments like lets say programs in c where you type ./program arg1 arg2 arg3..., where in bash it is the same, the number indicating the argument, so $0 is the zero-th argument which is always the name, so we don't use it. Starting from $1 $2 $3 and so on are the arguments which are usable in bash functions. In our case typing "start Desktop/", $1 is assigned "Desktop/", which is then converted to C:\Users<Your Username>\Desktop and assigned to $path. Then $path is passed to /mnt/c/Windows/explorer.exe to finally open in file explorer. Pretty nifty right? That's what I said first time 1 minute ago when I first saw and understood bash functions.

What's a common Linux command to show current dir in desktop?

xdg-utils comes from freedesktop.org. The freedesktop.org project is intended to improve interoperability between the various different desktop environments available on Linux. It's as close as you'll get to reliable method for doing this on Linux therefore.

How to change default directory in Windows Subsystem for Linux

You should only change the startingDirectory for WSL (Ubuntu in this case) terminal sessions.

  1. Open settings.json via CTRL+SHIFT+,
  2. Make sure you are modifying startingDirectory under profiles/list/name: "Ubuntu"

Example below (the slashes need to be escaped):

....
{
"guid": "{2c4de342-xxx-xxx-xxx-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "\\\\wsl$\\Ubuntu\\home\\windows_username_in_lower_case"
},
....

Documentation about startingDirectory including default values and expected values.

Inside settings.json you will also find an explanation of the json schema which is here

If you need to know how or where to edit Windows Terminal settings/preferences: https://learn.microsoft.com/en-us/windows/terminal/get-started

Start WSL Ubuntu in specific or current folder on Windows

I'm on Windows 10 Home with May Update and have Ubuntu 18.04 for WSL installed, I can open the console in any folder with Shift + Right Click and selecting the Open Linux shell here option

Sample Image



Related Topics



Leave a reply



Submit