mirror of
https://github.com/irssi/irssi.git
synced 2026-08-21 17:42:49 +02:00
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:
parent
a1cbb8d28f
commit
f972d05025
3 changed files with 45 additions and 15 deletions
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef IRSSI_COMMON_H
|
||||
#define IRSSI_COMMON_H
|
||||
|
||||
#define IRSSI_DIR_FULL "%s/.irssi" /* %s == g_get_home_dir() */
|
||||
|
||||
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
|
||||
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
|
||||
|
||||
|
|
|
|||
|
|
@ -189,16 +189,20 @@ void core_register_options(void)
|
|||
|
||||
void core_preinit(const char *path)
|
||||
{
|
||||
const char *home;
|
||||
char *str;
|
||||
int len;
|
||||
|
||||
if (irssi_dir == NULL) {
|
||||
home = g_get_home_dir();
|
||||
irssi_dir = g_build_filename(g_get_user_config_dir(), "irssi", NULL);
|
||||
if (home == NULL)
|
||||
if (g_file_test(irssi_dir, G_FILE_TEST_IS_DIR) == FALSE) {
|
||||
home = ".";
|
||||
g_free(irssi_dir);
|
||||
|
||||
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, home);
|
||||
const char *home;
|
||||
home = g_get_home_dir();
|
||||
irssi_dir = g_build_filename(home? home: ".", ".irssi", NULL);
|
||||
}
|
||||
} else {
|
||||
str = irssi_dir;
|
||||
irssi_dir = fix_path(str);
|
||||
|
|
@ -208,7 +212,7 @@ void core_preinit(const char *path)
|
|||
irssi_dir[len-1] = '\0';
|
||||
}
|
||||
if (irssi_config_file == NULL)
|
||||
irssi_config_file = g_strdup_printf("%s/"IRSSI_HOME_CONFIG, irssi_dir);
|
||||
irssi_config_file = g_build_filename(irssi_dir, IRSSI_HOME_CONFIG, NULL)
|
||||
else {
|
||||
str = irssi_config_file;
|
||||
irssi_config_file = fix_path(str);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue