Skip to content

Commit

Permalink
wipy wip - backup before big re-install
Browse files Browse the repository at this point in the history
  • Loading branch information
burgesQ committed Jun 14, 2023
1 parent ac4dd75 commit 840071f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 30 deletions.
74 changes: 45 additions & 29 deletions sections/dir.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# ------------------------------------------------------------------------------

SPACESHIP_DIR_SHOW="${SPACESHIP_DIR_SHOW=true}"
SPACESHIP_DIR_ASYNC="${SPACESHIP_DIR_ASYNC=true}"
SPACESHIP_DIR_PREFIX="${SPACESHIP_DIR_PREFIX="in "}"
SPACESHIP_DIR_SUFFIX="${SPACESHIP_DIR_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_DIR_TRUNC="${SPACESHIP_DIR_TRUNC=3}"
Expand All @@ -16,6 +17,7 @@ SPACESHIP_DIR_TRUNC_REPO="${SPACESHIP_DIR_TRUNC_REPO=true}"
SPACESHIP_DIR_COLOR="${SPACESHIP_DIR_COLOR="cyan"}"
SPACESHIP_DIR_LOCK_SYMBOL="${SPACESHIP_DIR_LOCK_SYMBOL=""}"
SPACESHIP_DIR_LOCK_COLOR="${SPACESHIP_DIR_LOCK_COLOR="red"}"
SPACESHIP_DIR_SHORT="${SPACESHIP_DIR_SHORT=false}"

# ------------------------------------------------------------------------------
# Section
Expand All @@ -27,45 +29,59 @@ spaceship_dir() {
local dir trunc_prefix

# Threat repo root as a top-level directory or not
#if [[ $SPACESHIP_DIR_TRUNC_REPO == true ]] && spaceship::is_git; then
# local git_root=$(git rev-parse --show-toplevel)
if [[ $SPACESHIP_DIR_TRUNC_REPO == true ]] && spaceship::is_git; then
local git_root=$(git rev-parse --show-toplevel)

# if (cygpath --version) >/dev/null 2>/dev/null; then
# git_root=$(cygpath -u $git_root)
# fi
if (cygpath --version) >/dev/null 2>/dev/null; then
git_root=$(cygpath -u $git_root)
fi

# # Check if the parent of the $git_root is "/"
# if [[ $git_root:h == / ]]; then
# trunc_prefix=/
# else
# trunc_prefix=$SPACESHIP_DIR_TRUNC_PREFIX
# fi
# check if the parent of the $git_root is "/"
if [[ $git_root:h == / ]]; then
trunc_prefix=/
else
trunc_prefix=$SPACESHIP_DIR_TRUNC_PREFIX
fi

# # `${NAME#PATTERN}` removes a leading prefix PATTERN from NAME.
# # `$~~` avoids `GLOB_SUBST` so that `$git_root` won't actually be
# # considered a pattern and matched literally, even if someone turns that on.
# # `$git_root` has symlinks resolved, so we use `${PWD:A}` which resolves
# # symlinks in the working directory.
# # See "Parameter Expansion" under the Zsh manual.
# dir="$trunc_prefix$git_root:t${${PWD:A}#$~~git_root}"
#else
if [[ SPACESHIP_DIR_TRUNC -gt 0 ]]; then
# `%(N~|TRUE-TEXT|FALSE-TEXT)` replaces `TRUE-TEXT` if the current path,
# with prefix replacement, has at least N elements relative to the root
# directory else `FALSE-TEXT`.
# See "Prompt Expansion" under the Zsh manual.
trunc_prefix="%($((SPACESHIP_DIR_TRUNC + 1))~|$SPACESHIP_DIR_TRUNC_PREFIX|)"
fi

dir="$trunc_prefix%${SPACESHIP_DIR_TRUNC}~"
# fi
# `${NAME#PATTERN}` removes a leading prefix PATTERN from NAME.
# `$~~` avoids `GLOB_SUBST` so that `$git_root` won't actually be
# considered a pattern and matched literally, even if someone turns that on.
# `$git_root` has symlinks resolved, so we use `${PWD:A}` which resolves
# symlinks in the working directory.
# See "Parameter Expansion" under the Zsh manual.
dir="$trunc_prefix$git_root:t${${PWD:A}#$~~git_root}"
else
if [[ SPACESHIP_DIR_TRUNC -gt 0 ]]; then
# `%(N~|TRUE-TEXT|FALSE-TEXT)` replaces `TRUE-TEXT` if the current path,
# with prefix replacement, has at least N elements relative to the root
# directory else `FALSE-TEXT`.
# See "Prompt Expansion" under the Zsh manual.
trunc_prefix="%($((SPACESHIP_DIR_TRUNC + 1))~|$SPACESHIP_DIR_TRUNC_PREFIX|)"
fi
dir="$trunc_prefix%${SPACESHIP_DIR_TRUNC}~"
fi

local suffix="$SPACESHIP_DIR_SUFFIX"

if [[ ! -w . ]]; then
suffix="%F{$SPACESHIP_DIR_LOCK_COLOR}${SPACESHIP_DIR_LOCK_SYMBOL}%f${SPACESHIP_DIR_SUFFIX}"
fi

if [[ $SPACESHIP_DIR_SHORT == true ]]; then
local i pwd
pwd=("${(s:/:)PWD/#$HOME/~}")
if (( $#pwd > 4)); then
for i in {1..$(($#pwd-3))}; do
if [[ "$pwd[$i]" = .* ]]; then
pwd[$i]="${${pwd[$i]}[1,2]}"
else
pwd[$i]="${${pwd[$i]}[1]}"
fi
done
fi
dir="${(j:/:)pwd}"
fi

spaceship::section \
--color "$SPACESHIP_DIR_COLOR" \
--prefix "$SPACESHIP_DIR_PREFIX" \
Expand Down
4 changes: 3 additions & 1 deletion sections/git.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SPACESHIP_GIT_SUFFIX="${SPACESHIP_GIT_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}
SPACESHIP_GIT_SYMBOL="${SPACESHIP_GIT_SYMBOL=""}"

if [ -z "$SPACESHIP_GIT_ORDER" ]; then
SPACESHIP_GIT_ORDER=(git_branch git_tag git_status git_diff git_hash git_commit_msg)
SPACESHIP_GIT_ORDER=(git_branch git_tag git_status git_state git_diff git_hash git_commit_msg)
fi

# ------------------------------------------------------------------------------
Expand All @@ -23,6 +23,7 @@ fi
source "$SPACESHIP_ROOT/sections/git_branch.zsh"
source "$SPACESHIP_ROOT/sections/git_tag.zsh"
source "$SPACESHIP_ROOT/sections/git_status.zsh"
source "$SPACESHIP_ROOT/sections/git_state.zsh"
source "$SPACESHIP_ROOT/sections/git_diff.zsh"
source "$SPACESHIP_ROOT/sections/git_hash.zsh"
source "$SPACESHIP_ROOT/sections/git_commit_msg.zsh"
Expand All @@ -31,6 +32,7 @@ source "$SPACESHIP_ROOT/sections/git_commit_msg.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/git_branch.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/git_tag.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/git_status.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/git_state.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/git_diff.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/git_hash.zsh"
spaceship::precompile "$SPACESHIP_ROOT/sections/git_commit_msg.zsh"
Expand Down
62 changes: 62 additions & 0 deletions sections/git_state.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Git status
#

# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------

SPACESHIP_GIT_STATE_SHOW="${SPACESHIP_GIT_STATE_SHOW=false}"
SPACESHIP_GIT_STATE_ASYNC="${SPACESHIP_GIT_STATE_ASYNC=true}"
SPACESHIP_GIT_STATE_PREFIX="${SPACESHIP_GIT_STATE_PREFIX=""}"
SPACESHIP_GIT_STATE_SUFFIX="${SPACESHIP_GIT_STATE_SUFFIX=""}"
SPACESHIP_GIT_STATE_COLOR="${SPACESHIP_GIT_STATE_COLOR="blue"}"
SPACESHIP_GIT_STATE_CHERRY_PICK="${SPACESHIP_GIT_STATE_CHERRY_PICK="cherry_pick"}"
SPACESHIP_GIT_STATE_REBASE="${SPACESHIP_GIT_STATE_REBASE="rebase"}"
SPACESHIP_GIT_STATE_MERGE="${SPACESHIP_GIT_STATE_MERGE="merge"}"
SPACESHIP_GIT_STATE_REVERT="${SPACESHIP_GIT_STATE_REVERT="revert"}"
SPACESHIP_GIT_STATE_BISECT="${SPACESHIP_GIT_STATE_BISECT="bisect"}"
SPACESHIP_GIT_STATE_AM="${SPACESHIP_GIT_STATE_AM="am"}"
SPACESHIP_GIT_STATE_AM_OR_REBASE="${SPACESHIP_GIT_STATE_AM_OR_REBASE="am_or_rebase"}"

# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------

# We used to depend on OMZ git library,
# But it doesn't handle many of the status indicator combinations.
# Also, It's hard to maintain external dependency.
# See PR #147 at https://git.io/vQkkB
# See git help status to know more about status formats
spaceship_git_state() {
[[ $SPACESHIP_GIT_STATE_SHOW == false ]] && return
spaceship::is_git || return

local INDEX=$(command git status 2> /dev/null) git_state=
ec
vcs_info

# appliy/total patch: %n/%a

# thx https://github.com/zsh-users/zsh/blob/master/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
gitaction
VCS_INFO_git_getaction()

git_state="$gitaction"
# # Check for bisect in progress
# # thx: https://stackoverflow.com/questions/37667324/how-do-i-get-the-current-status-of-a-git-bisect
# if $(command git bisect visualize > /dev/null); then
# local tot=$(command git bisect visualize --oneline | wc -l)
# let "left = $tot / 2"
# let step=$(print -v int %.0f `echo "l($left)/l(2)" | bc -l`)

# git_state="$SPACESHIP_GIT_STATE_BISECT ($tot left, rougly $step)$git_state"
# fi

if [[ -n $git_state ]]; then
# Status prefixes are colorized
spaceship::section \
--color "$SPACESHIP_GIT_STATE_COLOR" \
"$SPACESHIP_GIT_STATE_PREFIX$git_state$SPACESHIP_GIT_STATE_SUFFIX"
fi
}

0 comments on commit 840071f

Please sign in to comment.