add: xdg-support

- config file XDG support inspired from #511
- added support to try loading scripts from XDG_DATA_HOME, if not present try
  loading from XDG_CONFIG_HOME, if not present try loading the usual way.
This commit is contained in:
altffour 2021-01-06 17:34:33 +03:00
commit f972d05025
No known key found for this signature in database
GPG key ID: B4ADFA86EDF5CCE9
3 changed files with 45 additions and 15 deletions

View file

@ -390,6 +390,34 @@ char *perl_script_get_path(const char *name)
file = IS_PERL_SCRIPT(name) ? g_strdup(name) :
g_strdup_printf("%s.pl", name);
/* check from %XDG_DATA_HOME% */
path = g_build_filename(g_get_user_data_dir(), "irssi/scripts/", file, NULL);
if (stat(path, &statbuf) != 0) {
g_free(path);
path = g_strdup_printf(SCRIPTDIR"/%s", file);
if (stat(path, &statbuf) != 0) {
g_free(path);
path = NULL;
} else {
g_free(file);
return path;
}
}
/* check from %XDG_CONFIG_HOME% */
path = g_build_filename(g_get_user_config_dir(), "irssi/scripts/", file, NULL);
if (stat(path, &statbuf) != 0) {
g_free(path);
path = g_strdup_printf(SCRIPTDIR"/%s", file);
if (stat(path, &statbuf) != 0) {
g_free(path);
path = NULL;
} else {
g_free(file);
return path;
}
}
/* check from ~/.irssi/scripts/ */
path = g_strdup_printf("%s/scripts/%s", get_irssi_dir(), file);
if (stat(path, &statbuf) != 0) {