2012-02-29 60 views
45

在Bash中,當我打開兩個終端時,每個終端都保持其自己的歷史記錄,因此點擊箭頭總是顯示在該終端中輸入的以前的命令。同一終端的最後一個命令

在zsh中,歷史記錄是共享的,因此箭頭向上顯示在任一終端中輸入的最後一個命令。我非常喜歡ctrl-R給了我完整的共享歷史記錄,但是有沒有辦法讓箭頭向我提供來自活動終端的最後一條命令?

+0

對此有過任何裁決嗎?我似乎記得遇到了這個技巧的網站。 IMO這應該是默認行爲。 – lang2 2016-12-14 10:07:44

+0

一個很好的選擇,有兩個:https://superuser.com/questions/446594/separate-up-arrow-lookback-for-local-and-global-zsh-history – Melebius 2017-09-12 09:58:33

回答

68

setopt是什麼意思?

也許你可以選擇SHARE_HISTORY集。

你可以使用setopt no_share_historyunsetopt share_history來解除它。

如需更多選項,請登錄man zshoptions

+12

我懷疑很多人可能會在這裏降落(像我一樣),同時尋找共享zsh歷史的方式,並且在同一個窗口中仍然首先顯示_last_命令。 – Excalibur 2012-07-24 19:09:34

+1

非常好,正是我在找的東西,'setopt'不是很直觀,我期待像'setopt share_history 0'' – 2013-07-12 12:43:27

+0

@Excalibur你是對的。你有沒有找到任何解決方案如何得到這種行爲? – lumbric 2013-12-19 13:59:21

1

我不能直接幫你,但在我的終端裏,命令歷史是一對一的終端,所以它是你期望的行爲。下面我打印出我的.zshrc文件。請與它一起玩。我用Yakuake運行我的終端。

# The following lines were added by compinstall 

bindkey -v 

bindkey -M viins '^r' history-incremental-search-backward 
bindkey -M vicmd '^r' history-incremental-search-backward 


#http://grml.org/zsh/zsh-lovers.html 
zstyle ':completion:*' use-cache on 
zstyle ':completion:*' cache-path ~/.zsh/cache 



zstyle ':completion:*' completer _complete _match _approximate 
zstyle ':completion:*:match:*' original only 
zstyle ':completion:*:approximate:*' max-errors 1 numeric 
zstyle ':completion:*' expand prefix suffix 
zstyle ':completion:*' list-colors '' 
zstyle ':completion:*' list-suffixes true 
zstyle ':completion:*' original true 
zstyle ':completion:*:functions' ignored-patterns '_*' 
zstyle ':completion:*:cd:*' ignore-parents parent pwd 
zstyle :compinstall filename '/home/borys/.zshrc' 
zstyle ':completion:*:(rm|kill|diff):*' ignore-line yes 

autoload colors; colors 
setopt autocd 
setopt extendedglob 


autoload -Uz compinit 
compinit 
# End of lines added by compinstall 
# Lines configured by zsh-newuser-install 
HISTFILE=~/.histfile 
HISTSIZE=1000 
SAVEHIST=1000 
# End of lines configured by zsh-newuser-install 

# opens txt files in vi 
alias -s txt=vi 

#shortcuts for going up in directories hierarchy 
alias -g ...='../..' 
alias -g ....='../../..' 
alias -g .....='../../../..' 

alias d="dirs -v" 
setopt PUSHD_IGNORE_DUPS 
setopt AUTO_PUSHD 
DIRSTACKSIZE=14 



alias findfn="find -type f -name " 
alias duall="du -s ./* | sort -n| cut -f 2-|xargs -i du -sh {}" 

#prompt theme 
COLOR_RESET="%{$reset_color%}" 
PS1="$fg_bold[black][%[email protected]%m:$fg[blue]%~] 
$COLOR_RESET%%" 
PS2=$PS1 
    # PS1=[%[email protected]%m:%2~] 

# color stderr 
exec 2>>(while read line; do 
    print '\e[91m'${(q)line}'\e[0m' > /dev/tty; print -n $'\0'; done &) 

#show vi mode in prompt 
function zle-line-init zle-keymap-select { 
#fg_light_red=$'%{\e[5;25m%}' 

# RPS1="$fg_light_red ${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}" 
# RPS2=$RPS1 
# PS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --} 
#[%[email protected]%m:%2~]" 
PS1="${${KEYMAP/vicmd/$COLOR_RESET}/(main|viins)/$fg_bold[black]}[%[email protected]%m:$fg[blue]%~] 
$COLOR_RESET%%" 
    PS2=$PS1 
    zle reset-prompt 
} 
zle -N zle-line-init 
zle -N zle-keymap-select 

export SVN_EDITOR=vi