Skip to content

Commit

Permalink
Respect the XDG standard for configuration files
Browse files Browse the repository at this point in the history
From GH #513:

    Rather than reading the user configuration from `~/.tigrc` by
    default, instead check `$XDG_CONFIG_HOME/tig/config` and only then
    look for `~/.tigrc`. Further reading:
    https://ploum.net/207-modify-your-application-to-use-xdg-folders/

Fixes #513
  • Loading branch information
jonas committed Aug 4, 2016
1 parent 8fe27d5 commit 1e6da9d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Improvements:
- Compact relative date display mode. (GH #331)
- Add date column option controlling whether to show local date.
- Move to parent commit in the main view. (GH #388)
- Respect the XDG standard for configuration files. (GH #513)
- Support for custom `strftime(3)` date formats, e.g.:

set main-view-date = custom
Expand Down
14 changes: 12 additions & 2 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ load_options(void)
const char *tig_diff_opts = getenv("TIG_DIFF_OPTS");
const bool diff_opts_from_args = !!opt_diff_options;
bool custom_tigrc_system = !!tigrc_system;
char buf[SIZEOF_STR];

opt_file_filter = true;
if (!find_option_info_by_value(&opt_diff_context)->seen)
Expand All @@ -977,8 +978,17 @@ load_options(void)
return error("Error in built-in config");
}

if (!tigrc_user)
tigrc_user = TIG_USER_CONFIG;
if (!tigrc_user) {
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");

if (!xdg_config_home)
tigrc_user = TIG_USER_CONFIG;
else if (!string_format(buf, "%s/tig/config", xdg_config_home))
return error("Failed to expand $XDG_CONFIG_HOME");
else
tigrc_user = buf;
}

load_option_file(tigrc_user);

if (!diff_opts_from_args && tig_diff_opts && *tig_diff_opts) {
Expand Down
28 changes: 28 additions & 0 deletions test/tigrc/xdg-config-home-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

. libtest.sh

tigrc <<EOF
This tigrc file should not be loaded!
EOF

steps "
<Ctrl-t>
"

#export TIGRC_SYSTEM="should-not-be-loaded"
export XDG_CONFIG_HOME="$HOME/.config"
mkdir -p "$XDG_CONFIG_HOME/tig"

cat > "$XDG_CONFIG_HOME/tig/config" <<EOF
bind generic <Ctrl-t> @sh -c 'echo ran > ~/RUNME'
EOF

test_tig status

assert_equals stderr <<EOF
EOF

assert_equals RUNME <<EOF
ran
EOF

0 comments on commit 1e6da9d

Please sign in to comment.