Where does ZSH loads the env variable from - zsh

I am trying to change the ruby version with rbenv, it seems that there is an env variable
RBENV_VERSION=3.0.1
I cannot find where does this comes from, there is no declaration on .zshrc file.
On the .szhenv file I have the following
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Is there any other file that could define this env variable?

It's most likely the eval "$(rbenv init -)" line. That runs rbenv init - and then runs the output as shell commands.
If that doesn't help, you can add setopt xtrace to the start of your .zshenv. This will dump every command the shell runs to stderr, with file names and line numbers. You can then do zsh -il 2>trace.log and search trace.log for RBENV_VERSION.
From the rbenv github page, it looks like you can use rbenv shell <version> to set the version for a shell session, which sets $RBENV_VERSION.

Related

Exported variables from zshrc not available in WebStorm Run Configuration

I set up an NPM_TOKEN in my .zshrc file. When I run yarn start in a terminal my Gatsby app runs fine, but when I create an NPM run configuration in WebStorm for start, it can't find the token:
error An unexpected error occurred: "Failed to replace env in config: ${NPM_TOKEN}".
I actually get the same error when attempting to commit from Webstorm. Works fine in terminal (even the WS terminal)
I have Fig installed, and ohmyzsh, and here is my .zshrc file.
[[ -f "$HOME/.fig/shell/zshrc.pre.zsh" ]] && builtin source
"$HOME/.fig/shell/zshrc.pre.zsh"
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git)
source $ZSH/oh-my-zsh.sh
source ~/.zprofile # loads some custom aliases using "source
.aliases/some_alias_file.zsh" etc
export NPM_TOKEN="my token"
[[ -f "$HOME/.fig/shell/zshrc.post.zsh" ]] && builtin source "$HOME/.fig/shell/zshrc.post.zsh"
export NVM_DIR="$HOME/.nvm"
Is there a way to fix this?
UPDATE: Adding my NPM_TOKEN to .bashrc fixed this. So I guess Webstorm is running bash, or reading that file, instead of zsh and reading its config files? We're slightly over my head at this point. But I would imagine there's a way to configure this?

run zsh command for all files in a folder

I have a models folder that contains multiple sql files for example models/mart/table1.sql, models/mart/table2.sql, models/mart/table3.sql
I run this command manually on the terminal:
dbt run-operation generate_model_yaml --args '{"model_name": "table1"}'
However, instead of running it individually for each table, I want to include it in the Bitbucket pipeline. How can I modify the command such that it runs in a loop? It should be able to extract the tablename (filename) for all files from a specified folder eg (models/mart) and then run the command accordingly by replacing the model_name by the filename each time?
pipelines:
custom:
dbt-run-default:
- step:
name: 'Compile'
image: fishtownanalytics/dbt:1.0.0
script:
- cd dbt_4flow
- dbt deps --profiles-dir ./profiles
I'm not sure I quite understand which parts of the paths you want to pick apart. Does this work?
for file in models/mart/*.sql; do
table=$(basename "$file" .sql)
model=${file%/*}
printf " --args '{\"%s\": \"%s\"}'\n" "$model" "$table"
dbt run-operation generate_model_yaml --args "{\"model_name\": \"$table\"}"
done

How do I use to the zsh 'command' option to execute a the builtin 'source' command?

I am trying to log each time my shell sources a file. I am using zsh, so I went into zshenv and added this function.
source() {
echo "sourcing $1"
command source $1
}
The idea is everytime "source [file]" appears in one of my dotfiles and is executed, it should print the action to terminal first, before actually sourcing the file.
instead i'm getting some errors like this
sourcing /Users/js/.cargo/env
source:2: command not found: source
sourcing /Users/js/.sources/postgres-env.sh
source:2: command not found: source
sourcing /Users/js/.oh-my-zsh/oh-my-zsh.sh
source:2: command not found: source
sourcing /Users/js/.iterm2_shell_integration.zsh
source:2: command not found: source
What is the correct way to use the shell 'command' option with zsh to call source here?
command is intended to specifically invoke external commands. For example if you have an alias or function for git, command git will bypass those.
You're looking for the builtin command to limit command lookup to only builtin commands.
source() {
echo "sourcing $1"
builtin source "$1"
}
For it to work regardless of shell, you could use this instead:
#!/usr/bin/env sh
source() {
echo "sourcing $1"
. "$1"
}
source "$1"

Why tmuxinator zsh complete file is not work?

According to the hint, I download the file
https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.zsh
into /usr/local/share/zsh/site-functions/_tmuxinator(file path), but the autocompletion not work.
Then I source the file like below in ~/.zshrc, it is also not work.
. /usr/local/share/zsh/site-functions/_tmuxinator
My config environments are:
zsh: zsh 5.8 (x86_64-suse-linux-gnu)
tmuxinator: tmuxinator 2.0.1
And I use oh-my-zsh as my zsh environment and rbenv to install tmuxinator.
The fpath environment variable in my system is:
/home/run/.oh-my-zsh/plugins/git /home/run/.oh-my-zsh/functions /home/run/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh//functions/Calendar /usr/share/zsh//functions/Chpwd /usr/share/zsh//functions/Completion /usr/share/zsh//functions/Completion/Base /usr/share/zsh//functions/Completion/Linux /usr/share/zsh//functions/Completion/Unix /usr/share/zsh//functions/Completion/X /usr/share/zsh//functions/Completion/Zsh /usr/share/zsh//functions/Completion/openSUSE /usr/share/zsh//functions/Exceptions /usr/share/zsh//functions/MIME /usr/share/zsh//functions/Math /usr/share/zsh//functions/Misc /usr/share/zsh//functions/Newuser /usr/share/zsh//functions/Prompts /usr/share/zsh//functions/TCP /usr/share/zsh//functions/VCS_Info /usr/share/zsh//functions/VCS_Info/Backends /usr/share/zsh//functions/Zftp /usr/share/zsh//functions/Zle /etc/zsh_completion.d
which includes the directory /usr/local/share/zsh/site-functions.
You may have to force rebuild zcompdump:
rm -f ~/.zcompdump; compinit

Adding directory to PATH through Makefile

I'm having some trouble in exporting the PATH I've modified inside the Makefile into the current Terminal.
I'm trying to add to the PATH, the bin folder inside wherever the Makefile directory is.
Here's the relevant strip of the makefile:
PATH := $(shell pwd)/bin:$(PATH)
install:
mkdir -p ./bin
export PATH
echo $(PATH)
The echo prints it correctly but if I redo the echo in the terminal, the PATH remains the same.
Thanks in advance for the help.
If you're using GNU make, you need to explicitly export the PATH variable to the environment for subprocesses:
export PATH := $(shell pwd)/bin:$(PATH)
install:
mkdir -p ./bin
export PATH
echo $(PATH)
What you are trying to do is not possible. Make is running in another process than the shell in your terminal. Changes to the environment in the make process does not transfer to the shell.
Perhaps you are confusing the effect of the export statement. export does not export the values of the variables from the make process to the shell. Instead, export marks variables so they will be transfered any child processes of make. As far as I know there is no way to change the environment of the parent process (the shell where you started make is the parent process of the make process).
Perhaps this answers will make the concept of exporting variables to child processes a bit clearer.
Perhaps you can rely on the user to do it for you. Note the quoting
install_hint:
#echo "Execute this command at your shell prompt:"
#echo "export PATH=$(shell pwd)/bin:\$$PATH"

Resources