2011-12-15 7 views
4

私はCygwinのインストールを手に入れました。起動するたびにBashを特定のディレクトリで起動したいと思います。どうすればこれを達成できますか?ファイルの末尾に、そのディレクトリにcdを追加するには、~/.bashrcCygwinでデフォルトパスを設定する

答えて

2

は、あなたは どちらかあなたの $HOMEそのディレクトリに変更したり、 [しようと、それはうまくいきませんでした]ことができます。

+0

どこに '〜/ .bashrc'がありますか?編集:ファイル全体が巨大なコメントであるようです。 – Puppy

+0

'cd 'を追加すると動作するように見えました。 – Puppy

+2

'〜'はあなたの[ホームディレクトリ](http://unix.stackexchange.com/questions/23375/what-exactly-is-a-home-directory)のショートカットで、ログインする場所です。通常は'/ home/username'' username'はあなたの実際のユーザー名です。 '.bashrc'は、あなたが望むように環境を設定するためにログインするときにbashが読むファイルです。 – Kevin

0

Pythonスクリプト

!!最後に.bashrsに任意の文字列を追加し、使用する前に!

使用name_script.pyのC:\パス

path_bachrc - パス

cmdを.bashrcにする - Cygwinの上

#***********************************************# 
# [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) 
0

バッシュは、あなたのホームフォルダで起動するcygwin.batへのパスを、 Cygwinが可能な限り厳密に模倣するLinuxのようなものです。したがって、あなたは単にchange your home folderにする必要があります。

(あなたのCygwinフォルダはWindowsユーザのホームフォルダと同じである必要はありませんが、デフォルトでは異なりますが、/cygdrive/c/Users/myidのようなものをCygwinユーザのエントリに入れて/etc/passwdにしてください)

1

~/.bash_profileには、cd /cygdrive/c/path/to/where/you/want/cygwin/to/startと書くことができます。このファイルはcygwinのインストールフォルダの<path_to_cygwin>\home\<user>\.bash_profileにあります。 (私の場合:C:\cygwin64\home\User\.bash_profile)。

関連する問題