nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 343f97b3aca81ee95470abf66a928563028d7f46
parent 706f3e93f4b207965a4c77bc435370a2c58ea9da
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 14 Jan 2020 12:41:22 +0100

new feature: allow specifying a custom nanorc file on the command line

This fulfills https://savannah.gnu.org/bugs/?57547.
Requested-by: Saagar Jha <saagar@saagarjha.com>

Diffstat:
Msrc/global.c | 3+++
Msrc/nano.c | 14+++++++++++++-
Msrc/proto.h | 3+++
Msrc/rcfile.c | 10+++++++++-
4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/global.c b/src/global.c @@ -249,6 +249,9 @@ char *statedir = NULL; char *startup_problem = NULL; /* An error message (if any) about nanorc files or history files. */ #endif +#ifdef ENABLE_NANORC +char *custom_nanorc = NULL; +#endif bool spotlighted = FALSE; /* Whether any text is spotlighted. */ diff --git a/src/nano.c b/src/nano.c @@ -635,6 +635,10 @@ void usage(void) print_opt("-d", "--rebinddelete", N_("Fix Backspace/Delete confusion problem")); print_opt("-e", "--emptyline", N_("Keep the line below the title bar empty")); +#ifdef ENABLE_NANORC + print_opt(_("-f <file>"), _("--rcfile=<file>"), + N_("Use only this file for configuring nano")); +#endif #ifdef ENABLE_BROWSER if (!ISSET(RESTRICTED)) print_opt("-g", "--showcursor", N_("Show cursor in file browser & help text")); @@ -1781,6 +1785,9 @@ int main(int argc, char **argv) {"constantshow", 0, NULL, 'c'}, {"rebinddelete", 0, NULL, 'd'}, {"emptyline", 0, NULL, 'e'}, +#ifdef ENABLE_NANORC + {"rcfile", 1, NULL, 'f'}, +#endif #ifdef ENABLE_BROWSER {"showcursor", 0, NULL, 'g'}, #endif @@ -1889,7 +1896,7 @@ int main(int argc, char **argv) while ((optchr = getopt_long(argc, argv, - "ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Zabcdeghijklmno:pr:s:tuvwxyz$", + "ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Zabcdef:ghijklmno:pr:s:tuvwxyz$", long_options, NULL)) != -1) { switch (optchr) { #ifndef NANO_TINY @@ -2029,6 +2036,11 @@ int main(int argc, char **argv) case 'e': SET(EMPTY_LINE); break; +#ifdef ENABLE_NANORC + case 'f': + custom_nanorc = mallocstrcpy(custom_nanorc, optarg); + break; +#endif case 'g': SET(SHOW_CURSOR); break; diff --git a/src/proto.h b/src/proto.h @@ -175,6 +175,9 @@ extern char *statedir; #if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES) extern char *startup_problem; #endif +#ifdef ENABLE_NANORC +extern char *custom_nanorc; +#endif extern bool spotlighted; extern size_t light_from_col; diff --git a/src/rcfile.c b/src/rcfile.c @@ -1647,11 +1647,18 @@ void do_rcfiles(void) { const char *xdgconfdir; + if (custom_nanorc) { + nanorc = get_full_path(custom_nanorc); + if (access(nanorc, F_OK) != 0) + die(_("Specified rcfile does not exist\n")); + } else + nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc"); + /* First process the system-wide nanorc, if it exists and is suitable. */ - nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc"); if (is_good_file(nanorc)) parse_one_nanorc(); + if (custom_nanorc == NULL) { get_homedir(); xdgconfdir = getenv("XDG_CONFIG_HOME"); @@ -1663,6 +1670,7 @@ void do_rcfiles(void) parse_one_nanorc(); else if (homedir == NULL && xdgconfdir == NULL) jot_error(N_("I can't find my home directory! Wah!")); + } check_vitals_mapped();