diff --git a/zc-ls b/zc-ls new file mode 100644 index 0000000..975cb71 --- /dev/null +++ b/zc-ls @@ -0,0 +1,38 @@ +setopt localoptions extendedglob clobber + +integer idx is_locked +local name busyfile busywith + +for (( idx = 1; idx <= 100; idx ++ )); do + name="" + busywith="" + + __zconvey_is_session_active "$idx" && is_locked=1 || is_locked=0 + + __zconvey_get_name_of_id "$idx" + name="$REPLY" + + busyfile="$ZCONVEY_OTHER_DIR/${idx}.busy" + [[ -e "$busyfile" && "$idx" != "$ZCONVEY_ID" ]] && busywith=" \033[1;33m(BUSY: $(<$busyfile))\033[0m" + + if [[ "$is_locked" = "0" && -n "$name" ]]; then + print "\033[1;31m(ABSENT)\033[0m ID: $idx, NAME: $name" + elif [[ "$is_locked" = "0" && -z "$name" ]]; then + # Don't inform about absent, nameless sessions + : + elif [[ "$is_locked" = "1" && -z "$name" ]]; then + if [ "$idx" = "$ZCONVEY_ID" ]; then + print "\033[1;32m\033[4m(CURRENT) ID: $idx\033[0m$busywith" + else + print "\033[1;33m(ON-LINE)\033[0m ID: $idx$busywith" + fi + elif [[ "$is_locked" = "1" && -n "$name" ]]; then + if [ "$idx" = "$ZCONVEY_ID" ]; then + print "\033[1;32m\033[4m(CURRENT) ID: $idx, NAME: $name\033[0m$busywith" + else + print "\033[1;33m(ON-LINE)\033[0m ID: $idx, NAME: $name$busywith" + fi + fi +done + +# vim:ft=zsh diff --git a/zconvey.plugin.zsh b/zconvey.plugin.zsh index f558c60..22d8c83 100644 --- a/zconvey.plugin.zsh +++ b/zconvey.plugin.zsh @@ -22,7 +22,7 @@ fi # # Autoloads # -autoload zc zc-rename zc-take +autoload zc zc-rename zc-take zc-ls # # Global variables @@ -115,44 +115,6 @@ function __zconvey_is_session_active() { # User functions # -function zc-ls() { - setopt localoptions extendedglob clobber - integer idx is_locked - local name busyfile busywith - - for (( idx = 1; idx <= 100; idx ++ )); do - name="" - busywith="" - - __zconvey_is_session_active "$idx" && is_locked=1 || is_locked=0 - - __zconvey_get_name_of_id "$idx" - name="$REPLY" - - busyfile="$ZCONVEY_OTHER_DIR/${idx}.busy" - [[ -e "$busyfile" && "$idx" != "$ZCONVEY_ID" ]] && busywith=" \033[1;33m(BUSY: $(<$busyfile))\033[0m" - - if [[ "$is_locked" = "0" && -n "$name" ]]; then - print "\033[1;31m(ABSENT)\033[0m ID: $idx, NAME: $name" - elif [[ "$is_locked" = "0" && -z "$name" ]]; then - # Don't inform about absent, nameless sessions - : - elif [[ "$is_locked" = "1" && -z "$name" ]]; then - if [ "$idx" = "$ZCONVEY_ID" ]; then - print "\033[1;32m\033[4m(CURRENT) ID: $idx\033[0m$busywith" - else - print "\033[1;33m(ON-LINE)\033[0m ID: $idx$busywith" - fi - elif [[ "$is_locked" = "1" && -n "$name" ]]; then - if [ "$idx" = "$ZCONVEY_ID" ]; then - print "\033[1;32m\033[4m(CURRENT) ID: $idx, NAME: $name\033[0m$busywith" - else - print "\033[1;33m(ON-LINE)\033[0m ID: $idx, NAME: $name$busywith" - fi - fi - done -} - function zc-id() { __zconvey_get_name_of_id "$ZCONVEY_ID" if [ -z "$REPLY" ]; then