Turnipdabeets
Turnipdabeets

Reputation: 6005

Bash Terminal - .profile does not call some functions in terminal

I've had a hard time getting some of my functions in my .profile to work.

I often end up opening the file in my terminal copying the command and then pasting it in the terminal. So, the commands work.

But only about half of the functions work when I type directly in the terminal. The other half give me an error like: -bash:   npm: command not found or -bash: Load: command not found

Specifically two that really bug me are set_registry_alt and reload. I'm unable to access those but I'm able to access set_registry_npm. Is there something I'm missing that is causing inconsistencies in my .profile? Is there a way to make sure I don't some how have hidden characters causing problems?

Here's my code:

    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/$@
}

# 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.

Upvotes: 1

Views: 245

Answers (2)

Turnipdabeets
Turnipdabeets

Reputation: 6005

The answer was two parts:

  1. @barmar pointed out that this error message has a space before npm -bash:   npm: command not found and there was an invisible space that needed to be removed.

  2. Load RVM into a shell session *as a function* was supposed to be a comment so it was missing #.

These two things fixed my .profile

Upvotes: 2

fabreg
fabreg

Reputation: 123

This line is wrong:

Load RVM into a shell session *as a function*

You should remove it.

Upvotes: 0

Related Questions