zsh-workers
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-workers@zsh.org
Subject: [PATCH 10/18] Add helper script to check state of _tmux completion
Date: Mon, 10 Aug 2015 15:27:30 +0200	[thread overview]
Message-ID: <1439213258-14196-11-git-send-email-ft@bewatermyfriend.org> (raw)
In-Reply-To: <1439213258-14196-1-git-send-email-ft@bewatermyfriend.org>

---
 Util/check-tmux-state | 216 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 216 insertions(+)
 create mode 100644 Util/check-tmux-state

diff --git a/Util/check-tmux-state b/Util/check-tmux-state
new file mode 100644
index 0000000..7e29338
--- /dev/null
+++ b/Util/check-tmux-state
@@ -0,0 +1,216 @@
+#!/bin/zsh -f
+
+# Tmux has lots of options and sub-commands. It's very tedious to manually
+# check if the actual command's idea of all this matches the completion
+# function. So this is a helper script that automates checking the state of
+# _tmux.
+#
+# You need to call it like this, with a running tmux server:
+#
+# zsh -f check-tmux-state <path-to-tmux-binary> <path-to-_tmux-function>
+#
+# The script will tell you the differences in available and supported
+# sub-commands, command aliases, server options, session options and
+# window-options.
+#
+# It also checks if options have moved from one scope to another. If this
+# happens, then the option in question also appears in the "new/old" listings
+# of the involved scopes. First fix the scope changes, then the "new/old" lists
+# are accurate.
+
+emulate zsh
+setopt extended_glob null_glob no_octal_zeroes
+
+if (( $#argv != 2 )); then
+    printf 'usage: zsh -f check-tmux-state <tmux-binary> <_tmux-function>\n'
+    exit 1
+fi
+
+printf ' -!- Checking status of _tmux completion function definition -!-\n'
+
+autoload -Uz colors
+colors
+
+tmux=$1
+func=$2
+
+differences=none
+
+# We'll source the _tmux file and call a bunch of its functions to gather
+# information. For that, we need to put a few stubs into place so sourcing the
+# file doesn't blow up in our face.
+
+function _arguments () { }
+function _describe () { }
+function local () { }
+
+typeset -A rev
+
+source $func
+__tmux-server-options
+__tmux-session-options
+__tmux-window-options
+
+# Subcommand helper functions are defined like "function _tmux-foo() {"
+# in the _tmux function definition file.
+typeset -a supported_commands
+supported_commands=( $( grep 'function *\<_tmux-' $func |
+                        sed -e 's,^.*\<_tmux-,,' -e 's,(.*$,,' ) )
+
+# Ask tmux for available commands:
+typeset -a available_commands
+available_commands=( $( $tmux list-commands | cut -f1 -d' ' ) )
+
+# Ask tmux for available aliases:
+typeset -A available_aliases
+available_aliases=( $( $tmux list-commands |
+                       grep '^[a-z-]* *(' |
+                       sed -e 's,^\([a-z-]*\) *(\([a-z-]*\))\(.*\)$,\2 \1,' ) )
+
+# Gather information about options:
+typeset -a supported_session_options
+supported_session_options=( ${"${tmux_session_options[@]}"%%:*} )
+typeset -a available_session_options
+available_session_options=( $( $tmux show-options -g | cut -f1 -d' ' ) )
+
+typeset -a available_server_options
+supported_server_options=( ${"${tmux_server_options[@]}"%%:*} )
+typeset -a supported_server_options
+available_server_options=( $( $tmux show-options -s -g | cut -f1 -d' ' ) )
+
+typeset -a supported_window_options
+supported_window_options=( ${"${tmux_window_options[@]}"%%:*} )
+typeset -a available_window_options
+available_window_options=( $( $tmux show-options -w -g | cut -f1 -d' ' ) )
+
+typeset -a supported available
+
+function find_new () {
+    local i
+    new=()
+    for i in "${available[@]}"; do
+        [[ -z ${supported[(r)$i]} ]] && new+=( $i )
+    done
+}
+
+function find_old () {
+    local i
+    old=()
+    for i in "${supported[@]}"; do
+        [[ -z ${available[(r)$i]} ]] && old+=( $i )
+    done
+}
+
+function compare_sets() {
+    name=$1
+    local -a old new
+    new=()
+    old=()
+    find_old
+    find_new
+    if (( $#old > 0 )) || (( $#new > 0 )); then
+        printf '\n%sDifferences with %s:%s\n' ${fg[yellow]} $name $reset_color
+        differences=some
+        if (( $#new > 0 )); then
+            printf '%sNew:%s' ${fg[green]} $reset_color
+            printf ' %s' "${new[@]}"
+            printf '\n'
+        fi
+        if (( $#old > 0 )); then
+            printf '%sOld:%s' ${fg[red]} $reset_color
+            printf ' %s' "${old[@]}"
+            printf '\n'
+        fi
+    fi
+}
+
+function find_changed_scope() {
+    name=$1
+    local -a changes
+    local i av
+    changes=()
+    for i in "${supported[@]}"; do
+        av=${available[(r)$i]}
+        [[ -n $av ]] && changes+=( $av )
+    done
+    if (( $#changes > 0 )); then
+        differences=some
+        printf '\n%sDifferences with scope %s:%s\n' \
+               ${fg[yellow]} $name $reset_color
+        printf '%sChanged:%s' ${fg[green]} $reset_color
+        printf ' %s' "${changes[@]}"
+        printf '\n'
+    fi
+}
+
+supported=( "${supported_session_options[@]}" )
+available=( "${available_server_options[@]}" )
+find_changed_scope 'session=>server'
+
+supported=( "${supported_server_options[@]}" )
+available=( "${available_session_options[@]}" )
+find_changed_scope 'server=>session'
+
+supported=( "${supported_window_options[@]}" )
+available=( "${available_session_options[@]}" )
+find_changed_scope 'window=>session'
+
+supported=( "${supported_session_options[@]}" )
+available=( "${available_window_options[@]}" )
+find_changed_scope 'session=>window'
+
+supported=( "${supported_window_options[@]}" )
+available=( "${available_server_options[@]}" )
+find_changed_scope 'window=>server'
+
+supported=( "${supported_server_options[@]}" )
+available=( "${available_window_options[@]}" )
+find_changed_scope 'server=>window'
+
+supported=( "${supported_commands[@]}" )
+available=( "${available_commands[@]}" )
+compare_sets commands
+
+supported=( "${supported_session_options[@]}" )
+available=( "${available_session_options[@]}" )
+compare_sets session_options
+
+supported=( "${supported_server_options[@]}" )
+available=( "${available_server_options[@]}" )
+compare_sets server_options
+
+supported=( "${supported_window_options[@]}" )
+available=( "${available_window_options[@]}" )
+compare_sets window_options
+
+typeset -a alias_messages
+for i in "${(k)_tmux_aliasmap[@]}"; do
+    su=${_tmux_aliasmap[$i]}
+    av=${available_aliases[$i]}
+    if [[ -z $av ]]; then
+        alias_messages+=( "${fg[red]}Old alias${reset_color}: $i ($su)" )
+    elif [[ $av != $su ]]; then
+        alias_messages+=( "Changed alias $i: is ($av) was ($su)" )
+    fi
+done
+for i in "${(k)available_aliases[@]}"; do
+    su=${_tmux_aliasmap[$i]}
+    av=${available_aliases[$i]}
+    if [[ -z $su ]]; then
+        alias_messages+=( "${fg[green]}New alias${reset_color}: $i ($av)" )
+    fi
+done
+if (( $#alias_messages > 0 )); then
+    differences=some
+    printf '\n%sDifferences with %s:%s\n' ${fg[yellow]} "aliases" $reset_color
+    for i in "${alias_messages[@]}"; do
+        printf '%s\n' $i
+    done
+fi
+
+if [[ $differences == none ]]; then
+    printf '\n... _tmux seems to be up to date!\n'
+else
+    printf '\n'
+fi
+exit 0
-- 
2.1.4


  parent reply	other threads:[~2015-08-10 13:35 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-10 13:27 [PATCH 00/18] Updates for _tmux Frank Terbeck
2015-08-10 13:27 ` [PATCH 01/18] _tmux: Update command line options Frank Terbeck
2015-08-10 13:27 ` [PATCH 02/18] _tmux: Update options for supported commands Frank Terbeck
2015-08-10 13:27 ` [PATCH 03/18] _tmux: Add support for new sub-commands Frank Terbeck
2015-08-10 13:27 ` [PATCH 04/18] _tmux: Remove dead code Frank Terbeck
2015-08-10 13:27 ` [PATCH 05/18] _tmux: Don't unset, set empty in local scope Frank Terbeck
2015-08-10 13:27 ` [PATCH 06/18] _tmux: No need to unset local variables Frank Terbeck
2015-08-10 13:27 ` [PATCH 07/18] _tmux: Replay all arguments when dispatching to new _tmux() Frank Terbeck
2015-08-10 13:27 ` [PATCH 08/18] _tmux: "local -x" serves no purpose Frank Terbeck
2015-08-10 13:27 ` [PATCH 09/18] _tmux: options => session_options Frank Terbeck
2015-08-10 13:27 ` Frank Terbeck [this message]
2015-08-10 15:20   ` wrapping "local" (was: Re: [PATCH 10/18] Add helper script to check state of _tmux completion) Frank Terbeck
2015-08-10 15:32     ` Peter Stephenson
2015-08-10 15:50       ` [PATCH] Disable ‘local’ keyword in script to make data retrieval work Frank Terbeck
2015-08-10 13:27 ` [PATCH 11/18] _tmux: Remove old sub-commands and their aliases Frank Terbeck
2015-08-10 13:27 ` [PATCH 12/18] _tmux: Add new command aliases Frank Terbeck
2015-08-10 13:27 ` [PATCH 13/18] _tmux: Fix options with changed scope Frank Terbeck
2015-08-10 13:27 ` [PATCH 14/18] _tmux: Remove support for old options Frank Terbeck
2015-08-10 13:27 ` [PATCH 15/18] _tmux: Add new session options Frank Terbeck
2015-08-10 13:27 ` [PATCH 16/18] _tmux: Add support for new server options Frank Terbeck
2015-08-10 13:27 ` [PATCH 17/18] _tmux: Add support for new window options Frank Terbeck
2015-08-10 13:27 ` [PATCH 18/18] _tmux: Update TODO Frank Terbeck
2015-08-10 13:52 ` [PATCH 00/18] Updates for _tmux Peter Stephenson
2015-08-10 14:46 ` [PATCH 19/18] _tmux: Update bell-action and prefix options Frank Terbeck
2015-08-10 14:46   ` [PATCH 20/18] _tmux: Fix \ooo display in completion list Frank Terbeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439213258-14196-11-git-send-email-ft@bewatermyfriend.org \
    --to=ft@bewatermyfriend.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).