Score:1

Why is my bash script not being sourced when opening new tmux pane?

cx flag

The following logic in .bash_aliases to remove duplicate paths works fine when opening a new terminal:

# prune duplicate paths
PATHS=("PATH" "LD_LIBRARY_PATH" "C_INCLUDE_PATH")
for P in "${PATHS[@]}"; do
    source $HOME/bin/prune_paths $P
done

~/bin/prunepaths

#!/bin/bash

path_name=$1
curr_paths=${!path_name}

# split paths string into an array of paths
IFS=':' read -ra path_array <<< "$curr_paths"

# filter out duplicates and elements containing single quotes
declare -a unique_path_array=()
for element in "${path_array[@]}"; do
    if [[ ! " ${unique_path_array[@]} " =~ " ${element} " ]] && [[ ! "$element" =~ "'" ]]; then
        unique_path_array+=("$element")
    fi
done

# concatenate unique paths
final_paths=$(IFS=':'; echo "${unique_path_array[*]}")

export $path_name=$final_paths

However, when I start tmux or open a new pane it duplicates exports.
The following example export done before the above loop:

export PATH=$HOME/bin:$HOME/.local/bin:$PATH

Results in:

/home/bob/.local/bin
/home/bob/bin
/home/bob/bin
/home/bob/.local/bin
...

If I re-source .bash_aliases the duplicates are removed.
It never creates more than one duplicate of each path.

Any ideas about what's going on or suggestions for how I can track down the issue would be much appreciated.

Score:1
cx flag

I found the answer right after posting but will leave it up in case anyone needs it.

Put the following line in your .tmux.conf:

set-option -g default-command bash
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.