#!/bin/sh
# Konsole Information reporter
# This is work-in-progress to support a konsole-switcher
# application that allows you to use cmd-line patterns to
# warp back to any particular konsole window and konsole
# session tab running on your desktop.

# e.g.
#    konswitch dpg-server
#      Found:
#       1) ssh dpg-server
#       2) vim dpg-server.config
#       select ?

is_debug() { [ "$DEBUG" = 1 ] ;}
debug() { is_debug && echo "DEBUG: $@" 1>&2 ;}

for kon in $(dcop konsole\*); do
  echo "-------------------------"
  koncur=$(dcop ${kon} konsole currentSession)
  debug koncur=${koncur}
  sessnames=""

  echo "name==[$(dcop ${kon} konsole-mainwindow#1 name)]"
  echo "caption==[$(dcop ${kon} konsole-mainwindow#1 caption)]"
  echo "windowid==[$(dcop ${kon} konsole-mainwindow#1 getWinID)]"


#  for konsess in $(seq 1 $(dcop ${kon} konsole sessionCount )); do
  for konsess in $(dcop ${kon} | grep '^session-' ); do
    debug konsess=${konsess}
    sessnames="${sessnames} $(dcop ${kon} ${konsess} sessionName)"
    if [ "${konsess}" == ${koncur} ]; then
      echo "${kon}:${konsess}:*Name=$(dcop ${kon} ${konsess} sessionName)"
    else
      echo "${kon}:${konsess}: Name=$(dcop ${kon} ${konsess} sessionName)"
    fi
  done
#  echo "Session Names are: ${sessnames}"
done

#dcop konsole-3570 session-2 sessionName

exit 0

: << END_NOTES

dowdy@debian:~$ koninfo
konsole-3657:1: Name=Shell
konsole-19416:1: Name=Shell
konsole-19431:1: Name=Shell
konsole-19431:2: Name=Shell No. 2
konsole-3688:1: Name=VPN
konsole-3688:2: Name=root@das-ingest

END_NOTES
