I've got a Cygwin installation, and I'd like it to start Bash in a certain directory whenever I start up. How can I achieve this?
In your ~/.bashrc
, You can either change your [tried and it didn't work] add a $HOME
to that directory, or you cancd
to that directory at the end of the file.
~
is a shortcut for your home directory, which is where you log in. It's usually /home/username
where username
is your actual username. .bashrc
is a file that bash reads when you log in to set up the environment the way you want it. –
Rivas In your ~/.bash_profile
you may simply write cd /cygdrive/c/path/to/where/you/want/cygwin/to/start
. You will find this file in your cygwin installation folder, under <path_to_cygwin>\home\<user>\.bash_profile
. (In my case: C:\cygwin64\home\User\.bash_profile
).
python script
!!before use add .bashrs any string to the end!!
use name_script.py c:\path
path_bachrc - path to .bashrc
cmd - path to cygwin.bat
#***********************************************#
# [email protected] #
#***********************************************#
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)
Bash on Cygwin starts up in your home folder, just like on Linux, which Cygwin mimics as closely as it can. So, you simply need to change your home folder.
(Note that your Cygwin folder need not be the same as your Windows user home folder. By default, they are different, but you could make them the same by putting something like /cygdrive/c/Users/myid
into your Cygwin user entry in /etc/passwd
.)
© 2022 - 2024 — McMap. All rights reserved.
~/.bashrc
? Edit: The whole file appears to be a gigantic comment. – Kitchens