79 lines
1.8 KiB
Bash
Executable file
79 lines
1.8 KiB
Bash
Executable file
# Function to clean up and normalize paths
|
|
path_print_clean() {
|
|
local var=${1:-PATH}
|
|
local arr
|
|
local newarr=()
|
|
local path
|
|
local p
|
|
|
|
# Read PATH into an array
|
|
IFS=: read -r -a arr <<<"${!var}:"
|
|
|
|
# Declare an associative array to keep track of seen paths
|
|
declare -A seen
|
|
|
|
for p in "${arr[@]}"; do
|
|
# Empty element is equivalent to CWD (weird, I know), remove it
|
|
if [[ -z $p ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Remove any relative paths
|
|
if [[ ${p:0:1} != '/' ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Normalize path and ensure we can access it
|
|
path=$(cd "$p" &>/dev/null && pwd)
|
|
|
|
# Path doesn't exist or we can't access it
|
|
if [[ -z $path ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Filter out dups while we are here
|
|
if [[ -n ${seen[$path]} ]]; then
|
|
continue
|
|
fi
|
|
seen[$path]=true
|
|
|
|
# Store the new path
|
|
newarr+=("$path")
|
|
done
|
|
|
|
local IFS=:
|
|
echo "${newarr[*]}"
|
|
}
|
|
|
|
# Function to clean up the PATH variable
|
|
path_clean() {
|
|
local path
|
|
path=$(path_print_clean) || return 1
|
|
# Use eval to correctly assign the cleaned path to the PATH variable
|
|
export PATH="$path"
|
|
}
|
|
|
|
# Load bash completion
|
|
if [[ -f /etc/bash_completion ]]; then
|
|
. /etc/bash_completion
|
|
fi
|
|
|
|
# Custom aliases
|
|
alias python="python3"
|
|
alias grep="grep --color=auto"
|
|
|
|
if [[ -f "$HOME/.local/bin/scripts/check_aliases" ]]; then
|
|
. "$HOME/.local/bin/scripts/check_aliases"
|
|
fi
|
|
|
|
# Set the default editor
|
|
export EDITOR='nvim'
|
|
|
|
# Add eza completions to BASH_COMPLETION
|
|
[[ ! "$BASH_COMPLETION" =~ (^|:)${HOME}/.local/bin/eza/completions/bash(:|$) ]] && export BASH_COMPLETION="$HOME/.local/bin/eza/completions/bash:$BASH_COMPLETION"
|
|
|
|
# Initialize zoxide
|
|
eval "$(zoxide init bash)"
|
|
|
|
path_clean
|
|
|