Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(zsh): prompt improvement #283

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions zsh/config.d/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ function current_context () {
return
fi

echo "[%{$fg_bold[blue]%}$current_context%{${reset_color}%}]"
echo "[$fg_bold[blue]$current_context$reset_color]"
}

function current_path () {
echo "[%{${fg_bold[yellow]}%}%~%{${reset_color}%}]"
echo "[$fg_bold[yellow]%~$reset_color]"
}

function current_timestamp () {
echo "[%{$fg_bold[green]%}$(date +'%H:%M:%S')%{${reset_color}%}]"
echo "[$fg_bold[green]$(date +'%H:%M:%S')$reset_color]"
}

function parse_git_branch() {
Expand All @@ -200,36 +200,37 @@ function parse_git_branch() {
function current_git_status () {
local git_branch="$(parse_git_branch)"

if [ -n "$git_branch" ]; then
STATUS="$fg[red]@${${git_branch}#(refs/heads/|tags/)}${reset_color}"

UNTRACK_STATUS=""
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
UNTRACK_STATUS+="%{$fg[red]%}●%{$reset_color%}"
fi

if ! git diff --quiet 2> /dev/null; then
UNTRACK_STATUS+="%{$fg[yellow]%}●%{$reset_color%}"
fi
if [ -z "$git_branch" ]; then
echo ""
return
fi

if ! git diff --cached --quiet 2> /dev/null; then
UNTRACK_STATUS+="%{$fg[green]%}●%{$reset_color%}"
fi
UNTRACK_STATUS=""
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
UNTRACK_STATUS+="$fg_bold[red]u$reset_color"
fi

STATUS="["$STATUS"]"
if ! git diff --quiet 2> /dev/null; then
UNTRACK_STATUS+="$fg_bold[yellow]e$reset_color"
fi

if [ -n "$UNTRACK_STATUS" ]; then
STATUS=$STATUS"["$UNTRACK_STATUS"]"
fi
if ! git diff --cached --quiet 2> /dev/null; then
UNTRACK_STATUS+="$fg_bold[green]s$reset_color"
fi

echo $STATUS
STATUS="$fg_bold[red]${${git_branch}#(refs/heads/|tags/)}$reset_color"
if [ -n "$UNTRACK_STATUS" ]; then
echo "[$UNTRACK_STATUS$fg_bold[gray]@$STATUS$reset_color]"
else
echo "[$fg_bold[bold]@$STATUS$reset_color]"
fi

}

PROMPT='$(current_timestamp)$(current_platform)$(current_context)$(current_path)$(current_git_status)'
PROMPT+=$'\n'
PROMPT+='> '
SPROMPT="%{${fg[red]}%}%r is correct? [y, n, a, e]:%{${reset_color}%}"
SPROMPT="${fg[red]}%r$reset_color is correct? [y, n, a, e]:"

if command -v fzf > /dev/null; then
source <(fzf --zsh)
Expand Down
Loading