From 282befe3579897174288075810a6c1d89df7a29f Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Fri, 7 May 2021 11:11:55 +0200 Subject: [PATCH 2/2] shell: add ~/.config/bash/ startup script options Introduce an alternate location for storing a profile and bashrc file, inside ~/.config/bash. This is mostly compatible with the XDG Base Directory Specification[1], but doesn't support expanding the XDG_CONFIG_HOME environment variable, which would require a larger patch with string manipulation/pasting. [1] https://specifications.freedesktop.org/basedir-spec/ --- doc/bash.1 | 21 ++++++++++++++------- shell.c | 5 +++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/doc/bash.1 b/doc/bash.1 index 5af7d428..69aa9853 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -188,6 +188,8 @@ Display a usage message on standard output and exit successfully. Execute commands from .I file instead of the standard personal initialization file +.I ~/.config/bash/bashrc +or .I ~/.bashrc if the shell is interactive (see .SM @@ -219,6 +221,8 @@ below). .TP .B \-\-norc Do not read and execute the personal initialization file +.I ~/.config/bash/bashrc +or .I ~/.bashrc if the shell is interactive. This option is on by default if the shell is invoked as @@ -318,9 +322,10 @@ is invoked as an interactive login shell, or as a non-interactive shell with the \fB\-\-login\fP option, it first reads and executes commands from the file \fI/etc/profile\fP, if that file exists. -After reading that file, it looks for \fI~/.bash_profile\fP, -\fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads -and executes commands from the first one that exists and is readable. +After reading that file, it looks for \fI~/.config/bash/profile\fP, +\fI~/.bash_profile\fP, \fI~/.bash_login\fP, and \fI~/.profile\fP, in that +order, and reads and executes commands from the first one that exists and +is readable. The .B \-\-noprofile option may be used when the shell is started to inhibit this behavior. @@ -333,8 +338,9 @@ exists. .PP When an interactive shell that is not a login shell is started, .B bash -reads and executes commands from \fI~/.bashrc\fP, if that file exists. -This may be inhibited by using the +looks for \fI~/.config/bash/bashrc\fP, and \fI~/.bashrc\fP, in that +order, and reads and executes commands from the first one that exists and +is readable. This may be inhibited by using the .B \-\-norc option. The \fB\-\-rcfile\fP \fIfile\fP option will force @@ -424,8 +430,9 @@ connected to a network connection, as when executed by the remote shell daemon, usually \fIrshd\fP, or the secure shell daemon \fIsshd\fP. If .B bash -determines it is being run in this fashion, it reads and executes -commands from \fI~/.bashrc\fP, if that file exists and is readable. +determines it is being run in this fashion, it reads and executes commands +from the first one of \fI~/.config/bash/bashrc\fP, and \fI~/.bashrc\fP, +which exists and is readable. It will not do this if invoked as \fBsh\fP. The .B \-\-norc diff --git a/shell.c b/shell.c index 6327e72d..c14c1844 100644 --- a/shell.c +++ b/shell.c @@ -1104,7 +1104,8 @@ execute_profile () if (!act_like_sh) { - if (maybe_execute_file ("~/.bash_profile", 1) || + if (maybe_execute_file ("~/.config/bash/profile", 1) || + maybe_execute_file ("~/.bash_profile", 1) || maybe_execute_file ("~/.bash_login", 1)) return; } @@ -1125,7 +1126,7 @@ execute_bashrc () if (bashrc_file) maybe_execute_file (bashrc_file, 1); - else + else if (maybe_execute_file ("~/.config/bash/bashrc", 1) == 0) maybe_execute_file (DEFAULT_BASHRC, 1); } -- 2.31.1