您尚未登录。

#1 2025-03-14 21:05:30

lwalwg
会员
注册时间: 2021-11-15
帖子: 44

[关帖]疑惑,问个zsh和bash的问题

感觉bash(lxterminal)功能不够,看大家都推荐zsh,安装了oh-my-zsh-git;
也尝试了iso的那个软件,最后又卸载了。

现在是拷贝网络的配置后自己修改了,可是效果不理想。
想实现历史命令不重复(bash和zsh),显示日期,但是为什么.bashrc的export映射到zsh中。
附.zshrc (wiki中附一个配置例子,只修改了开头,消除重复和存放命令文件路径等其他没修改)
https://github.com/MrElendig/dotfiles-a … ter/.zshrc

#消除历史记录重复条目
setopt HIST_IGNORE_DUPS
# Share history in every terminal session
setopt SHARE_HISTORY
#------------------------------------------------------------------#
# File:     .zshrc   ZSH resource file                             #
# Version:  0.1.16                                                 #
# Author:   Øyvind "Mr.Elendig" Heggstad <mrelendig@har-ikkje.net> #
#------------------------------------------------------------------#

#-----------------------------
# Source some stuff
#-----------------------------
if [[ -f /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]]; then
  . /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi

BASE16_SHELL="$HOME/.config/base16-shell/base16-default.dark.sh"
[[ -s $BASE16_SHELL ]] && source $BASE16_SHELL

#------------------------------
# History stuff
#------------------------------
HISTFILE=~/.zsh_history
#HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000

#------------------------------
# Variables
#------------------------------
#export BROWSER="chromium"
#export EDITOR="nvim"
#export PATH="${PATH}:${HOME}/bin:${HOME}/.cabal/bin"
#export GOPATH="$HOME/go"

#-----------------------------
# Dircolors
#-----------------------------
LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:';
export LS_COLORS

#------------------------------
# Keybindings
#------------------------------
bindkey -v
typeset -g -A key
bindkey '^?' backward-delete-char
bindkey '^[[5~' up-line-or-history
bindkey '^[[3~' delete-char
bindkey '^[[6~' down-line-or-history
bindkey '^[[A' up-line-or-search
bindkey '^[[D' backward-char
bindkey '^[[B' down-line-or-search
bindkey '^[[C' forward-char
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line

#------------------------------
# Alias stuff
#------------------------------
alias ls="ls --color -F"
alias ll="ls --color -lh"
alias spm="sudo pacman"
alias gr="gvim --remote-silent"
alias vr="vim --remote-silent"

#------------------------------
# ShellFuncs
#------------------------------
# -- coloured manuals
man() {
  env \
    LESS_TERMCAP_mb=$(printf "\e[1;31m") \
    LESS_TERMCAP_md=$(printf "\e[1;31m") \
    LESS_TERMCAP_me=$(printf "\e[0m") \
    LESS_TERMCAP_se=$(printf "\e[0m") \
    LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
    LESS_TERMCAP_ue=$(printf "\e[0m") \
    LESS_TERMCAP_us=$(printf "\e[1;32m") \
    man "$@"
}

#------------------------------
# Comp stuff
#------------------------------
zmodload zsh/complist
autoload -Uz compinit
compinit
zstyle :compinstall filename '${HOME}/.zshrc'

#- buggy
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
#-/buggy

zstyle ':completion:*:pacman:*' force-list always
zstyle ':completion:*:*:pacman:*' menu yes select

zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*'   force-list always

zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*'   force-list always

#------------------------------
# Window title
#------------------------------
case $TERM in
  termite|*xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term)
    precmd () {
      vcs_info
      print -Pn "\e]0;[%n@%M][%~]%#\a"
    }
    preexec () { print -Pn "\e]0;[%n@%M][%~]%# ($1)\a" }
    ;;
  screen|screen-256color)
    precmd () {
      vcs_info
      print -Pn "\e]83;title \"$1\"\a"
      print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~]\a"
    }
    preexec () {
      print -Pn "\e]83;title \"$1\"\a"
      print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~] ($1)\a"
    }
    ;;
esac

#------------------------------
# Prompt
#------------------------------
autoload -U colors zsh/terminfo
colors

autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git hg
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:git*' formats "%{${fg[cyan]}%}[%{${fg[green]}%}%s%{${fg[cyan]}%}][%{${fg[blue]}%}%r/%S%%{${fg[cyan]}%}][%{${fg[blue]}%}%b%{${fg[yellow]}%}%m%u%c%{${fg[cyan]}%}]%{$reset_color%}"

setprompt() {
  setopt prompt_subst

  if [[ -n "$SSH_CLIENT"  ||  -n "$SSH2_CLIENT" ]]; then
    p_host='%F{yellow}%M%f'
  else
    p_host='%F{green}%M%f'
  fi

  PS1=${(j::Q)${(Z:Cn:):-$'
    %F{cyan}[%f
    %(!.%F{red}%n%f.%F{green}%n%f)
    %F{cyan}@%f
    ${p_host}
    %F{cyan}][%f
    %F{blue}%~%f
    %F{cyan}]%f
    %(!.%F{red}%#%f.%F{green}%#%f)
    " "
  '}}

  PS2=$'%_>'
  RPROMPT=$'${vcs_info_msg_0_}'
}
setprompt


# vim: set ts=2 sw=2 et:

.bashrc

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
alias grep='grep --color=auto'
PS1='[\u@\h \W]\$ '
#历史记录(无论是否连续,只记录最后一条)
#export HISTCONTROL=erasedups

#export HISTCONTROL=ignoreboth

#历史记录(连续记录一条)
export HISTFILESIZE= # unlimited
export HISTSIZE= # unlimited
export HISTCONTROL=erasedups:ignoredups:ignorespace # Don't put duplicate lines in the history and do not add lines that start with a space
#export HISTIGNORE="cd:pwd:ls:ll:l:la:[bf]g:exit" # ignore such commands
export HISTTIMEFORMAT='%Y%m%d-%H:%M:--'
export PROMPT_COMMAND='history -a'
#export PROMPT_DIRTRIM=3

现在怀疑出问题的就是HISTFORMAT,在bash中命令历史无问题,但是在zsh中怎么也受影响了?

现在运行了一下,zsh中history命令不显示一堆数字,可以用 -f,我已经source,注销,重启,都没作用。

startx
history 0
source .zshrc
history 0
fc
history 0
fc -lf
fc -IR
fc -IA
: 1741958994:0;history 0
: 1741959009:0;source .zshrc
: 1741959012:0;history 0
: 1741959059:0;history
: 1741959069:0;history 0
: 1741959103:0;vi .zsh_history
: 1741959283:0;cat .zsh_history

但是wiki中去重复语句不起作用。。

最近编辑记录 lwalwg (2025-03-14 21:42:49)

离线

#2 2025-03-14 21:25:19

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 9,168
个人网站

Re: [关帖]疑惑,问个zsh和bash的问题

setopt hist_save_no_dups
setopt hist_ignore_dups

zsh 的选项请 man zshoptions 查阅文档。

离线

#3 2025-03-14 21:36:46

lwalwg
会员
注册时间: 2021-11-15
帖子: 44

Re: [关帖]疑惑,问个zsh和bash的问题

好的,收到谢谢。
我关闭帖子,自己摸索吧。还是有问题
网上直接搜索到你的blog了,结果把命令历史给丢了(fc -IR ;fc -IA)。。。捂脸

最近编辑记录 lwalwg (2025-03-14 21:41:35)

离线

页脚