agkozak/zsh-z

[Need help]How to set the variables for zsh-z?

shenmishajing opened this issue · 6 comments

How to set the variables for zsh-z? I add the following code to my .zshrc, but it does not work.

export ZSHZ_DATA=$ZSH_CUSTOM/plugins/z/data
export ZSHZ_ECHO=1
export ZSHZ_CASE=smart
export ZSHZ_NO_RESOLVE_SYMLINKS=1

I have tried to put them in the beginning of my .zshrc, but they do not work also. So, How should I set those variables correctly?

How strange. When I put your code into a .zshrc, it works for me.

Could you post the whole .zshrc so that I can see if there are any conflicts? Thanks.

@agkozak Here is my .zshrc:

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="powerlevel10k/powerlevel10k"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.

plugins=(
  copypath
  copyfile
  sudo
  git
  z
  zsh-history-substring-search
  zsh-autosuggestions
  fast-syntax-highlighting
)

export ZSH_COMPDUMP=$ZSH/cache/.zcompdump-$(scutil --get ComputerName 2>/dev/null)-${ZSH_VERSION}
source $ZSH/oh-my-zsh.sh

HB_CNF_HANDLER="$(brew --repository)/Library/Taps/homebrew/homebrew-command-not-found/handler.sh"
if [ -f "$HB_CNF_HANDLER" ]; then
source "$HB_CNF_HANDLER";
fi

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

bindkey '^p' history-substring-search-up
bindkey '^n' history-substring-search-down

# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
  OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
  zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
  zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish

export ZSHZ_DATA=$ZSH_CUSTOM/plugins/z/data
export ZSHZ_ECHO=1
export ZSHZ_CASE=smart
export ZSHZ_NO_RESOLVE_SYMLINKS=1

alias ls='lsd'
alias l='ls -alg'
alias co='code'
export editor='code --wait'

export HOMEBREW_API_DOMAIN="https://mirrors.bfsu.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.bfsu.edu.cn/homebrew-bottles"
export HOMEBREW_PIP_INDEX_URL="https://mirrors.bfsu.edu.cn/pypi/web/simple"
export HOMEBREW_CLEANUP_MAX_AGE_DAYS=0

# set proxy
export proxy_ip='localhost'
export proxy_port='7890'
alias sp='export https_proxy=http://$proxy_ip:$proxy_port http_proxy=http://$proxy_ip:$proxy_port all_proxy=socks5://$proxy_ip:$proxy_port'
# unset proxy
alias up='unset all_proxy&&unset https_proxy&&unset http_proxy'
# echo proxy
alias ep='echo "http_proxy=$http_proxy\nhttps_proxy=$https_proxy\nall_proxy=$all_proxy"'

# use proxy in terminal
sp

# To customize prompt, run `p10k configure` or edit $ZSH_CUSTOM/themes/powerlevel10k/.p10k.zsh.
[[ ! -f $ZSH_CUSTOM/themes/powerlevel10k/.p10k.zsh ]] || source $ZSH_CUSTOM/themes/powerlevel10k/.p10k.zsh

by the way, I have move the ~/.p10k.zsh to $ZSH_CUSTOM/themes/powerlevel10k/.p10k.zsh

Thanks! I'll try out your configuration a little later.

Could you also check to make sure that you're running an up-to-date version of Oh-My-Zsh where z is my agkozak/zsh-z and not the old rupa/z? If you type

less ~/.oh-my-zsh/plugins/z/z.plugin.zsh

you should see

################################################################################
# Zsh-z - jump around with Zsh - A native Zsh version of z without awk, sort,
# date, or sed
#
# https://github.com/agkozak/zsh-z
#
# Copyright (c) 2018-2023 Alexandros Kozak

Yes, I have updated oh-my-zsh recently. This is the result of less

Screenshot 2023-11-16 at 11 55 59

Thanks for your help.

@agkozak Well, I'm sorry that I find they already work. I think the reason of this is that I restart a terminal after I set those variables, but I forget to restart all the terminals, especially those in tmux, so I get a .z file created under my home dir again and again. It's my fatal error, sorry for this.

Good job diagnosing that. It will be good for me to remember that that can happen moving forward.