Setting the default path with Cygwin

I have a Cygwin installation, and I would like it to run Bash in a specific directory whenever I run. How can I achieve this?

+4
source share
4 answers

In your ~/.bashrc you can either change your $HOME to this directory, or you can [tried and it didn’t work] add cd to this directory at the end of the file.

+2
source

In ~/.bash_profile you can just write cd /cygdrive/c/path/to/where/you/want/cygwin/to/start . This file is located in the cygwin installation folder under <path_to_cygwin>\home\<user>\.bash_profile . (In my case: C:\cygwin64\home\User\.bash_profile ).

+1
source

python script

!! before use add .bashrs any line to the end !!

use name_script.py c: \ path

path_bachrc - path to .bashrc

cmd - path to cygwin.bat

 #***********************************************# # gangelXXX@gmail.com # #***********************************************# import argparse import subprocess import os path_bachrc = 'c:/PP/cygwin/home/adm/.bashrc' cmd = 'c:\PP\cygwin\Cygwin.bat' def delEndLineFromFile(filename): with open(filename, 'r') as f: aList = f.readlines() bList = aList[0:-1] with open(filename, 'w') as fd: fd.writelines(bList) parser = argparse.ArgumentParser() parser.add_argument("newPath", type=str, help="New path in .bachrc cygwin") args = parser.parse_args(); delEndLineFromFile(path_bachrc); p = args.newPath; pNew = 'cd /cygdrive/' + p[:1] + p[2:].replace('\\', '/') print(pNew) with open(path_bachrc, 'a') as f: f.write(pNew) PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell = True) 
0
source

Cygwin's Bash runs in your home folder, just like on Linux, which Cygwin simulates as close as possible. So you just need to change your home folder .

(Note: the Cygwin folder should not be the same as your Windows user home folder. By default they are different, but you can make them the same by putting something like /cygdrive/c/Users/myid in the Cygwin user account in /etc/passwd .)

0
source

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


All Articles