1

I switched to zsh for my daily usage recently. One problem that I come across is that how I can autostart some background command line executable(for example, fetchmail -d 1800). When I add the line into ~/.zprofile or ~/.zshrc, everything goes fine until I open another zsh process instance(in fact, I am using tmux so it happens frequently), fetchmail complains that

  fetchmail: can't accept options while a background fetchmail is running.

I thought that ~/.zprofile might only be executed once, but It seems that I was wrong. So how can I handle it properly?

Thanks.

4

2 回答 2

2

Edit: Better than original idea (from comment below):

ps -C fetchmail >/dev/null || fetchmail -d 1800

Fixed original idea:

How about checking if there is process in background already running and running fetchmail only if it isn't:

[ -z `ps aux | grep "fetchmail" | grep -v "grep"` ] && fetchmail -d 1800
于 2013-03-30T14:05:52.760 回答
2

Why do you need to start it in zsh configuration file? All or almost all of window managers and desktop environments support running commands at startup. For example, when using fluxbox you can just add this startup line into $HOME/.fluxbox/startup.

Note: .zprofile is read each time somebody starts a login shell. .zshrc is read each time somebody starts interactive shell. .zshenv is read each time somebody starts a shell (no matter which). (Unless explicitly turned off by command-line arguments.) There is really no configuration file which is read only once.

于 2013-03-30T14:37:58.733 回答