Mac 使用ZSH终端设置问题,解决command not found
来源:互联网 发布:数据库笔试题及答案 编辑:程序博客网 时间:2024/06/04 22:06
可参考网址:https://stackoverflow.com/questions/8299610/zsh-command-not-found-for-editor
说明:此网站加载很慢,这里拷贝了一份,方便大家参考
For whatever reason, zsh doesn't like me setting command-line arguments for my $EDITOR
variable, but from what I can tell, it's not supposed to be this way. I've seen people use
export EDITOR='open -Wn'
in their ~/.zshrc file, but when I try to do that, I just get a complaint.
zsh: command not found: open -Wn
Any reason why this might be happening? Setting the $EDITOR
to 'mate'
, 'vim'
or 'open'
seems to work just fine, but 'mate -w'
and 'open -Wn'
don't work.
I'm running zsh inside screen on Mac OS X, and my ~/.zshrc is as follows:
# -----------------------------------------------# Screen Settings# -----------------------------------------------# If screen isn't already running, turn it on.if [[ $STY == '' ]]; then # Execute screen. exec screen -aADRUfi# -----------------------------------------------# Startup Scripts# -----------------------------------------------cd ~/Desktop[[ -s "~/.rvm/scripts/rvm" ]] && source "~/.rvm/scripts/rvm"# -----------------------------------------------# Environment Variables# -----------------------------------------------export HISTFILE=~/.zsh_historyexport HISTSIZE=10000export HISTCONTROL=ignoredupsexport SAVEHIST=10000export PATH=.:/usr/local/bin:/usr/local/sbin:/usr/local/narwhal/bin:/bin:/sbin:/usr/bin:/usr/local/share:/usr/sbin:/usr/local/texlive/2011/bin/universal-darwinexport EDITOR='open -Wn'export LC_TYPE=en_US.UTF-8export LSCOLORS=exFxcxdxAxexbxHxGxcxBx# -----------------------------------------------# Prompt# -----------------------------------------------## Root Prompt[ $UID = 0 ] && export PROMPT="%~ +=> " && export RPROMPT="%*"## General Prompt[ $UID != 0 ] && export PROMPT="%~ => " && export RPROMPT="%*"# -----------------------------------------------# Aliases# -----------------------------------------------## Command Aliasesalias ..='cd ..'alias ...='cd ../..'alias internet='lsof -P -i -n | cut -f 1 -d " " | uniq'alias restart='sudo shutdown -r NOW'alias ls='ls -@1AFGph'alias tree='tree -alCF --charset=UTF-8 --du --si'alias mate='mate -w'alias zshrc='$EDITOR ~/.zshrc && source ~/.zshrc'alias vimrc='$EDITOR ~/.vimrc.local'alias gvimrc='$EDITOR ~/.gvimrc.local'## Root Aliases[ $UID = 0 ] && \ alias rm='rm -i' && \ alias mv='mv -i' && \ alias cp='cp -i'# -----------------------------------------------# User-defined Functions# -----------------------------------------------# Usage: extract <file># Description: extracts archived files / mounts disk images.# Note: .dmg/hdiutil is Mac OS X-specific.extract () { if [ -f $1 ]; then case $1 in *.tar.bz2) tar -jxvf $1 ;; *.tar.gz) tar -zxvf $1 ;; *.bz2) bunzip2 $1 ;; *.dmg) hdiutul mount $1 ;; *.gz) gunzip $1 ;; *.tar) tar -xvf $1 ;; *.tbz2) tar -jxvf $1 ;; *.tgz) tar -zxvf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *) echo "'$1' cannot be extracted/mounted via extract()." ;; esac else echo "'$1' is not a valid file." fi}# Usage: pman <manpage># Description: opens up the selected man page in Preview.pman () { man -t $@ | open -f -a /Applications/Preview.app}# Usage: fp <name># Description: find and list processes matching a case-insensitive partial-match string.fp () { ps Ao pid,comm|awk '{match($0,/[^\/]+$/); print substr($0,RSTART,RLENGTH)": "$1}'|grep -i $1|grep -v grep}# Usage: fk <name># Description: find and kill a process matching a case-insensitive partial-match string.fk () { IFS=$'\n' PS3='Kill which process? (1 to cancel): ' select OPT in "Cancel" $(fp $1); do if [ $OPT != "Cancel" ]; then kill $(echo $OPT|awk '{print $NF}') fi break done unset IFS}# Usage: create <file># Description: creates and opens a file for editing.create () { touch $1 && open $1}# Usage: reset# Description: 'resets' the terminal by changing the current working directory# to the desktop and clearing the screen.reset () { cd ~/Desktop; clear}# Usage: quit# Description: exits the terminal.quit () { killall Terminal}# -----------------------------------------------# zsh Options# -----------------------------------------------# Directoriessetopt \ AUTO_CD \ AUTO_PUSHD \ CD_ABLE_VARS \ CHASE_DOTS \ CHASE_LINKS \# Completionsetopt \ AUTO_LIST \ AUTO_MENU \ AUTO_PARAM_SLASH \ COMPLETE_IN_WORD \ LIST_TYPES \ MENU_COMPLETE \ REC_EXACT \# Historysetopt \ APPEND_HISTORY \ EXTENDED_HISTORY \# Input/Outputsetopt \ CORRECT \# Scripts and Functionssetopt \ MULTIOS \# Othersetopt \ NO_BEEP \ ZLE# Key Bindingsbindkey "^[[3~" delete-char# -----------------------------------------------# zsh Autocompletion# -----------------------------------------------# Turn on auto-completion.autoload -U compinit && compinit -C && autoload -U zstyle+# Attempt to complete as much as possible.zstyle ':completion:*' completer _complete _list _oldlist _expand _ignored _match _correctzstyle ':completion:*::::' completer _expand _complete _ignored _approximate# Sort files by name.zstyle ':completion:*' file-sort name# Allow for case-insensitive completion.zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'# Color completions.zstyle ':completion:*' list-colors ${LSCOLORS}zstyle ':completion:*:*:kill:*:processes' command 'ps -axco pid,user,command'zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'# Set the amount of completions that triggers the menu.zstyle ':completion:*' menu select=long# Ignore certain patterns.zstyle ':completion:*:functions' ignored-patterns '_*'zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.(o|c~|old|pro|zwc)'# Cache completions.zstyle ':completion::complete:*' use-cache 1zstyle ':completion::complete:*' cache-path ~/.zcompcache/$HOST# Allow errors.zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'# Insert all expansions for expand completer (eh, don't know what this does).zstyle ':completion:*:expand:*' tag-order all-expansions# Formatting and messages.zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'zstyle ':completion:*' verbose yeszstyle ':completion:*:descriptions' format '%B%d%b'zstyle ':completion:*:messages' format '%d'zstyle ':completion:*:warnings' format 'No matches for: %d'zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'zstyle ':completion:*' group-name ''# Offer indexes before parameters in subscripts.zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
3 Answers
In zsh, when you write $EDITOR
, it expands to a single word. Unlike other Bourne-style shells, zsh does not split words when it expands unquoted expansions. You can make it happen with the =
modifier on parameter expansion.
$=EDITOR $file
A more portable method is to ensure that EDITOR
does not contain any space. Most applications treat $EDITOR
as a shell snippet or as a whitespace-separated list of words, but I've encountered a few that treat it as a command name. Make EDITOR
point to a shell script.
% cat ~/bin/EDITOR#!/bin/shopen -Wn -- "$@"% grep EDITOR ~/.profileexport EDITOR=~/bin/EDITOR
How are you invoking the EDITOR? If you have EDITOR set with options, then you would get an error with:
$ $EDITOR file
but it should work if you do:
$ eval $EDITOR file
eval
, you can turn on word splitting specifically on this expansion: $=EDITOR file
. – Gilles Nov 28 '11 at 21:34Programs that invoke the editor defined by $EDITOR
may assume that the whole string referenced by it is the name of the command. So they will try to find an executable file called open -Wn
.
Another issue is that open merely opens the file with an application that the operating system deems appropriate. If there is no application associated with the file type, the command will fail.
- Mac 使用ZSH终端设置问题,解决command not found
- mac 终端 command not found
- mac下终端出现command not found现象解决
- zsh:Command not found : adb
- zsh: command not found: gradle
- zsh: command not found: conda
- 解决Mac上adb: command not found问题
- 解决Mac上adb: command not found问题
- 解决Mac上adb: command not found问题
- 解决Mac上adb: command not found问题
- 解决Mac上adb: command not found问题
- 解决Mac上adb: command not found问题
- Mac添加环境变量,解决command not found
- Mac上终端执行命令出现command not found解决办法
- Mac - 终端报错 -bash: startup.sh: command not found
- Mac OS 终端命令行执行总是出现 command not found
- Mac OS 终端命令行执行总是出现 command not found
- oh-my-zsh ,“zsh: command not found: adb”
- JWT token令牌
- 2017赛季ACM区域赛战绩汇总【END】
- day08-vim编辑
- 进程间通信——共享内存
- 用TextWatcher限制输入长度并弹出提示
- Mac 使用ZSH终端设置问题,解决command not found
- HTML基础-第一部分
- 指针+选太子
- JS小算法
- Hibernate回顾
- 前文
- partition-list
- Spring与mybatis整合
- 匈牙利命名规则
EDITOR=emacsclient -c
in zsh; I had no idea about this difference between zsh and Bash. – DGrady Jan 13 '16 at 0:08