zsh composer无法在Mac终端上打开输入文件

时间:2019-04-03 16:27:18

标签: php macos composer-php

我是php新手,只需从tutorial的Mac终端上安装composer。

我的终端模拟器是iterm2,它安装了oh-my-zsh。当我键入此命令时:

curl -sS https://getcomposer.org/installer | php

显示:

  

Composer(版本1.8.4)已成功安装到:/Users/lutfiyanra/composer.phar   使用它:php composer.phar

我认为我必须配置〜/ .zshrc并添加命令:

alias composer="php /usr/local/bin/composer.phar"

因此,我添加该命令并保存后,使用以下命令重新加载它:source ~/.zshrc

但是,当我键入:composer versioncomposer 它显示了

  

无法打开输入文件:/Users/lutfiyanra/.composer/composer.phar

以下是我的.bash_profile

source ~/.profile
# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

export PATH=/usr/local/bin:$PATH
export PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.3.1/bin:$PATH
#alias composer="php /usr/local/bin/composer.phar"

和我的.zshrc

# 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="/Users/lutfiyanra/.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/robbyrussell/oh-my-zsh/wiki/Themes
POWERLEVEL9K_MODE='awesome-fontconfig'
ZSH_THEME="powerlevel9k/powerlevel9k"


# 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 ~/.oh-my-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 the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# 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.
# 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 ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
zsh-syntax-highlighting
zsh-autosuggestions
)

# source $ZSH/oh-my-zsh.sh

# User configuration
PATH="$HOME/anaconda3/bin:$PATH"

# 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"
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# 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"
# Customise the Powerlevel9k prompts

alias "composer"="php ~/.composer/composer.phar"

prompt_zsh_showStatus () {
  state=`osascript -e 'tell application "Spotify" to player state as string'`;
  if [ $state = "playing" ]; then
    artist=`osascript -e 'tell application "Spotify" to artist of current track as string'`;
    track=`osascript -e 'tell application "Spotify" to name of current track as string'`;

    echo -n "$artist - $track";
  fi
}

# POWERLEVEL9K_STATUS_BACKGROUND="black"
# POWERLEVEL9K_STATUS_FOREGROUND="blue"
POWERLEVEL9K_BATTERY_CHARGING='yellow'
POWERLEVEL9K_BATTERY_CHARGED='green'
POWERLEVEL9K_BATTERY_DISCONNECTED='$DEFAULT_COLOR'
POWERLEVEL9K_BATTERY_LOW_THRESHOLD='10'
POWERLEVEL9K_BATTERY_LOW_COLOR='red'
POWERLEVEL9K_BATTERY_ICON='\uf1e6'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_freecodecamp battery dir vcs)
POWERLEVEL9K_PROMPT_ON_NEWLINE=true #buat ngetik perintah dibawah prompt kiri
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="↱"
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="↳\uF460\uF460\uF460 "
# POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(zsh_showStatus)
POWERLEVEL9K_TIME_BACKGROUND="black"
POWERLEVEL9K_TIME_FOREGROUND="blue"
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M}"
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status time zsh_showStatus)
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
# Add the custom Medium M icon prompt segment
POWERLEVEL9K_CUSTOM_MEDIUM="echo -n $'\uf296' lutfiyanrzmd"
POWERLEVEL9K_CUSTOM_MEDIUM_FOREGROUND="blue"
POWERLEVEL9K_CUSTOM_MEDIUM_BACKGROUND="black"
# Add the custom freeCodeCamp prompt segment
POWERLEVEL9K_CUSTOM_FREECODECAMP="echo -n $'\uf408' lutfiyanra"
POWERLEVEL9K_CUSTOM_FREECODECAMP_FOREGROUND="blue"
POWERLEVEL9K_CUSTOM_FREECODECAMP_BACKGROUND="black"
# Load Nerd Fonts with Powerlevel9k theme for Zsh
POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme

# Set a color for iTerm2 tab title background using rgb values
function title_background_color {
  echo -ne "\033]6;1;bg;red;brightness;$ITERM2_TITLE_BACKGROUND_RED\a"
  echo -ne "\033]6;1;bg;green;brightness;$ITERM2_TITLE_BACKGROUND_GREEN\a"
  echo -ne "\033]6;1;bg;blue;brightness;$ITERM2_TITLE_BACKGROUND_BLUE\a"
}
ITERM2_TITLE_BACKGROUND_RED="18"
ITERM2_TITLE_BACKGROUND_GREEN="26"
ITERM2_TITLE_BACKGROUND_BLUE="33"
title_background_color
# Set iTerm2 tab title text
function title_text {
    echo -ne "\033]0;"$*"\007"
}
title_text Katanya Programmer

source /Users/lutfiyanra/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# prompt_zsh_showStatus () {
#   state=`osascript -e 'tell application "Spotify" to player state as string'`;
#   if [ $state = "playing" ]; then
#     artist=`osascript -e 'tell application "Spotify" to artist of current track as string'`;
#     track=`osascript -e 'tell application "Spotify" to name of current track as string'`;

#     echo -n "$artist - $track";
#   fi
# }

可能有什么问题吗?

1 个答案:

答案 0 :(得分:0)

  

Composer(版本1.8.4)已成功安装到:/Users/lutfiyanra/composer.phar使用它:php composer.phar

据说路径是/Users/lutfiyanra/composer.phar

您需要使用

作为别名

php /Users/lutfiyanra/composer.phar

代替php /usr/local/bin/composer.phar

似乎您错过了所遵循的安装指南中的命令sudo mv composer.phar /usr/local/bin/。如果运行此命令,则别名正确。如果这不起作用,您可以尝试使用别名:

alias composer="php ~/.composer/composer.phar"

代替

alias "composer"="php ~/.composer/composer.phar"

此外,错误消息是:

  

无法打开输入文件:/Users/lutfiyanra/.composer/composer.phar

在这里,它正在 .composer 目录中搜索 composer.php 文件,该文件的路径不正确。

安装作曲家的替代方法: 一种更简便的方法是使用自制软件在MacOS中安装作曲家和任何其他程序。我还没有安装,可以从这里安装Homebrew:https://brew.sh/

然后,您可以安装composer或任何其他已注册的软件包,如下所示:

brew install composer

相关问题