Code

Read tigrc(5) options from git configuration files
authorJonas Fonseca <fonseca@diku.dk>
Thu, 5 Feb 2009 11:47:48 +0000 (12:47 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 5 Feb 2009 17:57:33 +0000 (18:57 +0100)
NEWS
tig.1.txt
tig.c
tigrc.5.txt

diff --git a/NEWS b/NEWS
index bd7d6c4e93eff3ef938db403a4e28f61565308a2..c715318595f8432f101a77d3ba529599440f9fb0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,12 @@ Incompatibilities:
 Improvements:
 
  - Horizontal scrolling. Bound to Left/Right by default.
 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.
  - Tree view: avoid flickering when updating.
  - Tree view: annotate entries with commit information.
  - Tree & blob view: open any blob in an editor.
index 98e9f5d9cdbe8e5679d736eea4eca592c0c8f914..db8a4d7a45dc750ebf542be377e3d1b9d8a0814d 100644 (file)
--- a/tig.1.txt
+++ b/tig.1.txt
@@ -142,7 +142,9 @@ FILES
        System wide configuration file.
 
 '$GIT_DIR/config'::
        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[]
        git-config(1).
 
 include::BUGS[]
diff --git a/tig.c b/tig.c
index ce406c86fbed25706912987126721960c61cbbc0..83ee8b95e76dd615bdb3513356e9cb6d37a8f267 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -6609,6 +6609,22 @@ load_refs(void)
        return run_io_load(ls_remote_argv, "\t", read_ref);
 }
 
        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)
 {
 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 (!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.<head>.remote */
        if (*opt_head &&
            !strncmp(name, "branch.", 7) &&
        /* branch.<head>.remote */
        if (*opt_head &&
            !strncmp(name, "branch.", 7) &&
index ff0613dc7a498af15705bc573065d7f6e57ac406..6f11102a1f9384852f05636a02eaf78ff2951029 100644 (file)
@@ -3,7 +3,7 @@ tigrc(5)
 
 NAME
 ----
 
 NAME
 ----
-tigrc - tig user configuration file
+tigrc - tig configuration file
 
 
 SYNOPSIS
 
 
 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.
 
 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
 -----------
 
 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 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 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.
 --------------------------------------------------------------------------
 
 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
 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
 # 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
 --------------------------------------------------------------------------
 
 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
 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::
 ------------------------------------------------------------------------------
 
 Area names::
@@ -481,4 +502,5 @@ Licensed under the terms of the GNU General Public License.
 
 SEE ALSO
 --------
 
 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].