Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/config-example
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#gain_mul = 1.0
#sample_rate = 44100
#audio_pipe = /tmp/mypipe
#selection_command = fuzzel -d

# Format strings
#format_nowplaying_song = %t by %a on %l%r%@%s
Expand Down
7 changes: 7 additions & 0 deletions contrib/pianobar.1
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ Your pandora.com username.
.B volume = 0
Initial volume correction in dB. Usually between -30 and +5.

.TP
.B selection_command = fzf
Use this external command to select stations, songs, or artists. The command
receives newline-separated entries such as " 0) StationName" or " 0) Artist -
Title" via stdin and should return the selected entry verbatim via stdout.
Empty output aborts the selection. For example, `fzf`, `dmenu`, or `fuzzel -d`.

.SH REMOTE CONTROL
.B pianobar
can be controlled through a fifo. You have to create it yourself by executing
Expand Down
49 changes: 7 additions & 42 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,53 +111,18 @@ static bool BarMainGetLoginCredentials (BarSettings_t *settings,
puts ("");
settings->password = strdup (passBuf);
} else {
pid_t chld;
int pipeFd[2];

BarUiMsg (settings, MSG_INFO, "Requesting password from external helper... ");

if (pipe (pipeFd) == -1) {
BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
return false;
}
char *result = BarUiRunExternalCmd (settings, settings->passwordCmd,
NULL, 0);

chld = fork ();
if (chld == 0) {
/* child */
close (pipeFd[0]);
dup2 (pipeFd[1], fileno (stdout));
execl ("/bin/sh", "/bin/sh", "-c", settings->passwordCmd, (char *) NULL);
BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
close (pipeFd[1]);
exit (1);
} else if (chld == -1) {
BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
if (result == NULL) {
BarUiMsg (settings, MSG_NONE, "Error: Exit status non-zero.\n");
return false;
} else {
/* parent */
int status;

close (pipeFd[1]);
memset (passBuf, 0, sizeof (passBuf));
read (pipeFd[0], passBuf, sizeof (passBuf)-1);
close (pipeFd[0]);

/* drop trailing newlines */
ssize_t len = strlen (passBuf)-1;
while (len >= 0 && passBuf[len] == '\n') {
passBuf[len] = '\0';
--len;
}

waitpid (chld, &status, 0);
if (WEXITSTATUS (status) == 0) {
settings->password = strdup (passBuf);
BarUiMsg (settings, MSG_NONE, "Ok.\n");
} else {
BarUiMsg (settings, MSG_NONE, "Error: Exit status %i.\n", WEXITSTATUS (status));
return false;
}
}

settings->password = result;
BarUiMsg (settings, MSG_NONE, "Ok.\n");
} /* end else passwordCmd */
}

Expand Down
3 changes: 3 additions & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->username);
free (settings->password);
free (settings->passwordCmd);
free (settings->selectionCmd);
free (settings->autostartStation);
free (settings->eventCmd);
free (settings->loveIcon);
Expand Down Expand Up @@ -293,6 +294,8 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->password = strdup (val);
} else if (streq ("password_command", key)) {
settings->passwordCmd = strdup (val);
} else if (streq ("selection_command", key)) {
settings->selectionCmd = strdup (val);
} else if (streq ("rpc_host", key)) {
free (settings->rpcHost);
settings->rpcHost = strdup (val);
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef struct {
PianoAudioQuality_t audioQuality;
char *username;
char *password, *passwordCmd;
char *selectionCmd;
char *controlProxy; /* non-american listeners need this */
char *proxy;
char *bindTo;
Expand Down
Loading