Puppy
Puppy

Reputation: 146920

Setting default path with Cygwin

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?

Upvotes: 7

Views: 16448

Answers (4)

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

Upvotes: 3

Warren Young
Warren Young

Reputation: 42343

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

Upvotes: 0

user236976
user236976

Reputation: 1

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)

Upvotes: 0

Kevin
Kevin

Reputation: 56059

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.

Upvotes: 6

Related Questions