summaryrefslogtreecommitdiff
path: root/.bashrc
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-12-30 20:36:01 +0200
committerSyndamia <kamen@syndamia.com>2024-12-30 20:36:01 +0200
commit8e65740c4e5784fde61c622342765045ab41ee6b (patch)
tree50c3678672c8a33ac49c029bf4382933503fe903 /.bashrc
parent1c7072b2dfa119051e8bd901699a5eaa0893e305 (diff)
downloaddotfiles-8e65740c4e5784fde61c622342765045ab41ee6b.tar
dotfiles-8e65740c4e5784fde61c622342765045ab41ee6b.tar.gz
dotfiles-8e65740c4e5784fde61c622342765045ab41ee6b.zip
fix(bash): Fix of $SHELL in nix develop subshells
Explain in the comment; nix develop changes $SHELL to the non-interactive bash after .bashrc is sourced, so we do a gross hack to fix it
Diffstat (limited to '.bashrc')
-rw-r--r--.bashrc24
1 files changed, 23 insertions, 1 deletions
diff --git a/.bashrc b/.bashrc
index e23e23e..0ea7c66 100644
--- a/.bashrc
+++ b/.bashrc
@@ -4,6 +4,28 @@
# Source global definitions
[ -f /etc/bashrc ] && . /etc/bashrc
+# When running nix develop you get your interactive bash shell, however the
+# $SHELL variable is set to the non-interactive bash
+# This variable change happens after .bashrc sourcing
+# As an awful workaround, only on the first PROMPT_COMMAND after a new shell
+# is started, we check and fix $SHELL
+shell_var_fix() {
+ if [ -x '/run/current-system/sw/bin/bash' ] && \
+ [[ "$SHELL" =~ /nix/store.*-bash-[[:digit:]].* ]]
+ then
+ export SHELL='/run/current-system/sw/bin/bash'
+ fi
+
+ # Don't ever run this function again
+ export PROMPT_COMMAND="${PROMPT_COMMAND#shell_var_fix;}"
+ unset -f shell_var_fix
+}
+# This has a second purpose, to reset PROMPT_COMMAND, since subshells would
+# inherit it from the parent and inside the Prompt we prepend it
+# However, without this workaround, we wouldn't need to prepend in the first
+# place
+export PROMPT_COMMAND="shell_var_fix;"
+
# Prompt {{{
[ "$(tput colors)" -ge 256 ]; _hc=$?
hc_mode() { return $_hc ; }
@@ -190,7 +212,7 @@
# export PS0=" $(left_cap 'o' "$PS_TRIANGLE_BOT") \A$(right_cap)\n\$(kill -s SIGUSR2 $$)"
export PS0="\$(kill -s SIGUSR2 $$)"
- export PROMPT_COMMAND='EXSTAT="$?";seconds="$SECONDS";___changes="";___git_printed="";'$PS_COMM';___dirchanged=''; ___timer="n"'
+ export PROMPT_COMMAND="$PROMPT_COMMAND"'EXSTAT="$?";seconds="$SECONDS";___changes="";___git_printed="";'$PS_COMM';___dirchanged=''; ___timer="n"'
# }}}
# vi mode {{{