#!/usr/bin/env rexx /* Change the current Konsole session name to match the last node of the path. */ /* This program is called by bash script kcd, which performs the cd operation first; */ /* rexx cannot permanently change the current directory to another. */ /* .-------------------------------------------------------------------------------. */ /* | Change Log | */ /* |Version Date Description | */ /* |------- ---------- ------------------------------------------------------------| */ /* | | */ /* |1.0 2023-09-01 Creation | */ /* '-------------------------------------------------------------------------------' */ /* N.B. Root sessions seem to always set RC = 1 for every command, so this program */ /* checks for messages to determine if a failure has occurred. */ trace normal /* Define collections for collecting command output. */ bash. = ''; bash.0 = 0 message. = ''; message.0 = 0 DCOPsession = .Array ~ new /* Route commands to bash and their outputs into program storage. */ address 'bash' with output replace stem bash. error replace stem message. /* Make sure that the official commands are being used. */ dcop = '/opt/trinity/bin/dcop' tty = '/usr/bin/tty' who = '/usr/bin/who' /* Process the input argument. */ parse arg path path = strip(path) path = strip(path,trailing,'/') /* Leave off /home/ if the path is to the home directory. */ if left(path,6) = '/home/' then path = subStr(path,7) /* Use only the last node of the path for the new session name. */ if lastPos('/',path) > 0 then -- there is more than one. parse var path =(lastPos('/',Path,)+1) newName . else -- there is only one. parse var path newName /* Get this terminal's device number. */ call cmd tty parse var bash.1 '/dev/' thisTerminal /* See who owns this terminal. */ call cmd who loop B = 1 to bash.0 until terminal = thisTerminal parse var bash.B owner terminal . end /* Get the session name of the owner's DCOP DCOPsession. */ /* (An array is used to make it easier to bypass the header line.) */ address 'bash' dcop '--user' owner '--list-sessions' with output replace using (DCOPsession) DCOPsession ~ delete(1) -- Discard the header. /* There might be more than one session to talk to. */ loop D = 1 to DCOPsession ~ items /* Get the name(s) of the konsole instance(s). */ call cmd dcop '--user' owner '--session' DCOPsession[D] "'konsole*'" /* Save the output so that bash. may be reused. */ loop B = 1 to bash.0 K = B konsoleSession.K = bash.B konsoleSession.0 = K end /* Find the active Konsole session. */ loop K = 1 to konsoleSession.0 call cmd dcop '--user' owner '--session' DCOPsession[D] konsoleSession.K "'konsole-mainwindow#*'" mainWindow = bash.1 call cmd dcop '--user' owner '--session' DCOPsession[D] konsoleSession.K mainWindow 'isActiveWindow' if bash.1 = 'false' then iterate K /* Find the ID of the current session (tab). */ call cmd dcop '--user' owner '--session' DCOPsession[D] konsoleSession.K 'konsole currentSession' sessionID = bash.1 /* Rename the session (tab). */ call cmd dcop '--user' owner '--session' DCOPsession[D] konsoleSession.K sessionID 'renameSession' newName leave D end end exit 0 cmd: procedure expose message. bash. trace normal parse arg commandString commandString if message.0 = 0 then return loop M = 1 to message.0 say message.M end exit 1