Alias in bash_profile not working after MacOS Catalina upgrade - bash

I just upgraded to macOS Catalina (10.15.2) from macOS Mojave. I have used aliases in my ~/.bash_profile and it stopped working after Catalina upgrade.
alias mci='mvn clean install'
alias mcit='mvn clean install -Dmaven.test.skip=true'
alias mcid='mvn clean install -Dmaven.surefire.debug'
What should I do?

What kind of shell are you using? bash? zsh?
Have you changed anything else in your:
.profile
.bash_profile
.bashrc
If you could add your files here maybe there is a "bug" in the beginning for the files?
Seems catalina has changed the default shell to zsh. So maybe moving your
.bashrc is now .zshrc and .bash_profile is now .zprofile will fix this.

and to go back to bash instead
you can list the shells
cat /etc/shells
in the terminal, to update your account to use bash run chsh -s /bin/bash. enter password if need be and shut it down and re-open

Related

How to completely remove zsh (oh-my-zsh) from Mac M1 (MacOS Monterey)

I have tried to run:
uninstall_oh_my_zsh
but i get a message stating that: -bash: uninstall_oh_my_zsh: command not found
Other commands i have tried are:
chmod +x ~/.oh-my-zsh/tools/uninstall.sh
I get a response stating that: No such file or directory
sh ~/.oh-my-zsh/tools/uninstall.sh
Ran:
chsh -s /bin/bash
To change default terminal from /bin/zsh to /bin/bash
I also tried:
rm -rf ~/.oh-my-zsh
rm ~/.zshrc
cp ~/.zshrc.pre-oh-my-zsh ~/.zshrc
source ~/.zshrc
None of them have worked thus far, when i open my terminal. I get a message stating that:
The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh
You don't have Oh My Zsh (a set of configuration files for zsh and a way to manage them) installed in the first place.
The warning is coming from /bin/bash itself; it's hard-coded into the executable supplied by macOS.
$ strings /bin/bash | grep "default interactive shell"
The default interactive shell is now zsh.
Though they don't say so, I suspect the warning is there because they plan to remove bash from future versions of macOS entirely. They stopped providing newer versions of bash years ago.
Your default shell is already /bin/bash; the warning is recommending that you switch to /bin/zsh.
You can continue to use bash, though I recommend installing a newer version (3.2 is old) using something like Homebrew, then changing your login shell to the new version.
However, unless you are really committed to using bash, I suggest given zsh a try.

Show Git Branch Name in Terminal - MacOS Catalina - missing zsh files

I have a fresh MacOS Catalina 10.15.6 and I'm following the steps on this link show git branch name in terminal macos so I can display the branch name on my terminal whenever I cd in a git repository.
I'm in my home directory so when I run ls -la, I can't see any of the following files
.zshrc, .bashrc, .bash_profile, .zprofile
The only relevant files showing on the list are .bash_history and .zsh_history.
Are these located on a different path or am I missing any step in the process?
MACOS Instructions- execute the following commands in your terminal:
cd
nano .zshrc
copy and paste this lines of code:
autoload -Uz vcs_info
precmd() {vcs_info}
zstyle ':vcs_info:git:*' formats '(%b)'
setopt PROMPT_SUBST
PROMPT='%n> ${PWD/#$HOME/~} ${vcs_info_msg_0_}%%'
CTRL+o ENTER to save and CTRL+x to exit
source .zshrc
and that's it. Please share your configuration!
Simplest answer, install Oh My ZSH
Trust me, you can't do a better job customizing your own .zshrc file.
Just go here: https://ohmyz.sh/#install
Run this command in your terminal:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Voila, you got pretty terminal outputs
Following this answer on SuperUser StackExchange, I would assume that you have to create .zshrc, .bashrc, etc., on your own. As far as I can tell, you just need a .zshrc for what you are doing. Then you can continue with the setup from the tutorial.

How to get zsh to start automatically in Mac iTerm?

I am sure this is a configuration issue, but I cannot find what is wrong. I have zsh and oh-my-zsh installed on my new Mac view homebrew.
When I start terminal it doesn't load zhs theme or autocomplete unless I run zsh command to start it. After that all works fine.
However, all the aliases I setup in .zshrc file works fine without running zsh and there is no .bashrc file in the machine.
How can I make zsh to start automatically when I open iTerm.
You can change your default shell to zsh.
Using the below command, and type your password
chsh -s /bin/zsh
If you want to use brew managed zsh, you should append /usr/local/bin/zsh to the end of file /etc/shells, then run command chsh -s /usr/local/bin/zsh.
Then reopen your iTerm2, done.

I have to type export PATH=~/anaconda/bin:"$PATH" everytime I rerun the terminal

I have installed the Anaconda for Mac, but there is something wrong with me:
when I type the commandwhich conda or which ipython, I get conda not found and ipython not find
Then I find this command export PATH=~/anaconda/bin:"$PATH" works for me. It solves the problem above, but everytime I rerun the terminal the problem is still there, I have to type it again.
so I want to find a way to solve the problem fundamentally
I have tried to add it into the ~/.bashrc, ~/.profile, ~/.bash_profile, but these don't work for me.
Try this in .bash_profile
export PATH="$HOME/anaconda/bin:$PATH"
Then try launching a new terminal and running:
echo $PATH
The output should start with /anaconda/bin:
If that still doesn't work... A work around might be to invoke bash after running terminal i.e. type "bash". Which should cause bash to launch with .bash_profile
I run on MacOs Catalina 10.15 and this did the trick for me:
shell is zsh !
$ source /Users/myprofilename/anaconda3/bin/activate
then
$ conda init zsh
the new anaconda documentation also highlights this:
Make sure you're not using ZShell or another form of a shell. If the case you'd have to add the path to your respective shell file, e.g .zshrc.
sudo xed /etc/environment
after open this archive add :/home/youruser/anaconda3/bin
If you're using ZShell follow the steps below:
In your terminal type open ~/.zshrc
Add the following to the file export PATH=/opt/homebrew/bin:$PATH
Save your file and then run the following command source ~/.zshrc
Please note that the homebrew path on Apple silicon is /opt/homebrew/bin

Is there anything in Zsh like .bash_profile?

Everytime I open the terminal, I have to source .bash_profile to enable the $JAVA_HOME or other variables.
Yes, it's called ~/.zshenv.
Here's how I have $JAVA_HOME set in ~/.zshenv:
export JAVA_HOME="$(/usr/libexec/java_home)"
Keep in mind, however, that zsh is not bash, so just 'cause you have to source your .bash_profile every time you open a terminal does not mean that you have to do that with zsh. With zsh, I only have to re-source my ~/.zshenv when I make changes to it, and then only for terminals which are already open: new terminals should have already sourced my new and improved ~/.zshenv.
NOTE
I often find it helpful, when trying to determine which of my zsh startup files I should place things in to consult zsh startup files.
A newer version of the documentation for startup files can be found here.
I know this is an old question, but I recently upgraded MacOs to Catalina which changed the default shell from bash to zsh.
I ended up doing this:
echo source ~/.bash_profile > ~/.zshenv && source ~/.zshenv
To have zsh source my original .bash_profile.
Recently, with the upgrade to macOS Catalina, the default shell changed to zsh, which uses ~/.zshrc as the resource file.
We usually had ~/.bash_profile inside user home directory the solution is to simply
Open ~/.bash_profile by running vim ~/.bash_profile
Open ~/.zshrc by running vim ~/.zshrc
Copy the content of ~/.bash_profile into ~/.zshrc
Open a new terminal window and run your previous aliases/scripts, which should work flawlessly.
Other simple alternative to continue using your .bash_profile is add this file to your .zshrc file:
Open your .zhsrc file > vim ~/.zshrc
Add this line to your .zshrc file > source ~/.bash_profile
with this simple solution you can continue adding your .bash_prifile if you like zhs.
Adding .bash_profile
There are five separate profile scripts that get executed (in the order given below) when we launch a zsh shell or close it out.
(1) .zshenv --> This is always sourced first but can be overridden by other
(2).zprofile --> This is equivalent for users coming from ksh experience
(3).zshrc --> This is for all of the interactive customizations of zsh
(4).zlogin --> This executes after first three are done
(5).zlogout --> This is executed when we logout of the zsh shell
it would be advisable to put your stuff in .zshenv or in .zshrc
It is not mandatory to have any one of these files. But if it is there, it will be sourced from and executed in the above order.
In Mac Catalina onwards osx versions, the terminal uses zsh. There is a system-wide profile /etc/zprofile.
cat /etc/zprofile
# System-wide profile for interactive zsh(1) login shells.
# Setup user specific overrides for this in ~/.zprofile. See zshbuiltins(1)
# and zshoptions(1) for more details.
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
it says , if you want to override then create ~/.zprofile.
touch ~/.zprofile.
update: macOS Monterey 12.4
yes - for Zsh, it is the file: .zshrc
add there your parameter.
In Mac Catalina, terminal uses zsh. Instead of having .bash_profile, good to have .zshenv and write your script there.
When you open terminal next every time, scripts inside .zshenv gets executed.
I was running into this issue and I followed Zack and Luke Schoen's answer, but my $PATH didn't look the same as what I had in bash.
This post explains what the different config files do:
https://unix.stackexchange.com/questions/71253/what-should-shouldnt-go-in-zshenv-zshrc-zlogin-zprofile-zlogout
I found that splitting my .bash_profile path exports into .zprofile and my aliases into .zshrc worked best for what I wanted.
I found why Zack and Luke Schoen's answer didn't work for me:
The path exports that I listed in .zshenv were executed first and /usr/libexec/path_helper was executed afterwards,
which prepended the paths listed in /etc/paths.
I found the profile file under /etc/zprofile location. This will be for zsh

Resources