Browse files

Merge pull request #24 from pferor/master

XDG compliance support
  • Loading branch information...
2 parents fabeb14 + 1663a75 commit a8b52551a3b7d44cb76228c22786fa930355383d @gregkh committed Apr 5, 2013
Showing with 12 additions and 3 deletions.
  1. +1 −1 bti-shrink-urls
  2. +11 −2 bti.c
View
2 bti-shrink-urls
@@ -17,7 +17,7 @@
needs_escape=true
shrink_host=2tu.us
-test -f ~/.bti && . ~/.bti
+test -f ~/.bti && source ~/.bti || test -f ~/.config/bti && source ~/.config/bti
while test -n "$1" ; do
word="$1"
View
13 bti.c
@@ -275,8 +275,10 @@ static const char retweet_uri[] = "/retweet/";
static const char group_uri[] = "/../statusnet/groups/timeline/";
static const char config_default[] = "/etc/bti";
+static const char config_xdg_default[] = ".config/bti";
static const char config_user_default[] = ".bti";
+
static CURL *curl_init(void)
{
CURL *curl;
@@ -1203,6 +1205,7 @@ int main(int argc, char *argv[], char *envp[])
{ "retweet", 1, NULL, 'w' },
{ }
};
+ struct stat s;
struct session *session;
pid_t child;
char *tweet;
@@ -1236,13 +1239,19 @@ int main(int argc, char *argv[], char *envp[])
if (home) {
/* We have a home dir, so this might be a user */
session->homedir = strdup(home);
- config_file = config_user_default;
+
+ /* if '.config/' exists, use XDG standard, else don't */
+ if (-1 == stat("~/.config"), &s) {
+ config_file = config_xdg_default;
+ } else {
+ config_file = config_user_default;
+ }
} else {
session->homedir = strdup("");
config_file = config_default;
}
- /* set up a default config file location (traditionally ~/.bti) */
+ /* set up a default config file location (traditionally "~/.bti" or "~/.config/bti") */
session->configfile = zalloc(strlen(session->homedir) + strlen(config_file) + 7);
sprintf(session->configfile, "%s/%s", session->homedir, config_file);

0 comments on commit a8b5255

Please sign in to comment.