Skip to content

Commit

Permalink
load config also from XDG default config dir (#525) or Windows AppDat…
Browse files Browse the repository at this point in the history
…a dir (#201)
  • Loading branch information
mintty committed May 4, 2016
1 parent fc488f4 commit cff1bd8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
25 changes: 14 additions & 11 deletions docs/mintty.1
Expand Up @@ -44,14 +44,14 @@ introducing short options and double dashes introducing long options.
.TP
\fB-c\fP, \fB--config\fP \fIFILENAME\fP
Read settings from the specified configuration file, in addition to
\fI/etc/minttyrc\fP and \fI~/.minttyrc\fP.
the default config files.
Configuration changes are saved to the last file thus specified and not
read-only at the time of loading.

.TP
\fB-C\fP, \fB--loadconfig\fP \fIFILENAME\fP
Read settings from the specified configuration file, in addition to
\fI/etc/minttyrc\fP and \fI~/.minttyrc\fP.
the default config files.
The file is not taken into account for saving configuration changes.
This is useful to mix-in partial configuration variants, particularly
colour schemes. However, \fB-o ThemeFile=\fIFILENAME\fP may be preferable.
Expand Down Expand Up @@ -547,17 +547,20 @@ or the window menu. It has the following action buttons:
affecting further instances of mintty.

In configuration files, settings are stored as \fINAME\fP=\fIVALUE\fP pairs,
with one per line. By default, they are read from \fI/etc/minttyrc\fP and
\fI~/.minttyrc\fP. Additional configuration files can be specified using the
with one per line. By default, they are read from any file of
\fI/etc/minttyrc\fP, \fI$APPDATA/mintty/config\fP,
\fI~/.config/mintty/config\fP, \fI~/.minttyrc\fP, in this order.
Additional configuration files can be specified using the
\fB-c\fP/\fB--config\fP or \fB-C\fP/\fB--loadconfig\fP command line options.
These are read in order, with settings in later files overriding those
in earlier ones.
Configuration changes are saved to the last writable file specified with
\fB-c\fP/\fB--config\fP, or \fI~/.minttyrc\fP if none is given.
These are read in order after the default config files,
with settings in later files overriding those in earlier ones.
Configuration changes are saved to the last writable file
read by default or specified with \fB-c\fP/\fB--config\fP,
or \fI~/.minttyrc\fP if none is given.
Individual settings can also be specified on the command line using the
\fB-o\fP/\fB--option\fP.

\fINote:\fP Many string values in the \fIminttyrc\fP files, especially those
\fINote:\fP Many string values in the config files, especially those
referring to file names or Windows items, are \fBUnicode-enabled\fP,
meaning they are expected to be UTF-8-encoded in the configuration
file independently of the encoding the terminal runs in; as a fallback,
Expand Down Expand Up @@ -590,7 +593,7 @@ Settings affecting mintty's appearance.
\fBColours\fP
Clicking on one of the buttons here opens the colour selection dialog.
.br
In the settings (.minttyrc or command-line options), colours are
In the settings (config file or command-line options), colours are
represented as comma-separated RGB triples with decimal 8-bit values
ranging from 0 to 255. X-style hexadecimal colour specifications such
as #RRGGBB, rgb:RR/GG/BB or rgb:RRRR/GGGG/BBBB can be used as well.
Expand Down Expand Up @@ -1365,7 +1368,7 @@ screen. By default, only an error exit code is displayed.
\fBChange title if exited\fP (ExitTitle=)
Together with a hold option that keeps the terminal open after its child
process terminated, this option prefixes the window title with its string,
for example -o ExitTitle="TERMINATED: " or (in minttyrc) ExitTitle=TERMINATED: .
for example -o ExitTitle="TERMINATED: ".

.TP
\fBConfigure document opening by mouse click\fP (OpeningClicks=1)
Expand Down
16 changes: 7 additions & 9 deletions src/config.c
Expand Up @@ -13,8 +13,6 @@
#include <sys/cygwin.h>


#define dont_debug_config

#define dont_support_blurred


Expand Down Expand Up @@ -636,17 +634,17 @@ load_config(string filename, bool to_save)
if (access(filename, R_OK) == 0 && access(filename, W_OK) < 0)
to_save = false;

FILE *file = fopen(filename, "r");

if (to_save) {
file_opts_num = arg_opts_num = 0;
if (file || (!rc_filename && strstr(filename, "/.minttyrc"))) {
file_opts_num = arg_opts_num = 0;

delete(rc_filename);
rc_filename = path_posix_to_win_w(filename);
delete(rc_filename);
rc_filename = path_posix_to_win_w(filename);
}
}
#ifdef debug_config
printf ("will save to %s? %d\n", filename, to_save);
#endif

FILE *file = fopen(filename, "r");
if (file) {
static char line[256];
while (fgets(line, sizeof line, file)) {
Expand Down
16 changes: 15 additions & 1 deletion src/winmain.c
Expand Up @@ -1829,8 +1829,22 @@ main(int argc, char *argv[])
# endif
#endif

// Load config files
// try global config file
load_config("/etc/minttyrc", true);
string rc_file = asform("%s/.minttyrc", home);
// try Windows config location (#201)
char * appdata = getenv("APPDATA");
if (appdata && *appdata) {
string rc_file = asform("%s/mintty/config", appdata);
load_config(rc_file, true);
delete(rc_file);
}
// try XDG config base directory default location (#525)
string rc_file = asform("%s/.config/mintty/config", home);
load_config(rc_file, true);
delete(rc_file);
// try home config file
rc_file = asform("%s/.minttyrc", home);
load_config(rc_file, true);
delete(rc_file);

Expand Down
1 change: 1 addition & 0 deletions wiki/Changelog.md
@@ -1,3 +1,4 @@
* Loading config also from XDG default config dir (#525) or Windows AppData dir (#201).
* Option CtrlExchangeShiftExchange exchanges Control characters with Ctrl+Shift shortcuts (#524).
* Shortcut key Shift+Ctrl+A for "Select All".
* Option OpeningClicks configures whether documents are opened on single/double/triple Ctrl+mouse-click (#545).
Expand Down

0 comments on commit cff1bd8

Please sign in to comment.