I have a fresh mac in front of me, I installed homebrew (just fine), and oh my zsh (just fine).
I'm trying to install autojump which is a intelligent database of directories. For example, you can 'jump' to ~/Documents with j doc in terminal.
I did this
brew install autojump
I already have my .zshrc that looks fine I think. I added the line into it that it said:
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
When I start iterm2 I get the following warning:
/usr/local/Cellar/autojump/21.3.0/etc/autojump.bash:13: command not found: complete
/usr/local/Cellar/autojump/21.3.0/etc/autojump.bash:55: = not found
I have used brew to install other things, and I can run autojump -s successfully so I know it is seeing the $path. I don't know what else could be wrong though, as this is all a fresh install.
In your .zshrc, you must source autojump.zsh, not autojump.bash
(I do not know where it will be located on a Mac, but it will be in same folder as autojump.bash).
On Ubuntu, here is what you need to append at the end of your .zshrc:
source /usr/share/autojump/autojump.zsh
To fix the problem, you should update the line:
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
to say:
[[ -s `brew --prefix`/etc/autojump.zsh ]] && . `brew --prefix`/etc/autojump.zsh
i.e. use the .zsh version of the autojump script. That fixed it for me.
That file has no Shebang. This means that it is probably getting interpreted by Zsh.
This is a problem because complete is a Bash builtin.
Perhaps this can be a fix for you, or maybe
[[ -s `brew --prefix`/etc/autojump.sh ]] && bash `brew --prefix`/etc/autojump.sh
In my case, comment out
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
solved the issue.
You need to add
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
to your ~/.bash_profile. Homebrew tells you this when you install but I didn't notice it the first time and came to this webpage as a result.
In my case, I solve this issue adding :
autoload bashcompinit && bashcompinit
Before the first complete command.
I've used this link : Fixed! az.completion:10: command not found: complete
If you are mac user using .zsh
just add the following to your .zsrc file
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
for more info refer to link : https://github.com/eddiezane/lunchy/issues/57
Related
SO...
I have created some scripts to help configure my shell, but I am having an issue with nvm. My script looks like...
#!/bin/zsh
set -Eeuo pipefail
echo 'Installing nvm'
touch $HOME/.zshrc
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | zsh
echo 'Setting default'
echo 'stable' > $HOME/.nvmrc
echo 'Installing default'
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install
nvm use
...but I am getting...
N/A: version "stable -> N/A" is not yet installed.
You need to run "nvm install stable" to install it before using it.
...but when I run nvm install on my terminal, it works as expected. I tried wrapping nvm install with eval(), $(), but nothing seems to work, what am I missing? Any help is much appreciated!
Answer provided by #l3l_aze!
set -E at the top of the shell script was the culprit, so I changed my script to be...
#!/bin/zsh
set -euxo pipefail
...and it works!
My goal is to execute two commands in a specific folder as ubuntu from outside of it's lxc container.
I've tried a couple of things but I figured this example is the closest I have to working.
If I run
root#host$ lxc exec my-containter -- sudo --login --user ubuntu eval "cd /home/ubuntu/mydir && pwd && whoami && env && npm install && echo done"
I get an npm install error that can't find some module, but it looks like I'm the right user
However if I manually do it as two steps it does work... but I'm trying to put this in a bash script, so that I can keep doing operations on the host, so I think I need it as one.
root#host$ lxc exec my-containter -- sudo --login --user ubuntu
ubuntu#my-container$ eval "cd /home/ubuntu/mydir && pwd && whoami && env && npm install && echo done";
I discovered that my PATH environment variable is different in these two situations, the one that is failing is missing a specific path for nvm/npm. I tried exporting it during the eval command, but it seems like the resources available to me have already been found? What could I do to make the PATH variable populate the same way in the single line scenario?
PATH from 1-line (non-interactive)
PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/snap/bin
PATH from 2-lines (interactive)
PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/home/ubuntu/.nvm/versions/node/v8.9.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
I've also noticed this nvm code at the bottom on my .bashrc file. From what I've read it sounds like the .bashrc file only gets executed in interactive mode.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
The below command should do the job for you
lxc exec my-containter -- sudo --login --user ubuntu bash -ilc "cd /home/ubuntu/mydir && pwd && whoami && npm install && echo done"
The .bashrc file has below at the top
case $- in
*i*) ;;
*) return;;
This code prevents the rest of the part of .bashrc to be executed in case of a non-interactive bash. So to make it interactive you should add the -i flag
I'm getting the following build error when compiling my react-native project in Xcode env: node: No such file or directory
Not sure whats causing it?
Node v8.9.4
React-Native v0.50.4
NPM v5.6.0
And I'm using nvm
if you are using nvm do
sudo ln -s "$(which node)" /usr/local/bin/node
this will link current nvm to your usr local and next time Xcode will find the correct node path and version
Xcode have some issues finding node from nvm, try this inside the script that throws the error:
# Setup nvm and set node
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
$NODE_BINARY ../node_modules/#sentry/cli/bin/sentry-cli upload-dsym
Here is one of the solutions for this error if you're using nvm and sentry: https://docs.sentry.io/clients/react-native/manual-setup/#using-node-with-nvm
In my case, this was related to an old sentry configuration and the fact that I use nvm.
Following https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/
you should be able to execute ln -s $(which node) /usr/local/bin/node and get it fixed
Add this at the top of the script that's failing (in Project -> build phases):
. ~/.nvm/nvm.sh
The solution I used documented here, was to create a script at /usr/local/bin/node that calls nvm
#!/usr/bin/env sh
# Use the version of node specified in .nvmrc to run the supplied command
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm
nvm_rc_version > /dev/null 2> /dev/null
HAS_NVM_RC=$?
if [[ "$HAS_NVM_RC" == "0" ]] ; then
nvm run $*
else
nvm run default $*
fi
exit $?
I'm looking for a proper way to check if a command does not exist. I've read through Check if a program exists from a Bash script. So far I came up with:
command_exists () {
command -v $1 >/dev/null 2>&1;
}
if command_exists aws; then
echo # null
else
brew install awscli
fi
There has to be a way to only have one if clause like:
if ! command_exists aws; then
brew install awscli
fi
update: nevermind, above solution works.
I have a similar function defined and there’s no reason why your snippet of shell code shouldn’t work.
if ! command_exists aws; then
brew install awscli
fi
If you prefer, you can shorten this like so:
command_exists aws || brew install awscli
I installed rvm using commands which by convention should return rvm as a function
1) bash < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
2) echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
3) source .bash_profile
4) type rvm | head -1
should return ("rvm is a function") // and it returned, rails was perfectly fine yesterday.
It worked perfectly yesterday, but now today when I am checking out rails. Its saying rails is not installed.
type rvm | head -1
returns "RVM is Hashed".
Here is something that i got from official site, but i dont know next I should do.
So the question is:
What should be done to get the rvm installed in a function mode and not binary mode?
One possible reason might be that RVM is not being accessible from .bash_profile file so try out using .bashrc file instead of .bash_profile.
Copy and paste following commands into the terminal
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
source ~/.bashrc
Hope it works for you. worked for me cheers !!
===== Edit =====
The following should work in all cases :
curl -L https://get.rvm.io | bash -s stable
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
You should use a login shell in console you can test it by issuing:
$SHELL -l
it is possible to configure your terminal to use a login shell:
https://rvm.io/integration/gnome-terminal/
https://rvm.io/workflow/screen/
for other terminal emulators you need to read respective manual