# Format current directory with substitutions and truncation
function _prompt_directory
    set -l dir (pwd | string replace $HOME "~")

    for sub in $prompt_dir_substitutions
        set -l parts (string split ":" $sub)
        set -l name $parts[1]
        set -l icon $parts[2]
        set dir (string replace -a "/$name" "/$icon" $dir)
        set dir (string replace "^$name" "$icon" $dir)
    end

    if test $prompt_dir_truncation -gt 0
        set -l parts (string split "/" $dir)
        if test (count $parts) -gt $prompt_dir_truncation
            set parts "…" $parts[(math 2 - $prompt_dir_truncation)..-1]
        end
        set dir (string join "/" $parts)
    end

    echo $dir
end
