Zsh를 칭찬하는 게시물을 자주 접할 때 bash에서 zsh로 이동하는 것을 고려하고 있습니다. 나는 경험이 풍부한 커맨드 라인 사용자이며 기본 사항이 거의 동일하다고 가정하므로 이동의 이점을 얻고 조언을 구해야합니다.
답변 당 하나의 조언 만 제공하십시오. 나는 한 번에 모든 것을 배우려고하는 대신 돌아와서 여분의 정보 비트를 쉘 사용에 일정한 속도로 통합 할 수있는 한입 크기의 청크를 찾고 있습니다.
zsh
은 (는) bash
과 (와) 여러면에서 비슷합니다. bash
에는없는 몇 가지 기능이 있으며 강력한 방법으로 확장 할 수 있습니다. 움직이는 것을 일종의 혁명으로 생각하지 말고 일상 업무에서 도움이되는 일련의 진화 단계로 생각하십시오. 내 .zshrc
의 힌트입니다. 하나의 조언을 선호한다고하더라도이 게시물은 가장 긴 목록입니다. 여전히 포인트를 하나씩 살펴 보는 것이 좋습니다. 흥미로운 비트를 ~/.zshrc
에 추가하고 source ~/.zshrc
로 다시로드하십시오. 마지막 팁 : zsh
기본 ( "Emacs") 키보드 단축키 ^A ^E ^W Alt-F Alt-B Alt-P ^L ^R
의 키 입력을 배우십시오. Alt
을 두 개의 별도 키 입력으로 바꿀 수 있습니다. Alt-P
은 ESC
P
과 같습니다.
이를 통해보다 광범위한 탭 완성이 가능합니다.
autoload -U compinit
compinit
양쪽 끝에서 탭 완성.
setopt completeinword
탭 완성은 대소 문자를 구분하지 않아야합니다.
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
Killall을위한 더 나은 완성.
zstyle ':completion:*:killall:*' command 'ps -u $USER -o cmd'
"워드"의 정의를 변경합니다 (예 : ^ W와 함께.
autoload select-Word-style
select-Word-style Shell
Ls의 색상.
if [[ -x "`whence -p dircolors`" ]]; then
eval `dircolors`
alias ls='ls -F --color=auto'
else
alias ls='ls -F'
fi
Ls의 바로 가기.
alias ll='ls -l'
alias la='ls -a'
모든 열린 껍질에 대한 하나의 역사; 10,000 개의 항목을 저장합니다. 이것은 ./configure
등에 마지막으로 사용한 명령을 찾는 데 유용한 메모리 보조 도구가됩니다. Alt-P (이와 같이 시작하는 찾기 명령) 및 ^ R (이력 검색)을 자유롭게 사용하십시오.
HISTFILE=~/.zhistory
HISTSIZE=SAVEHIST=10000
setopt sharehistory
setopt extendedhistory
Ls **/*. txt (모든 텍스트 파일 찾기), ls -d *(D)
( "."로 시작하는 파일을 포함한 모든 파일 표시)과 같은 모든 종류의 확장 된 글 로빙을 활성화합니다. 자세한 내용을 보려면 man zshexpn
섹션 "FILENAME GENERATION"으로 이동하십시오.
# superglobs
setopt extendedglob
unsetopt caseglob
이 명령은 실행 기록없이 명령을 기억하는 데 유용합니다.
setopt interactivecomments # pound sign in interactive Prompt
"cd .."대신 "..", "cd/usr/include"대신 "/ usr/include"를 입력하십시오.
setopt auto_cd
좋은 프롬프트.
PS1='[%T] %[email protected]%m:%~# '
10 초 이상 걸리는 명령에 대한 CPU 사용 통계 표시
REPORTTIME=10
우분투에서 광범위하게 사용하는 일부 명령.
alias 'a=Sudo aptitude'
alias 'ai=Sudo aptitude install'
alias 'ar=Sudo aptitude remove'
alias 'au=Sudo aptitude update'
alias 'ag=Sudo aptitude safe-upgrade'
alias 'as=apt-cache search'
alias 'aw=apt-cache show'
크기별로 정렬 된 패키지를 나열합니다. 디스크 공간을 차지하는 패키지를 결정할 때 유용합니다.
function apt-list-packages {
dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | grep -v deinstall | sort -n | awk '{print $1" "$2}'
}
bash에서 Z Shell로 책을 추천합니다. 셸을 전환하는 데 필요한 모든 조언이 있습니다. 두 쉘의 차이점을 설명하고 새로운 zsher를 쉽게 사용할 수 있습니다.
여기 내 . zshrc 이며 가장 중요한 것입니다! zsh에는 사용할 수있는 옵션이 많으므로 인터넷 주변의 모든 예제를 보거나 Zsh homepage 에서 설명서를 읽으십시오.
내 .zshrc에는 명령 줄 오른쪽에 타임 스탬프 이외의 멋진 기능이 포함되어 있지 않습니다.
Btw, 여기 몇 가지 예가있는 곳마다 탭 완성을 시도하십시오.
mplayer -a[tab]
다음과 같은 것을 보여줄 것입니다.
mplayer -a
-ac -- force usage of a specific audio codec
-af -- activate audio filters
-afm -- force usage of a specific audio codec family
-alang -- select the DVD audio language
-ao -- specify audio driver
-aop -- specify audio output filter
암호가없는 ssh-keys 또는 ssh-agent를 사용하는 경우 원격 파일을 tabcomplete하는 것이 유용 할 수 있습니다.
scp apollo:/home/user/[tab]
Desktop/ Documents/ Downloads/ Music/ Pictures/ Public/ Templates/ Videos/
목록을 얻은 후 tab을 여러 번 눌러 다른 가능성을 순환 할 수 있습니다.
그러나이 쉘은 게으르고 표준 쉘이 어리 석고 짜증나는 느낌을 줄 것입니다!
특별히 유용한 확장 글로브 2 개 :
1- rmdir *(/^F)
-현재 디렉토리 아래의 비어 있지 않은 디렉토리를 모두 삭제하십시오.
2- grep traceback /srv/log/**/*(.m-2)
-지난 이틀 동안 수정 된 파일에서이 정규식을 찾으십시오
3- chmod g+w **/*(U^I)
-내가 쓸 수 있고 그룹 쓰기 가능하지 않은 파일을 그룹 쓰기 가능하게 만들기
네, 물론 이것을 find
로 쓸 수는 있지만 이것은 더 쉬워집니다. 공평하게 말해서 모두 명령 줄로 확장되는 것과 관련하여 두 가지 단점이 있습니다. 수천 개의 파일과 일치하면 명령 줄이 너무 길어지고 실패하고 두 번째로 모든 파일이 발견됩니다 파일이 실행되기 전에.
(아직 켜져 있지 않으면 setopt extendedglob
가 필요합니다.)
나는 bash에 대해 많이 알지 못하므로 경쟁 할 수 없다. 내 zsh 구성 파일의 일부 스 니펫.
일부 구성
HISTFILE=~/.zsh_history
HISTSIZE=1000
SAVEHIST=1000
REPORTTIME=10 # print elapsed time when more than 10 seconds
setopt NO_HUP
setopt NO_LIST_BEEP
setopt LOCAL_OPTIONS # allow functions to have local options
setopt LOCAL_TRAPS # allow functions to have local traps
setopt HIST_VERIFY
setopt SHARE_HISTORY # share history between sessions ???
setopt EXTENDED_HISTORY # add timestamps to history
setopt Prompt_SUBST
setopt CORRECT
setopt COMPLETE_IN_Word
setopt IGNORE_EOF
setopt APPEND_HISTORY # adds history
setopt INC_APPEND_HISTORY SHARE_HISTORY # adds history incrementally and share it across sessions
setopt HIST_IGNORE_ALL_DUPS # don't record dupes in history
setopt HIST_REDUCE_BLANKS
# Leave some chars out of the out of WORDCHARS so ^W acts more nicely
WORDCHARS='*?_-[]~\!#$%^(){}<>|`@#$%^*()+:?'
프롬프트에서 힘내
if [[ -n $SSH_CONNECTION ]]; then
export PS1='%m:%3~$(git_info_for_Prompt)%# '
else
export PS1='%3~$(git_info_for_Prompt)%# '
fi
일부 단축키는 줄의 시작 부분에 텍스트를 삽입하십시오.
insert_Sudo () { zle beginning-of-line; zle -U "Sudo " }
insert_apt () { zle beginning-of-line; zle -U "Sudo apt-get " }
insert_gem () { zle beginning-of-line; zle -U "Sudo gem " }
insert_install () { zle -U "install " }
zle -N insert-Sudo insert_Sudo
zle -N insert-apt insert_apt
zle -N insert-gem insert_gem
zle -N insert-install insert_install
bindkey "^B" insert-gem
bindkey "^N" insert-install
bindkey "^k" insert-Sudo
bindkey "^a" insert-apt
~/.zsh/functions에 저장 한 함수
Git_info_for_Prompt
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
if [ -d "$g/../.dotest" ]
then
if test -f "$g/../.dotest/rebasing"
then
r="|REBASE"
Elif test -f "$g/../.dotest/applying"
then
r="|AM"
else
r="|AM/REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
Elif [ -f "$g/.dotest-merge/interactive" ]
then
r="|REBASE-i"
b="$(cat "$g/.dotest-merge/head-name")"
Elif [ -d "$g/.dotest-merge" ]
then
r="|REBASE-m"
b="$(cat "$g/.dotest-merge/head-name")"
Elif [ -f "$g/MERGE_HEAD" ]
then
r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ]
then
r="|BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
then
if ! b="tag: $(git describe --exact-match HEAD 2>/dev/null)"
then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
if [ -n "$1" ]; then
printf "$1" "${b##refs/heads/}$r"
else
printf "[%s]" "${b##refs/heads/}$r"
fi
fi
일부 github 옵션
#compdef github
_github() {
if (( CURRENT > 2 )); then
# shift words so _arguments doesn't have to be concerned with second command
(( CURRENT-- ))
shift words
# use _call_function here in case it doesn't exist
_call_function 1 _github_${words[1]}
else
_values "github command" \
"fetch[Fetch from a remote to a local branch.]" \
"ignore[Ignore a SHA (from 'github network commits')]" \
"fetch_all[Fetch all refs from a user]" \
"info[Info about this project.]" \
"browse[Open this repo in a web browser.]" \
"home[Open this repo's master branch in a web browser.]" \
"clone[Clone a repo.]" \
"pull-request[Generate the text for a pull request.]" \
"network[Project network tools.]" \
"pull[Pull from a remote.]" \
"track[Track another user's repository.]"
fi
}
_github_pull() {
_arguments \
"--merge[Automatically merge remote's changes into your master.]"
}
_github_clone() {
_arguments \
"--ssh[Clone using the [email protected] style url.]"
}
_github_track() {
_arguments \
"--private[Use [email protected]: instead of git://github.com/.]" \
"--ssh[Equivalent to --private.]"
}
_github_network() {
if (( CURRENT > 2 )); then
# shift words so _arguments doesn't have to be concerned with second command
(( CURRENT-- ))
shift words
# use _call_function here in case it doesn't exist
_call_function 1 _github_network_${words[1]}
else
_values "github network command" \
"web[Open network in a web browser.]" \
"list[List networked repositories.]" \
"fetch[Fetched commits for a given networked repository.]" \
"commits[List networked commits not pulled into this repo.]"
fi
}
_github_network_commits() {
_arguments \
"--project[Filter commits on a certain project.]" \
"--author[Filter commits on a email address of author.]" \
"--common[Show common branch point.]" \
"--nocache[Do not use the cached network data.]" \
"--sort[How to sort : date(*), branch, author.]" \
"--thisbranch[Look at branches that match the current one]" \
"--applies[Filter commits to patches that apply cleanly.]" \
"--limit[Only look through the first X heads - useful for really large projects]" \
"--before[Only show commits before a certain date.]" \
"--after[Only show commits after a certain date.]" \
"--shas[Only show shas.]" \
"--cache[Use the network data even if it's expired.]" \
"--noapply[Filter commits to patches that do not apply cleanly.]"
}
나는 같은 여행에있다 :)
지금까지 나는 좋은 구성 파일 (.zshrc)을 가지고 있다는 것을 알았습니다.
이것을 예로 들어 http://matt.blissett.me.uk/linux/zsh/zshrc 의견을보고 주위를 해킹하십시오. 스택 오버 플로우 및 severphault 및 검색하기에도 좋은 장소.
나는 아직 http://dotfiles.org/.zshrc 에 뛰어 들지 않았지만 느슨하게 할 시간이 없다. :)
Zsh의 확장 된 globbing 및 재귀 glob에 대해 학습하십시오.
Zstyle과 zstyle을 사용하여 다양한 구성 (특히 완료)을 사용하여 구성을 조정하는 방법에 대해 조금 배우십시오.
연관 배열을 살펴보십시오. 또한 표준 배열 (bash와의 차이점에주의하십시오)
정규식을 사용하는 경우 =~
(bash에도 있음)을 살펴보고 setopt rematch_pcre
환상적인 zsh는 쓰기 전용 인 경향이 있기 때문에 zsh의 마법에 의존하는 스크립트는 작성하지 마십시오. 너무 많이 사용하는 경우 파이썬과 같은 언어로 언제 전환해야하는지 생각해보십시오.
Zsh는 매혹적입니다. 어두운면입니다. 어서 오십시오.
큰 이점 – 많은 명령에 대해 사전 패키지 된 완료 스크립트를 사용하여 탁월한 탭 완성. apt-get<TAB>
의 출력을 보여주는 예는 다음과 같습니다.
apt-get
action
autoclean build-dep clean dselect-upgrade install remove update
autoremove check dist-upgrade help purge source upgrade
나는 대화의 쿠페를주고 여러 사람들을 zsh로 전환했습니다. 여기에 github의 시작 및 자체 zsh 구성 사본과 함께 내 (이점은 무엇입니까) 메모의 github 저장소를 유지하십시오.
또 다른 훌륭한 리소스는 zsh lovers page ( grml zsh site 에서 제공)입니다.