1

I have the following status-right:

set -g status-right "#{prefix_highlight}[wifi:#[fg=brightred]#(wifi_status)#[fg=yellow]|#[fg=brightgreen]#{cpu_icon}#[fg=yellow]:#{cpu_percentage}|#{battery_icon}:#{battery_percentage}:#{battery_remain}] %a %h-%d %H:%M:%S#[default]"

and in it the custom shell-command wifi_status.

which runs a function(wifi_quality) that gets the wifi status and then displays it using spark.

This was working when I had the wifi_status file in /usr/local/bin but I wanted it in my version control repo for my dotfiles, so I moved it to a bin folder in my .zsh folder and added the folder to my path using $HOME/.zsh/bin. I can use the command in the shell terminal (even in tmux) and it displays the correct output:

▁▃▅█

But it won't display in the tmux status bar any more.

What's going on?

It's folder in $PATH, config was reloaded, it works in terminal, the file has been set to be executable, I don't get it, why is it now not working?

Since it was asked:

I start tmux by typing it into my terminal (tmux new).

My OS is OSX.

I'm running xterm2.

My login shell is ZSH with Oh-My-Zsh framework.

My dotfiles are located here.

Doing the following in tmux command line (prefix)

set-environment PATH $PATH

sets the PATH variable and it shows up when doing show-environment.

Copy + pasting wifi_status back to the /usr/local/bin folder also hasn't fixed the issue (even with a restart of tmux).

Writing the full path to script doesn't help either.

I solved the problem, For some reason my custom functions file wasn't being sourced properly and as a result it couldn't execute. Moving the function into the file solved that and now it's working.

guntbert
  • 1,637
Thermatix
  • 361
  • 4
  • 15
  • Where are you setting PATH? You say that you “added the folder to my path using $HOME/.zsh/bin, but since this isn't a standard configuration file, if it's being loaded at all, it's being loaded from a standard configuration file. Which one? I suspect that you're setting PATH only in your interactive zsh sessions and not in tmux. You need to post enough information about your configuration files to reproduce the problem. – Gilles 'SO- stop being evil' Aug 02 '16 at 23:03

1 Answers1

3

Looking at your configuration, you set several environment variables in .zshrc, including PATH. Don't do this. The file .zshrc is read when you start an interactive shell, so the variables that it sets will only be available in programs started from an interactive shell. They aren't available in programs that are started in other ways, in particular from a GUI menu.

You didn't say how you start tmux. If you start it without going through an interactive shell (for example from a login-time file, or directly inside a GUI terminal rather than by typing tmux at an interactive prompt), then those environment variables aren't set in the tmux process.

Move your environment variable definitions to a file that's executed at login time. Which file is executed depends on your login shell, and for GUI logins it depends on how your system has set up session startup, which depends on both the distribution and the display manager. Most setups run shell code from ~/.profile on login, so put your environment variable definitions there.

If your login shell is bash, make sure that you either don't have a ~/.bash_profile or that it contains the following two lines and nothing more:

. ~/.profile
if [[ $- = *i* ]]; then . ~/.bashrc; fi

If your login shell is zsh, make sure that your ~/.zprofile contains the following line:

emulate sh -c '. ~/.profile'

Alternatively, on most systems, you can define environment variables in ~/.pam_environment. Note that this file has a simple VARIABLE=VALUE syntax, without quotes, $ expansion, etc.

For more details, see What's the best distro/shell-agnostic way to set environment variables?

  • I thought my .zshrc was was executed when it's a login shell? And I thought Exporting the $path was enough to get the value into child shells? As for setting ENV variables, that's always been there. – Thermatix Aug 03 '16 at 07:53
  • @Thermatix .zshrc is only executed by interactive shells, not by non-interactive login shells. (Background: http://unix.stackexchange.com/questions/a/46856). Exporting PATH sets the value for child processes, but in your scenario tmux is evidently not a child of an interactive shell (since, experimentally, it didn't inherit from the value of PATH that you set in interactive shells). – Gilles 'SO- stop being evil' Aug 03 '16 at 08:24
  • Ok, Added a .zprofile file and a .profile and still, no dice. – Thermatix Aug 03 '16 at 08:40
  • @Thermatix Are you sure you started a new tmux process after logging in, rather than reusing an existing session? You can use tmux show-environment (see the manual for options) to check tmux's environment variables. – Gilles 'SO- stop being evil' Aug 03 '16 at 08:51
  • Doesn't make a difference, still not showing the correct path variable in tmux envs – Thermatix Aug 03 '16 at 10:01
  • @Thermatix Then you didn't set up your login scripts correctly. .profile works on most setups; if it isn't working for you, either you have an unusual setup or you made a mistake somewhere. Ask a new question where you explain exactly what distribution you have and how you log in (GUI or text mode? What is your login shell?), and copy-paste the content of your dot files (.profile, .zprofile, etc.). – Gilles 'SO- stop being evil' Aug 03 '16 at 10:05