Setting default path with Cygwin
Asked Answered
K

4

7

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?

Kitchens answered 15/12, 2011 at 18:6 Comment(0)
R
6

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

Rivas answered 15/12, 2011 at 18:10 Comment(2)
Where and what the hell is a ~/.bashrc? Edit: The whole file appears to be a gigantic comment.Kitchens
~ 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
L
3

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).

Liberality answered 18/11, 2015 at 20:5 Comment(0)
M
0

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)
Mudslinger answered 10/7, 2013 at 5:29 Comment(0)
H
0

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.)

Hovel answered 10/7, 2013 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.