# [PATCH] Add support reading default options from conf file

3 messages from 2005-06-09 to 2005-06-11. Participants: Jonas Fonseca, Petr Baudis.
Thread: https://gitlist.dev/t/871

## Jonas Fonseca, 2005-06-09 01:00

Subject: [PATCH] Add support reading default options from conf file
Message-ID: <20050609010056.GA9084@diku.dk>
URL: https://gitlist.dev/e/20050609010056.GA9084%40diku.dk

```
Reply-To: 
In-Reply-To: <42A754D5.10705@gmail.com>

Dan Holmsand <holmsand@gmail.com> wrote Wed, Jun 08, 2005:
> - Automatic color if the COGITO_AUTO_COLOR environment variable is set.

[ This has been discussed before. Default arguments. The 'new' cg
  wrapper makes this very easy. Not as smart as your env variable
  handling tho'. ]

The default options are read only for Cogito calls going through the new
cg wrapper which makes it trivial to 'overwrite' them by just calling
cg-COMMAMD.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---

 Documentation/make-cogito-asciidoc |   12 ++++++++++++
 cg                                 |    6 +++++-
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/Documentation/make-cogito-asciidoc b/Documentation/make-cogito-asciidoc
--- a/Documentation/make-cogito-asciidoc
+++ b/Documentation/make-cogito-asciidoc
@@ -140,6 +140,18 @@ FILE::
 	Indicates an already existing filename - always relative to the root
 	of the repository.
 
+FILES
+-----
+~/.cogito.conf::
+	This file is read when running the \`cg\` wrapper program and
+	contains information about default options. Each line consists
+	of a command name and a list of options. Empty lines and lines
+	starting with '#' are ignored. To always have \`cg log\` and
+	\`cg diff\` output colored put the following in ~/.cogito.conf:
+
+		log -c
+		diff -c
+
 COPYRIGHT
 ---------
 Copyright (C) Petr Baudis, 2005.
diff --git a/cg b/cg
--- a/cg
+++ b/cg
@@ -3,5 +3,9 @@
 cmd="$1"; shift
 [ x"$cmd" = x"--help" ] && cmd="help"
 
+if [ -e "$HOME/.cogito.conf" ]; then
+	defaults="$(grep "^$cmd" "$HOME/.cogito.conf" | sed "s/^$cmd //")"
+fi
+
 exe="cg-$cmd"
-exec $exe "$@"
+exec $exe "$defaults" "$@"

-- 
Jonas Fonseca

```

## Petr Baudis, 2005-06-09 08:32

Subject: Re: [PATCH] Add support reading default options from conf file
Message-ID: <20050609083243.GD29665@pasky.ji.cz>
URL: https://gitlist.dev/e/20050609083243.GD29665%40pasky.ji.cz
In-Reply-To: <20050609010056.GA9084@diku.dk>

```
Dear diary, on Thu, Jun 09, 2005 at 03:00:56AM CEST, I got a letter
where Jonas Fonseca <fonseca@diku.dk> told me that...
> Reply-To: 
> In-Reply-To: <42A754D5.10705@gmail.com>
> 
> Dan Holmsand <holmsand@gmail.com> wrote Wed, Jun 08, 2005:
> > - Automatic color if the COGITO_AUTO_COLOR environment variable is set.
> 
> [ This has been discussed before. Default arguments. The 'new' cg
>   wrapper makes this very easy. Not as smart as your env variable
>   handling tho'. ]
> 
> The default options are read only for Cogito calls going through the new
> cg wrapper which makes it trivial to 'overwrite' them by just calling
> cg-COMMAMD.
> 
> Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

No, this is the wrong way. The 'cg' wrapper must not really do anything
special on its own. It's not a _replacement_ for direct calling of the
cg-scripts, it's just an aid for people who don't want to get used to
it. So please do this in cg-Xlib.

Also, I'd prefer the config file to be something like ~/.cgrc. I want to
reserve the .conf file for something more sophisticated. ;-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
<Espy> be careful, some twit might quote you out of context..

```

## Jonas Fonseca, 2005-06-11 01:09

Subject: [PATCH] Read default options from config file
Message-ID: <20050611010931.GA13272@diku.dk>
URL: https://gitlist.dev/e/20050611010931.GA13272%40diku.dk
In-Reply-To: <20050609083243.GD29665@pasky.ji.cz>

```
Petr Baudis <pasky@ucw.cz> wrote Thu, Jun 09, 2005:
> Dear diary, on Thu, Jun 09, 2005 at 03:00:56AM CEST, I got a letter
> where Jonas Fonseca <fonseca@diku.dk> told me that...
> > 
> > Dan Holmsand <holmsand@gmail.com> wrote Wed, Jun 08, 2005:
> > > - Automatic color if the COGITO_AUTO_COLOR environment variable is set.
> > 
> > [ This has been discussed before. Default arguments. The 'new' cg
> >   wrapper makes this very easy. Not as smart as your env variable
> >   handling tho'. ]
> > 
> > The default options are read only for Cogito calls going through the new
> > cg wrapper which makes it trivial to 'overwrite' them by just calling
> > cg-COMMAMD.
> 
> No, this is the wrong way. The 'cg' wrapper must not really do anything
> special on its own. It's not a _replacement_ for direct calling of the
> cg-scripts, it's just an aid for people who don't want to get used to
> it. So please do this in cg-Xlib.
> 
> Also, I'd prefer the config file to be something like ~/.cgrc. I want to
> reserve the .conf file for something more sophisticated. ;-)

With the optparse stuff in things got a lot easier. I took the idea to
check for stole from Dan Holmsands patches to only read it when stdout
is a terminal. So the file is really only for interactive usage.

---

Introduce ~/.cgrc config file. The file is read on startup if stdout is
a terminal and may contain information about default command line
options. Each line consists of a command name and a list of options.
Lines not starting with a 'Cogito' command name are ignored.

To always have cg-log and cg-diff colorize the output put the followig
in ~/.cgrc:

	log -c
	diff -c

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---

 Documentation/make-cogito-asciidoc |   13 +++++++++++++
 cg-Xlib                            |    7 +++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/Documentation/make-cogito-asciidoc b/Documentation/make-cogito-asciidoc
--- a/Documentation/make-cogito-asciidoc
+++ b/Documentation/make-cogito-asciidoc
@@ -140,6 +140,19 @@ FILE::
 	Indicates an already existing filename - always relative to the root
 	of the repository.
 
+FILES
+-----
+~/.cgrc::
+	This file is read on startup if \`stdout\` is a terminal and may
+	contain information about default command line options. Each line
+	consists of a command name and a list of options. Lines not
+	starting with a 'Cogito' command name are ignored. To have
+	\`cg-log\` and \`cg-diff\` colorize the output put the following
+	in ~/.cgrc:
+
+		log -c
+		diff -c
+
 COPYRIGHT
 ---------
 Copyright (C) Petr Baudis, 2005.
diff --git a/cg-Xlib b/cg-Xlib
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -150,6 +150,13 @@ done
 ARGS=("$@")
 ARGPOS=0
 
+if [ -t 1 -a -e "$HOME/.cgrc" ]; then
+	_cg_name=${_cg_cmd#cg-}
+	_cg_defaults="$(sed -n "/^$_cg_name/s/^$_cg_name //p" < $HOME/.cgrc)"
+	ARGS=($_cg_defaults "${ARGS[@]}")
+fi
+
+
 optshift() {
 	unset ARGS[$ARGPOS]
 	ARGS=("${ARGS[@]}")
-- 
Jonas Fonseca

```
