__RUSTIMAL=1
export -n PROMPT_COMMAND
__rustimal_first=1
__rustimal_syncpath() {
local f="$RUSTIMAL_STATE/winpath" win="" new
[ -n "$RUSTIMAL_STATE" ] && [ -r "$f" ] || return 0
IFS= read -r win <"$f"
[ -n "$win" ] || return 0
if [ -z "${__rustimal_winpath+x}" ]; then
__rustimal_winpath="$win"
return 0
fi
[ "$win" = "$__rustimal_winpath" ] && return 0
__rustimal_winpath="$win"
new=$(cygpath -u -p "$win" 2>/dev/null) || return 0
[ -n "$new" ] || return 0
if [ -n "$ORIGINAL_PATH" ] && [[ ":$PATH:" == *":$ORIGINAL_PATH:"* ]]; then
PATH=":$PATH:"
PATH="${PATH/":$ORIGINAL_PATH:"/":$new:"}"
PATH="${PATH#:}"
PATH="${PATH%:}"
else
local e parts
IFS=: read -ra parts <<<"$new"
for e in "${parts[@]}"; do
[[ -z "$e" || ":$PATH:" == *":$e:"* ]] || PATH+=":$e"
done
fi
ORIGINAL_PATH="$new"
hash -r
}
__rustimal_prompt() {
local code=$? d="$PWD" head="" chev="35"
__rustimal_syncpath
while :; do
if [ -f "$d/.git/HEAD" ]; then
read -r head <"$d/.git/HEAD"
break
fi
[ -z "$d" ] || [ "$d" = "/" ] && break
d="${d%/*}"
done
case "$head" in
"ref: refs/heads/"*) __rustimal_branch="${head#ref: refs/heads/}" ;;
"") __rustimal_branch="" ;;
*) __rustimal_branch="${head:0:7}" ;;
esac
local p="$PWD" tilde='~'
case "$PWD" in
"$HOME") p="$tilde" ;;
"$HOME"/*) p="$tilde${PWD#"$HOME"}" ;;
esac
case "$p" in
/ | "$tilde") __rustimal_parent="" __rustimal_dir="$p" ;;
*/*) __rustimal_parent="${p%/*}/" __rustimal_dir="${p##*/}" ;;
*) __rustimal_parent="" __rustimal_dir="$p" ;;
esac
[ "$code" -ne 0 ] && chev="31"
printf '\e]2;rustimal:%s\a' "$PWD"
local sep='\n'
if [ -n "$__rustimal_first" ]; then
sep=''
unset __rustimal_first
if [ -n "$RUSTIMAL_HINT" ]; then
unset RUSTIMAL_HINT
printf '\e[90mTip: run \e[0m\e[36mrustimal --install\e[0m\e[90m to add the Start menu, Win+R and right-click entries.\e[0m\n'
fi
fi
PS1="${sep}\[\e[36m\]\${__rustimal_parent}\[\e[1;36m\]\${__rustimal_dir}\[\e[0m\]"
if [ -n "$__rustimal_branch" ]; then
PS1+=" \[\e[90m\]\${__rustimal_branch}\[\e[0m\]"
fi
PS1+=" \[\e[${chev}m\]❯\[\e[0m\] "
__rustimal_armed=1
}
PROMPT_COMMAND=__rustimal_prompt
claude() {
if [ $# -eq 0 ] && [ -t 0 ] && [ -t 1 ]; then
printf '\e]2;__rustimal_pick__:%s\a' "$PWD"
local choice=""
IFS= read -rs choice
case "$choice" in
"") return 0 ;;
new) ;;
*) set -- --resume "$choice" ;;
esac
fi
printf '\e]2;__rustimal_claude__\a\e[H\e[2J'
if [ -n "$RUSTIMAL_CLAUDE_SETTINGS" ] && [ -f "$RUSTIMAL_CLAUDE_SETTINGS" ]; then
set -- --settings "$RUSTIMAL_CLAUDE_SETTINGS" "$@"
fi
command claude "$@"
}
complete -E -o filenames -f 2>/dev/null
bind 'set completion-query-items -1' 2>/dev/null
if [ -z "$(trap -p DEBUG)" ]; then
trap '[ -n "$__rustimal_armed" ] && { __rustimal_armed=; __rustimal_syncpath; }' DEBUG
fi
__rustimal_prompt