From e6616b090470058039219f9bb7165a449d5f7934 Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Sun, 3 Mar 2024 16:18:19 +0100 Subject: [PATCH 1/2] support GITSTATUS_BACKEND = git (unfinished) --- gitstatus.plugin.zsh | 104 ++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/gitstatus.plugin.zsh b/gitstatus.plugin.zsh index b74396d..534f5d4 100644 --- a/gitstatus.plugin.zsh +++ b/gitstatus.plugin.zsh @@ -377,6 +377,61 @@ function _gitstatus_process_response"${1:-}"() { return 0 } +function _gitstatus_backend_gitstatusd"${1:-}"() { + local _gitstatus_zsh_daemon _gitstatus_zsh_version _gitstatus_zsh_downloaded + + function _gitstatus_set_daemon$fsuf() { + _gitstatus_zsh_daemon="$1" + _gitstatus_zsh_version="$2" + _gitstatus_zsh_downloaded="$3" + } + + local gitstatus_plugin_dir_var=_gitstatus_plugin_dir$fsuf + local gitstatus_plugin_dir=${(P)gitstatus_plugin_dir_var} + builtin set -- -d $gitstatus_plugin_dir -s $uname_s -m $uname_m \ + -p "printf '\\001' >&$pipe_fd" -e $pipe_fd -- _gitstatus_set_daemon$fsuf + [[ ${GITSTATUS_AUTO_INSTALL:-1} == (|-|+)<1-> ]] || builtin set -- -n "$@" + builtin source $gitstatus_plugin_dir/install || return + [[ -n $_gitstatus_zsh_daemon ]] || return + [[ -n $_gitstatus_zsh_version ]] || return + [[ $_gitstatus_zsh_downloaded == [01] ]] || return + + if (( UID == EUID )); then + local home=~ + else + local user + user="$(command id -un)" || return + local home=${userdirs[$user]} + [[ -n $home ]] || return + fi + + if [[ -x $_gitstatus_zsh_daemon ]]; then + HOME=$home $_gitstatus_zsh_daemon -G $_gitstatus_zsh_version "${(@)args}" >&$pipe_fd + local -i ret=$? + [[ $ret == (0|129|130|131|137|141|143|159) ]] && return ret + fi + + (( ! _gitstatus_zsh_downloaded )) || return + [[ ${GITSTATUS_AUTO_INSTALL:-1} == (|-|+)<1-> ]] || return + [[ $_gitstatus_zsh_daemon == \ + ${GITSTATUS_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/gitstatus}/* ]] || return + + builtin set -- -f "$@" + _gitstatus_zsh_daemon= + _gitstatus_zsh_version= + _gitstatus_zsh_downloaded= + builtin source $gitstatus_plugin_dir/install || return + [[ -n $_gitstatus_zsh_daemon ]] || return + [[ -n $_gitstatus_zsh_version ]] || return + [[ $_gitstatus_zsh_downloaded == 1 ]] || return + + HOME=$home $_gitstatus_zsh_daemon -G $_gitstatus_zsh_version "${(@)args}" >&$pipe_fd +} + +function _gitstatus_backend_git"${1:-}"() { + +} + function _gitstatus_daemon"${1:-}"() { local -i pipe_fd exec 0<&- {pipe_fd}>&1 1>>$daemon_log 2>&1 || return @@ -412,54 +467,11 @@ function _gitstatus_daemon"${1:-}"() { exec <$file_prefix.fifo || return zf_rm -- $file_prefix.fifo || return - local _gitstatus_zsh_daemon _gitstatus_zsh_version _gitstatus_zsh_downloaded - - function _gitstatus_set_daemon$fsuf() { - _gitstatus_zsh_daemon="$1" - _gitstatus_zsh_version="$2" - _gitstatus_zsh_downloaded="$3" - } - - local gitstatus_plugin_dir_var=_gitstatus_plugin_dir$fsuf - local gitstatus_plugin_dir=${(P)gitstatus_plugin_dir_var} - builtin set -- -d $gitstatus_plugin_dir -s $uname_s -m $uname_m \ - -p "printf '\\001' >&$pipe_fd" -e $pipe_fd -- _gitstatus_set_daemon$fsuf - [[ ${GITSTATUS_AUTO_INSTALL:-1} == (|-|+)<1-> ]] || builtin set -- -n "$@" - builtin source $gitstatus_plugin_dir/install || return - [[ -n $_gitstatus_zsh_daemon ]] || return - [[ -n $_gitstatus_zsh_version ]] || return - [[ $_gitstatus_zsh_downloaded == [01] ]] || return - - if (( UID == EUID )); then - local home=~ + if [[ ${GITSTATUS_BACKEND-} == git ]]; then + _gitstatus_backend_git$fsuf else - local user - user="$(command id -un)" || return - local home=${userdirs[$user]} - [[ -n $home ]] || return + _gitstatus_backend_gitstatusd$fsuf fi - - if [[ -x $_gitstatus_zsh_daemon ]]; then - HOME=$home $_gitstatus_zsh_daemon -G $_gitstatus_zsh_version "${(@)args}" >&$pipe_fd - local -i ret=$? - [[ $ret == (0|129|130|131|137|141|143|159) ]] && return ret - fi - - (( ! _gitstatus_zsh_downloaded )) || return - [[ ${GITSTATUS_AUTO_INSTALL:-1} == (|-|+)<1-> ]] || return - [[ $_gitstatus_zsh_daemon == \ - ${GITSTATUS_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/gitstatus}/* ]] || return - - builtin set -- -f "$@" - _gitstatus_zsh_daemon= - _gitstatus_zsh_version= - _gitstatus_zsh_downloaded= - builtin source $gitstatus_plugin_dir/install || return - [[ -n $_gitstatus_zsh_daemon ]] || return - [[ -n $_gitstatus_zsh_version ]] || return - [[ $_gitstatus_zsh_downloaded == 1 ]] || return - - HOME=$home $_gitstatus_zsh_daemon -G $_gitstatus_zsh_version "${(@)args}" >&$pipe_fd } always { local -i ret=$? zf_rm -f -- $file_prefix.lock $file_prefix.fifo From 7eed50af2aa580965ca8e6153aaf951da8813f5b Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Wed, 20 Mar 2024 11:19:05 +0100 Subject: [PATCH 2/2] wip --- gitstatus.plugin.zsh | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/gitstatus.plugin.zsh b/gitstatus.plugin.zsh index 534f5d4..516cb02 100644 --- a/gitstatus.plugin.zsh +++ b/gitstatus.plugin.zsh @@ -429,7 +429,71 @@ function _gitstatus_backend_gitstatusd"${1:-}"() { } function _gitstatus_backend_git"${1:-}"() { - + local buf req + while true; do + local parts=() + [[ -t 0 ]] # https://www.zsh.org/mla/workers/2020/msg00207.html + if sysread buf; then + parts+=($buf) + while [[ $buf != *$'\x1e' ]]; do + sysread buf || return + parts+=($buf) + done + else + (( $? == 4 )) || return + fi + for req in ${(ps:\x1e:)${(j::)parts}}; do + req=("${(@ps:\x1f:)req}") + (( $#req == 3 )) || return + if [[ $req[2] == :* ]]; then + local opts=(--git-dir=${req[2]#:}) + else + local opts=(-C "${req[2]}") + fi + # VCS_STATUS_WORKDIR + # git rev-parse --show-toplevel + + # VCS_STATUS_COMMIT + # VCS_STATUS_LOCAL_BRANCH + # VCS_STATUS_REMOTE_BRANCH + # VCS_STATUS_REMOTE_NAME + # VCS_STATUS_NUM_STAGED + # VCS_STATUS_NUM_UNSTAGED + # VCS_STATUS_NUM_CONFLICTED + # VCS_STATUS_NUM_UNTRACKED + # VCS_STATUS_COMMITS_AHEAD + # VCS_STATUS_COMMITS_BEHIND + # VCS_STATUS_STASHES + # VCS_STATUS_NUM_UNSTAGED_DELETED + # VCS_STATUS_NUM_STAGED_NEW + # VCS_STATUS_NUM_STAGED_DELETED + # git status --porcelain=v2 --branch --show-stash + + # VCS_STATUS_REMOTE_URL + # git config --get remote.$VCS_STATUS_REMOTE_NAME.url + + # ??? + # VCS_STATUS_INDEX_SIZE + # VCS_STATUS_ACTION + + # VCS_STATUS_TAG + # git describe --exact-match + + + VCS_STATUS_PUSH_REMOTE_NAME \ + VCS_STATUS_PUSH_REMOTE_URL \ + VCS_STATUS_PUSH_COMMITS_AHEAD \ + VCS_STATUS_PUSH_COMMITS_BEHIND \ + VCS_STATUS_NUM_SKIP_WORKTREE \ + VCS_STATUS_NUM_ASSUME_UNCHANGED \ + VCS_STATUS_COMMIT_ENCODING \ + VCS_STATUS_COMMIT_SUMMARY + if (( req[3] )); then + + else + fi + done + done } function _gitstatus_daemon"${1:-}"() {