cygwin 配置指南

[TOC]

安裝

官方網(wǎng)站
http://www.cygwin.com/
下載安裝
http://www.cygwin.com/setup-x86_64.exe

cygwin安裝目錄是C:\cygwin64\

Paste_Image.png

cygwin程序依賴(lài)目錄是

Paste_Image.png

建議選則國(guó)內(nèi)源,速度塊,且可以不斷更新

Paste_Image.png

建議選則國(guó)內(nèi)源,速度塊

必用插件

search中輸入 vim 等待片刻就會(huì)搜索出 vim 相關(guān)的模塊

Paste_Image.png

圖中keep表示已經(jīng)安裝完成,未安裝的點(diǎn)擊 成 install

常用安裝

vim - 默認(rèn)沒(méi)有安裝,請(qǐng)自行勾選后安裝
dos2unix 轉(zhuǎn)換 win 的腳本讓 unix 可用
curl(Net)
wget(Web)
time (GUN time commond)

推薦一定安裝 dos2unix 用于修復(fù) windows 換行符導(dǎo)致的腳本報(bào)錯(cuò) ^m 無(wú)法運(yùn)行的錯(cuò)誤

配置

加入右鍵菜單

如果安裝目錄修改過(guò),請(qǐng)自行替換腳本或者配置的對(duì)應(yīng)目錄

新建文件 cygwinRegDirShell.reg

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin]
""="CygWin Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin]
"Icon"="C:\\cygwin64\\Cygwin.ico"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin]
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin\command]
""="C:\\cygwin64\\Cygwin.bat %V"

運(yùn)行這個(gè)腳本即可寫(xiě)入注冊(cè)表

或者Win+R 輸入 regedit
進(jìn)入節(jié)點(diǎn) HKEY_CLASSES_ROOT\Directory\Background\shell

鼠標(biāo)右鍵,選擇新建->項(xiàng)填寫(xiě)cygwin 在右側(cè)窗口填入值

Paste_Image.png

右側(cè)數(shù)值添加 鼠標(biāo)右鍵 新建->字符串值

名稱(chēng) 類(lèi)型 數(shù)據(jù)
默認(rèn) REG_SZ CygWin Here
Icon REG_SZ C:\cygwin64\Cygwin.ico
NoWorkingDirectory REG_SZ
Paste_Image.png

然后鼠標(biāo)右鍵剛創(chuàng)建的 cygwin,選擇新建->項(xiàng),填寫(xiě)command
在右側(cè)填入

名稱(chēng) 類(lèi)型 數(shù)據(jù)
默認(rèn) REG_SZ C:\cygwin64\Cygwin.bat %V
Paste_Image.png
  • 然后進(jìn)入cygwin 安裝目錄修改Cygwin.bat文件
@echo off
setlocal enableextensions
set TERM=
set _T=%*
C:
chdir C:\cygwin64\bin
bash --login -i

修改.bash_profile文件,在C:\ctgwin64\home\[用戶名]\下, 在文件的最后增加

# Set CygWin Right Click open with folder
export _T=${_T//\\//}   # replace backslash to fowardslash
if [[ $_T == "" ]]; then
    export _T="c:/Users/${USER}"
fi
cd "$_T"

如果沒(méi)用找到.bash_profile文件,運(yùn)行一次 cygwin 將生成用戶文件基礎(chǔ)配置文件

換行符風(fēng)格

因?yàn)?win 的換行符不能在其他系統(tǒng)上使用,安裝 dos2unix 工具,再需要轉(zhuǎn)換的文本處執(zhí)行

dos2unix [filePath]

cygwin中文亂碼

這里是針對(duì)GBK亂碼,如果沒(méi)有亂碼就不需要修改

進(jìn)入用戶目錄, 打開(kāi)目錄下 .bash_profile 文件

cd ~
vim .bash_profile

將如下內(nèi)容添加到文件的末尾

## for windows GBK
export LC_CTYPE=zh_CN.GBK
export LANG=zh_CN.GBK
export OUTPUT_CHARSET=GBK
export XMODIFIERS=@im=Chinput3
stty cs8 -istrip
stty pass8
export LESSCHARSET=latin1

然后打開(kāi)用戶根目錄的 .inputrc 文件,解開(kāi)注釋

# Allow 8-bit input/output

增加bash 對(duì)8 字節(jié)字符處理

加載配置生效

source ~/.bash_profile

文件作色

修改~/.bashrc 在最末尾增加內(nèi)容

alias ls='ls -F -N --color=auto'

然后執(zhí)行 source ~/.bashrc

用戶環(huán)境變量

  • 用戶環(huán)境變量,在~/.bash_profile 的Set CygWin 前添加,以后的設(shè)置也這樣
alias ls='ls -hG'
alias ll='ls -l'
alias la='ls -a'
alias l='ls -CF'
alias gs='git status'

然后執(zhí)行 source ~/.bash_profile

vim基礎(chǔ)配置

在用戶的跟新建文件 vim ~/.vimrc 內(nèi)容有

" windows backspace can delete
set backspace=indent,eol,start
" open syntax
syntax on
" close compatible like annotate
:set nocompatible
" set not show line number can change by :set nu
:set nonu
" show cmd
:set showcmd

" set show line number when in edit
:set ruler
" set tab button stop
" default tabstop=8
:set tabstop=4
:set softtabstop=4
:set shiftwidth=4
:set expandtab
" use keyboard F11 to change paste mode
:set pastetoggle=<F11>
" normal is :set nolist | show hide is :set invlist
:set nolist

如果想使用 vi 類(lèi)似 vim 需要修改成這樣

" windows backspace can delete
set backspace=indent,eol,start
" open syntax
syntax on
" close compatible like annotate
set nocompatible
" set not show line number can change by :set nu
:set nonu
" show cmd
set showcmd

" set show line number when in edit
:set ruler
" set tab button stop
" default tabstop=8
:set tabstop=4
:set softtabstop=4
:set shiftwidth=4
:set expandtab

" use keyboard F11 to change paste mode
:set pastetoggle=<F11>
" normal is :set nolist | show hide is :set invlist
:set nolist

set wildmenu
set fo=cqrt
set laststatus=2
set textwidth=78
set ww=<,>,h,l
set autoindent
" set no error bells
set noeb visualbell
let mapleader = ","
syn on
filetype on
filetype plugin on
filetype indent on

shell老是提示\r錯(cuò)誤

檢查shell 內(nèi)容錯(cuò)誤cat -v

解決方法是對(duì)文件進(jìn)行換行風(fēng)格處理

sed 's/..$//g' srcfile > destfile

ssh / git-ssh配置

win+r 運(yùn)行 cygwin

cd ~
mkdir .ssh
cd .ssh
sshkey-gen -t rsa -C "your@mail.com"

輸入文件別名的生成 some-git.pubsome-git

然后配置本地ssh設(shè)置

vim config
# 輸入內(nèi)容為
Host gitlab.yougit.com
  HostName gitlab.yougit.com
  IdentityFile ~/.ssh/some-git

如果是ssh遠(yuǎn)程到服務(wù)器,可以添加

  • User 來(lái)設(shè)置用戶
Host youserver.host.com
  HostName 192.168.1.101
  User mine
  IdentityFile ~/.ssh/my_server

配置服務(wù)端

cat some-git.pub

把輸出的內(nèi)容配置到服務(wù)端

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容