From: Pete Zaitcev Date: Sun, 21 Mar 2010 20:46:03 +0000 (-0600) Subject: bti: suppress prompt if fed from a pipe X-Git-Url: https://git.toastfreeware.priv.at/gregoa/bti.git/commitdiff_plain/0c0fe71fc74e38111138214c2e9a50241a839375?hp=f3a8152f4191dd0cc854c6a5b6267e07f5af239f bti: suppress prompt if fed from a pipe Do not use readline for non-interactive sessions (e.g. those taking input from a pipe or file). This way stray prompts are not shown. Explicit prompts are retained, in case some script expects them. Signed-off-by: Pete Zaitcev Signed-off-by: Greg Kroah-Hartman --- diff --git a/bti.c b/bti.c index 285fdfa..02b8aea 100644 --- a/bti.c +++ b/bti.c @@ -83,6 +83,7 @@ struct session { char *hosturl; char *hostname; int bash; + int interactive; int shrink_urls; int dry_run; int page; @@ -172,8 +173,11 @@ static void session_readline_init(struct session *session) int (*bind_key)(int, void *); void (*insert)(void); - /* default to internal function if we can't find anything */ + /* default to internal function if we can't or won't find anything */ session->readline = get_string; + if (!isatty(0)) + return; + session->interactive = 1; tmp = malloc(strlen(libpath)+1); if (!tmp) @@ -1245,7 +1249,7 @@ int main(int argc, char *argv[], char *envp[]) } if (session->action == ACTION_UPDATE) { - if (session->bash) + if (session->bash || !session->interactive) tweet = get_string_from_stdin(); else tweet = session->readline("tweet: ");