From: Jonas Fonseca Date: Thu, 5 Feb 2009 11:47:48 +0000 (+0100) Subject: Read tigrc(5) options from git configuration files X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=51c22f5501881cb1753baa82d2d1d4e02a77769f;p=tig.git Read tigrc(5) options from git configuration files --- diff --git a/NEWS b/NEWS index bd7d6c4..c715318 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,12 @@ Incompatibilities: Improvements: - Horizontal scrolling. Bound to Left/Right by default. + - Read tigrc(5) options from git configuration files using the syntax: + + [tig] show-rev-graph = true + [tig "color"] cursor = yellow red bold + [tig "bind"] generic = P parent + - Tree view: avoid flickering when updating. - Tree view: annotate entries with commit information. - Tree & blob view: open any blob in an editor. diff --git a/tig.1.txt b/tig.1.txt index 98e9f5d..db8a4d7 100644 --- a/tig.1.txt +++ b/tig.1.txt @@ -142,7 +142,9 @@ FILES System wide configuration file. '$GIT_DIR/config':: - Repository config file. Read on start-up with the help of +'~/.gitconfig:: +'{sysconfdir}/etc/gitconfig:: + Git configuration files. Read on start-up with the help of git-config(1). include::BUGS[] diff --git a/tig.c b/tig.c index ce406c8..83ee8b9 100644 --- a/tig.c +++ b/tig.c @@ -6609,6 +6609,22 @@ load_refs(void) return run_io_load(ls_remote_argv, "\t", read_ref); } +static void +set_repo_config_option(char *name, char *value, int (*cmd)(int, const char **)) +{ + const char *argv[SIZEOF_ARG] = { name, "=" }; + int argc = 1 + (cmd == option_set_command); + int error = ERR; + + if (!argv_from_string(argv, &argc, value)) + config_msg = "Too many option arguments"; + else + error = cmd(argc, argv); + + if (error == ERR) + warn("Option 'tig.%s': %s", name, config_msg); +} + static int read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen) { @@ -6618,6 +6634,15 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen if (!strcmp(name, "core.editor")) string_ncopy(opt_editor, value, valuelen); + if (!prefixcmp(name, "tig.color.")) + set_repo_config_option(name + 10, value, option_color_command); + + else if (!prefixcmp(name, "tig.bind.")) + set_repo_config_option(name + 9, value, option_bind_command); + + else if (!prefixcmp(name, "tig.")) + set_repo_config_option(name + 4, value, option_set_command); + /* branch..remote */ if (*opt_head && !strncmp(name, "branch.", 7) && diff --git a/tigrc.5.txt b/tigrc.5.txt index ff0613d..6f11102 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -3,7 +3,7 @@ tigrc(5) NAME ---- -tigrc - tig user configuration file +tigrc - tig configuration file SYNOPSIS @@ -27,6 +27,9 @@ The hash mark ('#') is used as a 'comment' character. All text after the comment character to the end of the line is ignored. You can use comments to annotate your initialization file. +Alternatively, options can be set by putting them in one of the git +configuration files, which are read by tig on startup. See 'git-config(1)' for +which files to use. Set command ----------- @@ -47,11 +50,17 @@ set show-date = yes # Show commit date? set show-rev-graph = yes # Show revision graph? set show-refs = yes # Show references? set show-line-numbers = no # Show line numbers? -set author-width = 10 # Set width of the author column -set line-graphics = no # Disable graphics characters set line-number-interval = 5 # Interval between line numbers -set tab-size = 8 # Number of spaces per tab -set encoding = "UTF-8" # Commit encoding +-------------------------------------------------------------------------- + +Or in the git configuration files: + +-------------------------------------------------------------------------- +[tig] + author-width = 10 # Set width of the author column + line-graphics = no # Disable graphics characters + tab-size = 8 # Number of spaces per tab + encoding = "UTF-8" # Commit encoding -------------------------------------------------------------------------- The type of variables are either bool, int, and string. @@ -129,12 +138,18 @@ bind main space enter bind diff a previous bind diff d next bind diff b move-first-line -# 'unbind' the default quit key binding -bind main Q none # An external command to update from upstream bind generic F !git fetch -# Cherry-pick current commit onto current branch -bind generic C !git cherry-pick %(commit) +-------------------------------------------------------------------------- + +Or in the git configuration files: + +-------------------------------------------------------------------------- +[tig "bind"] + # 'unbind' the default quit key binding + main = Q none + # Cherry-pick current commit onto current branch + generic = C !git cherry-pick %(commit) -------------------------------------------------------------------------- Keys are mapped by first searching the keybindings for the current view, then @@ -323,11 +338,17 @@ color default white black color diff-header yellow default color diff-index blue default color diff-chunk magenta default -# A strange looking cursor line -color cursor red default underline -# UI colors -color title-blur white blue -color title-focus white blue bold +-------------------------------------------------------------------------- + +Or in the git configuration files: + +-------------------------------------------------------------------------- +[tig "color"] + # A strange looking cursor line + cursor red default underline + # UI colors + title-blur white blue + title-focus white blue bold ------------------------------------------------------------------------------ Area names:: @@ -481,4 +502,5 @@ Licensed under the terms of the GNU General Public License. SEE ALSO -------- -manpage:tig[1] and the http://jonas.nitro.dk/tig/manual.html[tig manual]. +manpage:tig[1], git-config(1), +and the http://jonas.nitro.dk/tig/manual.html[tig manual].