From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH v3 02/18] ls_colors.c: parse color.ls.* from config file Date: Sun, 30 Mar 2014 20:55:53 +0700 Message-ID: <1396187769-30863-3-git-send-email-pclouds@gmail.com> References: <1395841697-11742-1-git-send-email-pclouds@gmail.com> <1396187769-30863-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Sun Mar 30 15:56:15 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WUGDe-0002qX-M9 for gcvg-git-2@plane.gmane.org; Sun, 30 Mar 2014 15:56:15 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751903AbaC3N4J convert rfc822-to-quoted-printable (ORCPT ); Sun, 30 Mar 2014 09:56:09 -0400 Received: from mail-pb0-f44.google.com ([209.85.160.44]:58047 "EHLO mail-pb0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751746AbaC3Nzy (ORCPT ); Sun, 30 Mar 2014 09:55:54 -0400 Received: by mail-pb0-f44.google.com with SMTP id rp16so7020866pbb.31 for ; Sun, 30 Mar 2014 06:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=3p3/9Fa2CxpHkoAkzNJCYIr6DOHRg6D8hU31anv3ZGQ=; b=ap9NtrrIALLx55JomglGwKVcb8ZJl/G2ZWZHuITENhB75rpcPJrl2jxciyMiVpyV+c sZ/4gH6PzjuLNrTOcMOMu9XIZ2EXrvMRmyHGGz5Ajk34vS8ErdM3o9jItxsAqEjkRGJo YZI1csJNU3gSikvjukeUZ68uJ20xELaI9AxEyutBN4TOPfIBp0wB+Ac6mDskrQFcOMvB n455eqGRPVMnpUe2smT3+pMaX2ytgTOZV95AZtVqk2Nrq4sEqyW/cRYZ/ZVAN45//jBT aDDC1o8vQrnU9oIFUovtRV8mGPhWam2B/kXjr9F3eOm2BJH77F9VmqOA6kEBLcdSaBix X2NQ== X-Received: by 10.66.159.233 with SMTP id xf9mr418887pab.139.1396187754298; Sun, 30 Mar 2014 06:55:54 -0700 (PDT) Received: from lanh ([115.73.202.240]) by mx.google.com with ESMTPSA id kt8sm26219098pab.7.2014.03.30.06.55.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Mar 2014 06:55:53 -0700 (PDT) Received: by lanh (sSMTP sendmail emulation); Sun, 30 Mar 2014 20:56:50 +0700 X-Mailer: git-send-email 1.9.1.345.ga1a145c In-Reply-To: <1396187769-30863-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: This is the second (and preferred) source for color information. This will override $LS_COLORS. Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- Documentation/config.txt | 11 +++++++++++ ls_colors.c | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 73c8973..3fb754e 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -909,6 +909,17 @@ color.status.:: to red). The values of these variables may be specified as in color.branch.. =20 +color.ls.:: + Use customized color for file name colorization. If not set + and the environment variable LS_COLORS is set, color settings + from $LS_COLORS are used. `` can be `normal`, `file`, + `directory`, `symlink`, `fifo`, `socket`, `block`, `char`, + `missing`, `orphan`, `executable`, `door`, `setuid`, `setgid`, + `sticky`, `otherwritable`, `stickyotherwritable`, `cap`, + `multihardlink`. The values of these variables may be + specified as in color.branch.. + + color.ui:: This variable determines the default value for variables such as `color.diff` and `color.grep` that control the use of color diff --git a/ls_colors.c b/ls_colors.c index eb944f4..cef5a92 100644 --- a/ls_colors.c +++ b/ls_colors.c @@ -68,6 +68,14 @@ static const char *const indicator_name[] =3D { NULL }; =20 +static const char* const config_name[] =3D { + "", "", "", "", "normal", "file", "directory", "symlink", + "fifo", "socket", "block", "char", "missing", "orphan", "executable", + "door", "setuid", "setgid", "sticky", "otherwritable", + "stickyotherwritable", "cap", "multihardlink", "", + NULL +}; + struct bin_str { size_t len; /* Number of bytes */ const char *string; /* Pointer to the same */ @@ -285,6 +293,23 @@ static int get_funky_string(char **dest, const cha= r **src, int equals_end, return state !=3D ST_ERROR; } =20 +static int ls_colors_config(const char *var, const char *value, void *= cb) +{ + int slot; + if (!starts_with(var, "color.ls.")) + return 0; + var +=3D 9; + for (slot =3D 0; config_name[slot]; slot++) + if (!strcasecmp(var, config_name[slot])) + break; + if (!config_name[slot]) + return 0; + if (!value) + return config_error_nonbool(var); + color_parse(value, var, ls_colors[slot]); + return 0; +} + void parse_ls_color(void) { const char *p; /* Pointer to character being parsed */ @@ -395,4 +420,5 @@ void parse_ls_color(void) =20 if (!strcmp(ls_colors[LS_LN], "target")) color_symlink_as_referent =3D 1; + git_config(ls_colors_config, NULL); } --=20 1.9.1.345.ga1a145c