Last active
November 1, 2019 17:27
-
-
Save VonHeikemen/93db9290a3e7a166df514cfc6e3423f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* compile: gcc -std=c99 -Wall `pkg-config --cflags --libs libnotify` -lnotify cmus-notify.c -o cmus-notify | |
* | |
* test case: cmus-notify status playing file path title hola artist qace album ok | |
* | |
* installation: | |
* - Set the status_display_program variable in cmus | |
* :set status_display_program=/path-to/cmus-notify | |
* | |
* - Save the changes using | |
* :save | |
*/ | |
#include<string.h> | |
#include<libnotify/notify.h> | |
#include<libgen.h> | |
int main(int argc, char *argv[]) { | |
/* check status */ | |
if(strcmp(argv[2], "playing")) { | |
return 0; | |
} | |
char title[200] = ""; | |
char message[500] = "<b>Artist:</b> Unknown"; | |
/* Process arguments */ | |
for(int i = 3; i < argc; i+=2) { | |
if( strcmp(argv[i], "file") == 0 ) { | |
strcpy(title, basename(argv[i + 1])); | |
} | |
if( strcmp(argv[i], "title") == 0 && argv[i + 1][0] != '\0') { | |
strcpy(title, argv[i + 1]); | |
} | |
else if( strcmp(argv[i], "artist") == 0 && argv[i + 1][0] != '\0' ) { | |
strcpy(message, "<b>Artist:</b> "); | |
strcat(message, argv[i + 1]); | |
} | |
else if( strcmp(argv[i], "album") == 0 && argv[i + 1][0] != '\0') { | |
strcat(message, "\n<b>Album:</b> "); | |
strcat(message, argv[i + 1]); | |
} | |
} | |
/* Show notification */ | |
NotifyNotification *notif; | |
notify_init("cmus-notify"); | |
notif = notify_notification_new(title, message, NULL); | |
notify_notification_show(notif, NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment