Browse Source

Fix #59 with env variable CDIFF_OPTIONS

Matthew Wang 8 years ago
parent
commit
f3fe271a35
2 changed files with 18 additions and 3 deletions
  1. 11
    1
      README.rst
  2. 7
    2
      cdiff.py

+ 11
- 1
README.rst View File

97
 
97
 
98
       Note:
98
       Note:
99
         Option parser will stop on first unknown option and pass them down to
99
         Option parser will stop on first unknown option and pass them down to
100
-        underneath revision control
100
+        underneath revision control. Environment variable CDIFF_OPTIONS may be
101
+        used to specify default options that will be placed at the beginning
102
+        of the argument list.
101
 
103
 
102
 Read diff from local modification in a *Git/Mercurial/Svn* workspace (output
104
 Read diff from local modification in a *Git/Mercurial/Svn* workspace (output
103
 from e.g. ``git diff``, ``svn diff``):
105
 from e.g. ``git diff``, ``svn diff``):
126
     cdiff -ls -w90              # set text width 90 as well
128
     cdiff -ls -w90              # set text width 90 as well
127
     cdiff -ls file1 dir2        # see log with changes of given files/dirs only
129
     cdiff -ls file1 dir2        # see log with changes of given files/dirs only
128
 
130
 
131
+Environment variable ``CDIFF_OPTIONS`` may be used to specify default options
132
+that will be placed at the beginning of the argument list, for example:
133
+
134
+.. code-block:: bash
135
+
136
+    export CDIFF_OPTIONS='-s -w0'
137
+    cdiff foo                   # equivalent to "cdiff -s -w0 foo"
138
+
129
 If you feel more comfortable with a command such as ``git cdiff`` to trigger
139
 If you feel more comfortable with a command such as ``git cdiff`` to trigger
130
 the cdiff command, you may symlink the executable to one named ``git-cdiff``
140
 the cdiff command, you may symlink the executable to one named ``git-cdiff``
131
 as follows:
141
 as follows:

+ 7
- 2
cdiff.py View File

755
     # Hack: use OptionGroup text for extra help message after option list
755
     # Hack: use OptionGroup text for extra help message after option list
756
     option_group = OptionGroup(
756
     option_group = OptionGroup(
757
         parser, "Note", ("Option parser will stop on first unknown option "
757
         parser, "Note", ("Option parser will stop on first unknown option "
758
-                         "and pass them down to underneath revision control"))
758
+                         "and pass them down to underneath revision control. "
759
+                         "Environment variable CDIFF_OPTIONS may be used to "
760
+                         "specify default options that will be placed at the "
761
+                         "beginning of the argument list."))
759
     parser.add_option_group(option_group)
762
     parser.add_option_group(option_group)
760
 
763
 
761
-    opts, args = parser.parse_args()
764
+    # Place possible options defined in CDIFF_OPTIONS at the beginning of argv
765
+    cdiff_opts = [x for x in os.getenv('CDIFF_OPTIONS', '').split(' ') if x]
766
+    opts, args = parser.parse_args(cdiff_opts + sys.argv[1:])
762
 
767
 
763
     if opts.log:
768
     if opts.log:
764
         diff_hdl = revision_control_log(args)
769
         diff_hdl = revision_control_log(args)