From 1576e944ee710e45c322194aafce06991011ba0e Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 8 Jul 2026 04:50:04 -0400 Subject: [PATCH] Dynamic dir-change handling for git probe. --- tcshrc.cmd.cwd | 25 +++++++++++++++++++++++++ tcshrc.prompt.defs | 3 +++ tcshrc.prompt.final | 9 ++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tcshrc.cmd.cwd diff --git a/tcshrc.cmd.cwd b/tcshrc.cmd.cwd new file mode 100644 index 0000000..c86a2e9 --- /dev/null +++ b/tcshrc.cmd.cwd @@ -0,0 +1,25 @@ +#if ( ! $?cshenv_gitdirs ) +set cshenv_gitdirs=( /home/adam/cshenv:/home/adam/cshenv/.git ) + +set _masked_cwd=$cwd:as/ // +#echo "${_masked_cwd}" +set _search_key="${_masked_cwd}" +#echo "${_search_key}" +#echo "dirs $cshenv_gitdirs" +#echo "cache-match $cshenv_gitdirs:as/${_masked_cwd}//" +#echo "cache-match $cshenv_gitdirs:gx/^${_search_key}*/" +#set _cache_match = ( $cshenv_gitdirs:gx^${_search_key}* ) + +#if ( ${#_cache_match} == 1 ) then + #echo "Found ${_cache_match}" +#else + set _git_check=( `git rev-parse --git-dir |&cat` ) + #if ( -d "${_git_check}" ) then + #echo "Found and installed ${_git_check} git dir" + #set _masked_git=$_git_check:as/ // + #set cshenv_dirs=( ${cshenv_dirs} "${_masked_cwd}${masked_git}" ) + #else + #echo "Found no git dir for ${_masked_cwd}" + #set cshenv_dirs=( ${cshenv_dirs} "${_masked_cwd}" ) + #endif +#endif diff --git a/tcshrc.prompt.defs b/tcshrc.prompt.defs index 991b387..a154a26 100644 --- a/tcshrc.prompt.defs +++ b/tcshrc.prompt.defs @@ -139,6 +139,9 @@ _debug "Done building unicode sigils table" alias precmd 'source ${CSHENV_DIR}/tcshrc.prompt.final' #alias postcmd echo doit +# On dir change, check for things, like git dirs. +alias cwdcmd 'source ${CSHENV_DIR}/tcshrc.cmd.cwd' + set promptchars='%#' set prompt_simple="%{${sgr_reset}%}[%n@%m: %c]%# " diff --git a/tcshrc.prompt.final b/tcshrc.prompt.final index cdfacd0..3bf2dda 100644 --- a/tcshrc.prompt.final +++ b/tcshrc.prompt.final @@ -164,8 +164,10 @@ endif set git_prompt="" set git_prefix="" set git_tracking_stat="" -set git_branch=(`git branch --show-current -q |&cat`) -if( ${#git_branch} <= 1 ) then +#set git_branch=(`git branch --show-current -q |&cat`) +if( ${#_git_check} <= 1 ) then + set git_branch_text=( `cat ${_git_check}/HEAD` ) + set git_branch=${git_branch_text[2]:s.refs/heads/..} _debug "We see git branch |${git_branch}|" if( ${#git_branch} == 0 ) then _debug "We see git branch with no elements, clearing..." @@ -178,7 +180,8 @@ if( ${#git_branch} <= 1 ) then if( "${#git_branch}" == 1 ) then _debug "We see git branch |${git_branch[1]}|" _debug "Doing Rev List" - set git_counts=`git rev-list --count --left-right \@\{upstream\}..HEAD|&cat` + _debug "--git-dir=${_git_check}/" + set git_counts=`git --git-dir=${_git_check} rev-list --count --left-right \@\{upstream\}...HEAD|&cat` _debug "Done with Rev List" _debug "Got: ${git_counts}"