Set the default directory in the BASH window

The problem I am facing is that every time I open bash, it displays me in an undesirable directory, so I need to enter the cd / mnt / c commands to access my PC files, such as downloads, documents and etc. How to set default directory when opening bash?

+6
source share
3 answers

bash.exe The Windows executable that runs Bash on Windows implicitly makes the current directory its startup directory.

This means that you can simply change the shortcut file that opens Bash and change its field Start in:to open Bash in the directory of your choice (specify the usual path to Windows; it automatically goes to the /mnt/c-prefixed path when Bash starts).

  • Caution: the official Bash on Ubuntu on Windowsshortcut (in the "Start" menu) transfers ~as a launch directory as part of the field Target:; just remove  ~from the value C:\Windows\System32\bash.exe ~in Target:and then fill in the field Start in:.

Of course, you can create new shortcuts, each with its own launch directory, if necessary.


Adding a command Bash Console Hereto the context menu of folders in File Explorer

*.reg ( ) , .

Bash Console Here , .
Bash.

: aux. cmd.exe bash.exe, cmd.exe cmd.exe .

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\BashConsoleHere]
@="Bash Console Here"
"Icon"=hex(2):25,00,4c,00,4f,00,43,00,41,00,4c,00,41,00,50,00,50,00,44,00,41,\
  00,54,00,41,00,25,00,5c,00,6c,00,78,00,73,00,73,00,5c,00,62,00,61,00,73,00,\
  68,00,2e,00,69,00,63,00,6f,00,00,00

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\BashConsoleHere\command]
@="cmd /c cd \"%V\" && bash.exe"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\BashConsoleHere]
@="Bash Console Here"
"Icon"=hex(2):25,00,4c,00,4f,00,43,00,41,00,4c,00,41,00,50,00,50,00,44,00,41,\
  00,54,00,41,00,25,00,5c,00,6c,00,78,00,73,00,73,00,5c,00,62,00,61,00,73,00,\
  68,00,2e,00,69,00,63,00,6f,00,00,00

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\BashConsoleHere\command]
@="cmd /c cd \"%1\" && bash.exe"

PowerShell :

$null = 0..1 | % {
  $key = New-Item -Force ('HKCU:\Software\Classes\Directory{0}\shell\BashConsoleHere' -f ('', '\Background')[$_])
  $key | New-ItemProperty -Name '(Default)' -Value 'Bash Console Here' -Type String
  $key | New-ItemProperty -Name 'Icon' -Value '%LOCALAPPDATA%\lxss\bash.ico' -Type ExpandString
  $key = New-Item -Force "$($key.PsPath)\command"
  $key | New-ItemProperty -Name '(Default)' -Value "cmd /c cd `"$(('%1', '%V')[$_])`" && bash.exe" -Type String
}

:

0..1 | % {
  Remove-Item -Recurse -LiteralPath ('HKCU:\Software\Classes\Directory{0}\shell\BashConsoleHere' -f ('', '\Background')[$_])
}
+4
+3

- , , , - $HOME /mnt/c.

,

  • /mnt/c .
  • bash // /mnt/c
  • /mnt/c , - $HOME .ssh/, .
  • / $HOME /mnt/c.

You can do this using

usermod --home /mnt/c

or by changing the home directory to /etc/passwd

Caution: this may result in you being unable to log in or leave your account vulnerable.

+1
source

Source: https://habr.com/ru/post/1015307/