Skip to content

Commit 2662c8e

Browse files
committed
Support bashrc_d_on_exit()
1 parent 87ed39b commit 2662c8e

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

bash_login

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Do not put anything in this file; Bash will not read it. Bash would only
2-
# read it if ~/.bash_profile did not exist.
1+
# STOP! Do not put anything in this file; Bash will not read it. Bash would
2+
# only read it if ~/.bash_profile did not exist.

bash_logout

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
1-
# Copyright 2015 Robin Bate Boerop <[email protected]>
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
15-
# STOP! Do not put code here. It will not do what you think it will.
16-
# Instead, please add code to the exit_trap() function in the bashrc file.
1+
# STOP! Do not put code here. It will not do what you think. Instead, please
2+
# use bashrc_d_on_exit() to register a Bash command to be eval'd on exit.

bash_profile

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
export BASHRC_D_BASH_PROFILE_SOURCED=1
2020
export BASHRC_D_DIR=~/.bashrc.d
2121

22+
bashrc_d_on_exit_commands=()
23+
bashrc_d_invoke_on_exit_commands() {
24+
local i
25+
for i in ${bashrc_d_exit_commands[*]}; do
26+
eval $i
27+
done
28+
}
29+
bashrc_d_on_exit() {
30+
bashrc_d_on_exit_commands+=("$*")
31+
trap bashrc_d_invoke_on_exit_commands EXIT
32+
}
33+
2234
# Bash utility functions upon which the custom scripts can rely, but which
2335
# can be overridden if desired.
2436
#

0 commit comments

Comments
 (0)