2017-03-03 50 views
1

我很難讓我的一些功能在我的.profile中工作。Bash終端 - .profile不呼叫終端中的某些功能

我經常最終打開終端中的文件,複製該命令,然後粘貼到終端中。所以,這些命令起作用。

但是,當我直接在終端中鍵入時,只有大約一半的功能起作用。另一半給我一個錯誤,如:-bash:   npm: command not found-bash: Load: command not found

具體來說,兩個真正bug我set_registry_altreload。我無法訪問這些內容,但我可以訪問set_registry_npm。有什麼我錯過了,導致我的.profile不一致嗎?有沒有辦法確保我不知道隱藏的角色如何導致問題?

這裏是我的代碼:

variables=(
    "HTTP_PROXY" 
    "HTTPS_PROXY" 
    "ALL_PROXY" 
    "all_proxy" 
    "https_proxy" 
) 

function reload() { 
    source ~/.profile 
} 

function set_registry_npm { 
    npm config set registry="https://registry.npmjs.org/" 
} 

function set_registry_alt { 
  npm config set registry="link_that_works_but_removed_for_StackOverflow" 
} 

function load_proxy_full { 
    echo -n "Enter Username: " 
    read username 
    echo -n "Enter your Password: " 
    read -s password 
    url=http://${username}:${password}@proxy-change.xxxx.com:8080 

    npm config set https-proxy ${url} 
    npm config set proxy ${url} 

    export HTTP_PROXY=${url} 
    export HTTPS_PROXY=${url} 
    export ALL_PROXY=${url} 
    export all_proxy=${url} 
    export https_proxy=${url} 

    npm config delete registry 
} 

function unload_proxy { 
    unset ${variables[@]} 
    npm config delete https-proxy 
    npm config delete proxy 
} 

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting 
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 

    function parse_git_branch { 
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' 
    } 

    # This allows git autocomplete 
    if [ -f ~/.git-completion.bash ]; then 
     . ~/.git-completion.bash 
    fi 

    # Node Path from Homebrew I believe 
    export NODE_PATH="/usr/local/lib/node_modules:$NODE_PATH" 

    export VISUAL="subl -w" 
    export SVN_EDITOR="subl -w" 
    export GIT_EDITOR="subl -w" 
    export EDITOR="subl -w" 

function desktop { 
    cd /Users/$USER/Desktop/[email protected] 
} 

# Aliases 
    alias l='ls -lah' 

    # Git 
    alias gcl="git clone" 
    alias gst="git status" 
    alias gpl="git pull" 
    alias gp="git push" 
    alias gd="git diff | mate" 
    alias ga="git add" 
    alias gcm="git commit -m" 
    alias gb="git branch" 
    alias gba="git branch -a" 
    alias gcam="git commit -am" 
    alias gbb="git branch -b" 
    alias glol="git log --oneline --decorate --all --graph" 


# Case-Insensitive Auto Completion 
    bind "set completion-ignore-case on" 


    # via homebrew 
    if [ -f `brew --prefix`/etc/bash_completion ]; then 
    . `brew --prefix`/etc/bash_completion 
    fi 

export ANDROID_HOME=~/Library/Android/sdk 
export PATH=${PATH}:${ANDROID_HOME}/tools 
export PATH=${PATH}:${ANDROID_HOME}/platform-tools 

export PATH="$PATH:`yarn global bin`" 

[[ -s "/Users/$USER/.rvm/scripts/rvm" ]] && source "/Users/$USER/.rvm/scripts/rvm" # This loads RVM into a shell session. 
+0

此行'加載RVM成shell會話*的功能*'應該是一個評論。 – Barmar

+0

@Barmar你是對的,它最初是一個評論。我只是刪除它,但這個文件仍然不完全正確。 – Turnipdabeets

+0

'npm:command not found'意味着你沒有安裝Node.js,或者你安裝的目錄不在你的'$ PATH'中。 – Barmar

回答

2

答案是兩個部分:

  1. @barmar指出該錯誤消息具有空間NPM -bash:   npm: command not found之前並且有一個需要被移除的不可見的空間。

  2. Load RVM into a shell session *as a function*本該是一個評論,所以它失蹤#

這兩樣東西固定我的.profile

0

此行是錯誤的:

Load RVM into a shell session *as a function* 

你應該將其刪除。

+0

好的。固定'重新加載',但不是'npm_registry_alt' – Turnipdabeets

+0

我沒有看到'npm_registry_alt'。你的意思是'set_registry_alt'? – Barmar

+0

是'set_registry_alt' – Turnipdabeets