Reputation: 2110
So I have the following snippet:
if [[ ps -p$PPID | grep 'java' == '' ]]; then
ZSH_TMUX_AUTOSTART=true;
fi
which returns the following error:
/home/otis/.zshrc:8: parse error: condition expected: ps
The idea is that if ps -p$PPID | grep 'java'
returns nothing then set ZSH_TMUX_AUTOSTART=true
.
The reason I want to do this is I want to automagically start tmux in my gnome-terminal but not in my intellij terminal if I run this command in gnome it returns nothing and if I run from intellij it returns java
.
So the logic is solid basically if there is nothing returned always start tmux, but I am not that good at shell so any help would be much appreciated.
Cheers.
Upvotes: 3
Views: 1696
Reputation: 255
In your project, under Settings > Tools > Terminal, set Environment variables to INSIDE_EMACS=true
.
Upvotes: 1
Reputation: 308
I realize this is an old thread and the TERMINAL_EMULATOR variable may not have been the same at the time of the original post but I solved this on OSX with the following:
if [ "$TERMINAL_EMULATOR" != "JetBrains-JediTerm"]
then
ZSH_TMUX_AUTOSTART=true
fi
Upvotes: 6
Reputation: 18399
The reason you get an error message is due to the conditional expression ([[ … ]]
) expecting a condition after ps
, which it takes for a string not a command. You have to wrap the command in $(…)
to use its output inside the conditional expression. Alternatively you could just use the exit code of grep
to determine whether "java" has been found, which removes the need for a conditional expression.
if ! ps -p $PPID | grep -q java; then
ZSH_TMUX_AUTOSTART=true;
fi
Note that the the return values of the check are reversed to what you originally intended. Hence the !
to return true
if the exit code would be false
and vise versa. -q
just suppresses the output of grep
.
Upvotes: 5