1

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.

Jeff_V
  • 21
  • 2

1 Answers1

1

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
Jeff_V
  • 21
  • 2