oh-my-zsh config file not loading - zsh

I am trying to get ZSH config working correctly on Mac OSX. I installed it using curl: curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh. Then I modified my zshrc file to fit my needs. It works only after I run source ~/.zshrc. But then if I come back and open a new tab or new terminal I have to do source ~/.zshrc to get the config settings to work again. Has anybody ran into this issue? I believe there is a way to make it so I don't have to do source ~/.zshrc with every new tab.

I figured this out. It was due to my config file. The part of the zsh config that wasn't loading needed to be moved down after the plugins load. After moving that it all worked as expected.

If you have themes like Powerlevel9k installed for your zsh shell then source the oh-my-zsh config file after the theme variable assignments in your .zshrc file like shown below.
Eg:
........
........
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=('status' 'load' 'ram_joined' 'time')
# source oh-my-zsh config
source $ZSH/oh-my-zsh.sh

Not the ideal solution but solves the issue:
Terminal -> Preferences -> Profiles -> Shells -> Startup
Check the box that says "Run command" and in the input box run
source ~/.zsh/.zshrc
This will be executed when you open a new terminal window / tab.

My final solution was to go to Terminal --> Preferences --> General --> Shells open with --> Command (complete path), and set it to /bin/zsh (or your path to zsh), and then set both New windows/tabs open with to "Same profile". It works fine for me.
My initial attempt was to go to Terminal --> Preferences --> Profiles, and in my default profile's "shell" tab's Startup section, I set it to run command "source ~/.zshrc". This also solved the problem of /.zshrc not loading, but it seemed tedious to see that command show on every terminal tab/window.

I had a similar problem. I found that I had long ago changed my Terminal preferences to run tcsh instead of the default login shell. Took me forever to figure this out!

Related

What is the best way to set up zsh with oh-my-zsh, powerlevel10k and nvm?

I'm using zsh on Linux with OhMyZsh and the powerlevel10k theme. I'm also using nvm since I have to switch node versions for different projects.
I'd like to achieve that zsh automatically uses the node version set in the .nvmrc file (if one exists). That should be triggered when changing into a directory that has a .nvmrc file, but also when opening a terminal (e.g. opening a vscode project, the internal terminal should be set to the respective node version).
I tried the ohmyzsh nvm plugin (with export NVM_LAZY=true and export NVM_AUTOLOAD=true), but that causes this behavior with powerlevel10k when opening a terminal:
[WARNING]: Console output during zsh initialization detected.
When using Powerlevel10k with instant prompt, console output during zsh
initialization may indicate issues.
...
The zsh-nvm plugin works better (with export NVM_LAZY_LOAD=true and export NVM_AUTO_USE=true). It automatically changes the version when changing directories, however not when opening the terminal.
I achieved that by adding this line to my .zshrc file:
[ -s "./.nvmrc" ] && nvm use > /dev/null 2>&1
That does not cause the above mentioned powerlevel10k issue, however the terminal changes the look (applying the powerlevel10k theme) after a couple seconds. I guess that is because of loading nvm right away (and not lazy loading it anymore). If I open the terminal in a directory without .npmrc, it opens fast and with the p10k theme right away.
I can live with this setup, but it is still not ideal and feels hacky. Is there a better way to do it?
Just for reference, there is also this issue on the zsh-nvm github

Can't open input file: zsh

I'm trying to execute a .zsh script on Macos big sur and it's not letting me.
Whenever I run the .zsh in terminal, it says "/bin/zsh: can't open input file: file-name.zsh"
I already did brew install zsh prior to this so I'm a bit confused.
Any help would be greatly appreciated. Thanks!
In macOS Transparency Consent and Control (TCC) restricts access to "personal" data, including anything in a user's Desktop folder and outputs a /bin/zsh: can't open input file error message if you try to disobey this rule. Try moving file-name.zsh to a different folder, and if moving file-name.zsh to another folder doesn't help refer to file-name.zsh by using the full path to file-name.zsh.
Figured it out for ZSH on Mac! To get scripts to run from any relative directory, you can first append the rest of the path to the front of the script name and then run as usual:
BASEDIR=$(dirname "$0")
echo "Script location: ${BASEDIR}"
cd "$(dirname "$0")"
$BASEDIR/<script_name>.command
This is currently working for me on macOS Monterey.
(Copied from comment to Karel's answer about macOS ZSH + TCC policy)

Why do you need to source .zshrc for every new shell in iTerm?

I've used Iterm2 with zsh everyday for the past 3 years, but I got a new computer and had to set it up again. The problem is that when I run ~/.zshrc it works fine, but I have to do it on every new terminal window I open. Not a good experience.
I noticed that I don't have any bashrc, bash_profile, or profile (dot)files on my new machine.
Here's the code in ~/.zshrc:
export ZSH=/Users/healy/.oh-my-zsh
plugins=(
git
)
ZSH_THEME="agnoster"
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
DEFAULT_USER=healy
Again, it works perfectly (and as expected), but only after I run the source command, and that shouldn't be the case.
Make sure your export/source are added after the plugins in your zshrc, as stated in this post:
oh-my-zsh config file not loading
On starting a new shell just run the command source ~/.zshrc by configuring in the
Preferences -> Profiles -> Select Default Profile(default profile will be starred) -> General -> Command -> Select Login Shell -> Send text at start:
Enter the value source ~/.zshrc.
You may add source ~/.zshrc; clear in case you need to clear the screen contents after executing the command.
I had the same issue and changing the Shells Open with option fixed this for me.
To get here:
Open Preferences for Terminal
Select the General Tab
Change Sells open with from Default login shell to Command (complete path) with the /bin/zsh in the input box.
Screeshot:
On 11.2.1 with Terminal 2.11, assuming you have already created .zshrc in your home directory, launch Terminal and select Terminal >> Preferences >> Profiles >> Shell
Under "Startup" check "Run command:" and input source ~/.zshrc
In my case, oh-my-zsh is not loaded because the line was comment out.
# IT'S WRONG! NEED TO UNCOMMENT
# export ZSH=/Users/$(whoami)/.oh-my-zsh
Though this question is not due to the same "comment out" obviously, I came to a conclusion that, if you need to source ~/.zshrc every time opening a shell instance, there should be some issue with your .zshrc,
and check oh-my-zsh and antigen(maybe) work fine.
for me,It works like this.
Profiles 》Open Profiles 》Select “Edit Profiles” 》Profiles 》General
and put "source ~/.zsh" into Send text at start textfield.

Rstudio Git bash pop-up every time

I have integrated the git version control to an existing project in Rstudio(Windows). After that for every change I make in the Rmd file, a pop up is coming. I could see that it is a git bash executing on every command I have added in the file. I do not have more details on this.
Actually solved it myself just now with the help of this info:
https://stat545-ubc.github.io/git03_rstudio-meet-git.html
WARNING: On Windows, do NOT use C:/Program Files (x86)/Git/cmd/git.exe. The difference between the good and bad paths is bin vs. cmd.
My Rstudio-version was setting the cmd/git.exe as default.
If you change that to bin/git.exe my problem was solved...

How can I use oh-my-zsh with PHPStorm?

I just got oh-my-zsh (a very good command line utility) and would like to utilize this within the PHPStorm terminal. How can I accomplish this?
As oh-my-zsh is more of an extended zsh-configuration, it should be sufficient to just tell PHPStorm to use zsh as Shell. This can be done in the Settings dialog (Menu File->Settings) under section Project Settings->Terminal. Just change Shell Path to the path of zsh (can be found out with type zsh in a terminal).
To affect every (new) project you may have to repeat this in File->Default Settigs
For once and all setup:
Set it in Preferences->Tools->Terminal and Shell Path = /bin/zsh
restart your PhpStorm and thats it.

Resources