Git Bash 셸 사용자 지정
18067 단어 bashbeginnersgitproductivity
시작 파일 사용자 지정
Git bash 셸은 Git 전용 인증 액세스를 위한 대화형 로그인 셸로 호출됩니다. Bash는 몇 가지 시작 파일을 사용하여 사용자를 위한 셸 환경을 구성합니다.
~/.bash_profile
, ~/.bash_login
및 ~/.profile
와 같은 파일을 주어진 순서대로 소싱합니다. 존재하는 첫 번째 읽을 수 있는 파일이 소싱됩니다.배쉬 프로필
1.
~/.bash_profile
파일을 생성합니다. .bash_profile
에는 셸의 환경 변수를 설정하는 명령이 포함되어 있습니다. ~/.bash_profile
대신 A~/.profile
를 사용할 수 있지만 Bash에서만 읽을 수 있습니다. 쉘이 대화식이므로 ~/.bashrc
파일이 제공되지 않습니다. 자세한 내용은 Bash Manual을 참조하십시오. 아래의 모든 내용을 자신의 파일에 복사하십시오.# Source the ~/.bashrc file if it exists
if [ -f ~/.bashrc ]
then
. ~/.bashrc
fi
배쉬 쉘 스크립트
2.
~/.bashrc
파일을 생성합니다. .bashrc
파일에는 Bash 셸과 관련된 명령이 포함되어 있습니다. 별칭 및 bash 관련 기능을 위한 최적의 장소입니다. 아래의 모든 내용을 자신의 파일에 복사하십시오.# Git aliases
alias gs='git status -sb'
alias gcc='git checkout'
alias gcm='git checkout master'
alias gaa='git add --all'
alias gc='git commit -m $2'
alias push='git push'
alias gpo='git push origin'
alias pull='git pull'
alias clone='git clone'
alias stash='git stash'
alias pop='git stash pop'
alias ga='git add'
alias gb='git branch'
alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias gm='git merge'
# Bash aliases
alias .='cd .'
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias bashclear='echo "" > ~/.bash_history'
alias cls='clear'
alias ls='ls -F --color=auto --show-control-chars'
alias ll='ls -l'
alias ll.='ls -la'
alias lls='ls -la --sort=size'
alias llt='ls -la --sort=time'
alias rm='rm -iv'
alias work='cd /c/repos'
# Bash shell settings
# Typing a directory name just by itself will automatically change into that directory.
shopt -s autocd
# Automatically fix directory name typos when changing directory.
shopt -s cdspell
# Automatically expand directory globs and fix directory name typos whilst completing.
# Note, this works in conjuction with the cdspell option listed above.
shopt -s direxpand dirspell
# Enable the ** globstar recursive pattern in file and directory expansions.
# For example, ls **/*.txt will list all text files in the current directory hierarchy.
shopt -s globstar
# Ignore lines which begin with a <space> and match previous entries.
# Erase duplicate entries in history file.
HISTCONTROL=ignoreboth:erasedups
# Ignore saving short- and other listed commands to the history file.
HISTIGNORE=?:??:history
# The maximum number of lines in the history file.
HISTFILESIZE=99999
# The number of entries to save in the history file.
HISTSIZE=99999
# Set Bash to save each command to history, right after it has been executed.
PROMPT_COMMAND='history -a'
# Save multi-line commands in one history entry.
shopt -s cmdhist
# Append commands to the history file, instead of overwriting it.
# History substitution are not immediately passed to the shell parser.
shopt -s histappend histverify
힘내 배쉬 프롬프트
Git Bash 프롬프트는
git-prompt.sh
라는 셸 스크립트로 설정되며 c/Program\ Files/Git/etc/profile.d
디렉토리에서 찾을 수 있습니다. 8-10행에서 사용자 지정~/.config/git/git-prompt.sh
파일이 있는 경우 소싱됩니다. 이것이 기본 설정을 재정의하는 데 권장되는 방법이라고 생각합니다.# lines omitted
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
else
# lines omitted
fi
# lines omitted
3.
~/.config/git/git-prompt.sh
파일을 생성합니다. git-prompt.sh
파일에는 Git Bash 터미널의 제목과 Bash 프롬프트 문자열을 설정하는 명령이 포함되어 있습니다. 아래의 모든 내용을 자신의 파일에 복사하십시오.# Custom prompt settings
PROMPT_DIRTRIM=4 # Shorten deep paths in the prompt
PS1='\[\033]0;Git | Bash v\v | \W\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[30;45m\] [\A] ' # black text, magenta, 24h time
PS1="$PS1"'\[\033[30;42m\] \u ' # black text, green, user
#PS1="$PS1"'\[\033[30;42m\]@\h ' # black text, green, @host
PS1="$PS1"'\[\033[30;43m\] \w ' # black text, yellow, working director
if test -z "$WINELOADERNOEXEC"
then
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
if test -f "$COMPLETION_PATH/git-prompt.sh"
then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[97;46m\]' # white text, cyan
PS1="$PS1"'`__git_ps1`' # bash function
fi
fi
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
# Git status options
# Shows * or + for unstaged and staged changes, respectively.
export GIT_PS1_SHOWSTASHSTATE=true
# shows $ if there are any stashes.
export GIT_PS1_SHOWDIRTYSTATE=true
# Shows % if there are any untracked files.
export GIT_PS1_SHOWUNTRACKEDFILES=true
# shows <, >, <>, or = when your branch is behind, ahead, diverged from,
# or in sync with the upstream branch, respectively.
export GIT_PS1_SHOWUPSTREAM="auto"
사용자 구성
4.
~/.inputrc
파일을 생성합니다. 이 파일에는 내장된 GNU Readline 라이브러리를 사용하여 명령 히스토리, 디렉토리 표시 및 키보드 바인딩을 구성하는 명령이 포함되어 있습니다. 자세한 내용은 Bash Manual 및 Readline Documentation을 참조하십시오.# Disable beeps & bells, and do not display control characters.
set bell-style none
set echo-control-characters off
# The TAB key cycles forward through the completion choices.
# Press an arrow key, such as right-arrow, to choose a selection.
TAB: menu-complete
# The Shift-TAB key cycles backward through the completion choices.
# Like TAB, press an arrow key, such as right-arrow, to choose a selection.
"\e[Z": menu-complete-backward
# The first TAB key press will display a list that match the given prefix.
# The next TAB key press will start cycling through the available choices.
set menu-complete-display-prefix on
# Display completion matches upon the first press of the TAB key.
#set show-all-if-ambiguous on
#Enable colors when completing filenames and directories.
set colored-stats on
# Completion matches of multiple items highlight the matching prefix in color.
set colored-completion-prefix on
# Ignore case when completing.
set completion-ignore-case on
# Treat hypens and underscores as equivalent when completing.
set completion-map-case on
# Append the / character to the end of symlinked directories when completing.
set mark-symlinked-directories on
# Enable incremental history navigation with the UP and DOWN arrow keys.
# This will use the already typed text as a required prefix.
"\e[A": history-search-backward
"\e[B": history-search-forward
Readline 라이브러리는 또한 몇 가지 유용한 단축키를 제공합니다.
키보드 단축키
설명
컨트롤-A
줄의 시작 부분으로 이동합니다.
컨트롤-E
라인의 끝으로 이동합니다.
Alt-B
한 단어 뒤로 이동합니다.
Alt-F
앞으로 나아가십시오.
Alt-백스페이스
한 단어 뒤로 삭제합니다.
Alt-D
앞으로 한 단어를 삭제합니다.
컨트롤-R
역사를 통해 다시 검색하십시오.
컨트롤-R
기록을 거꾸로 순환합니다.
Control-Shift-R
역사를 앞으로 순환하십시오.
대체-.
이전 명령의 인수를 추가합니다.
완성된 결과
5. 사용자 지정이 완료되면 터미널을 다시 시작하거나 Windows 터미널에서 새 Git Bash 탭을 엽니다. Git Bash는 아래 결과와 유사해야 합니다.
배시 유틸리티
일부 Bash 유틸리티는 Windows용 Git에도 포함되어 있으며 기본 동작을 원하지 않는 경우 Git 환경을 개선하는 데 사용할 수 있습니다. 이러한 유틸리티는 각 독립 개발 환경에서 구성해야 합니다. 자세한 내용은 Pro Git Book을 참조하십시오.
git-completion 및 git-prompt 스크립트는 다음 디렉토리에서 찾을 수 있습니다.
/c/Program\ Files/Git/mingw64/share/git/completion/
git-completion.bash
및 git-prompt.sh
를 홈 디렉토리에 복사합니다.스크립트를 사용하려면
~/.bashrc
파일에 다음 줄을 추가합니다.# Enable tab completion for Git commands
source ~/.git-completion.bash
# Change bash prompt to display current Git branch and status
source ~/.git-prompt.sh
Reference
이 문제에 관하여(Git Bash 셸 사용자 지정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/blikoor/customize-git-bash-shell-498l텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)