# Actions for using mshelltools for command manipulation # for killing the process groups, you can use a myesno as follows: # precmd="if myesno -text \\"kill \\\$cmd\\" \ # -title \\"kill \\\$cmd\\"; \ # then kill -TERM \\\$setsid_GROUP; fi"; \ # suicide="sleep 1; kill -TERM \\\$setsid_GROUP"; \ # ... # or a mmenu: # precmd="case \\`mmenu -text \\"kill \\\$cmd\\" \ # -title \\"kill \\\$cmd\\" \ # -rows 1 \ # Yes No \\"kill -KILL\\" \\` in \ # 1) echo \\"\\"; \ # echo === kill -TERM: \ # \\"\\\$cmd\\" ===; \ # kill -TERM \\\$setsid_GROUP ;; \ # 3) echo \\"\\"; \ # echo === kill -KILL: \ # \\"\\\$cmd\\" ===; \ # kill -KILL \\\$setsid_GROUP ;; \ # esac"; \ # suicide="sleep 1; echo \\"\\"; \ # echo === DONE: \\"\\\$cmd\\" ===; \ # kill -TERM \\\$setsid_GROUP"; \ # ... # The "sleep 1" is just to make sure that if the user command starts a # background job, it has time to start properly before the kill is executed # on the process group. # Run for list widget output ACTION RunCommandList { DESCRIPTION Uses mprompt to ask for a command string, \ outputting stdout and stderr to mlist. EXEC_STRING sh -c \ 'shell=\$SHELL; \ suicide="sleep 1; kill -TERM \\\$setsid_GROUP"; \ if [ -f $HOME/.dt/.RunActionShell ]; \ then \ shell="`cat $HOME/.dt/.RunActionShell`"; \ shellp=""; \ else shell="/bin/bash"; shellp=""; \ fi; \ shellname=`basename \$shell`; \ shell="\$shell \$shellp"; \ colours=""; user=""; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then shell="sh_as_user \ -u root \ -f $HOME/.dt/.RunActionUser \ - \$shell"; \ colours="-bg red -fg yellow"; \ user="(root) "; \ fi; \ fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ cd \$exd; \ if [ -z "`echo \$ff`" ]; then cd; fi; \ mprompt \$colours \ -specfont 7x13 \ -text "Run \$shellname in `pwd`" \ -title "\${user}Run (list) Command" \ -autoicon -icontitle "Run" \ -defaultstring " \$ff" -noexit | \ while read cmd; do \ export cmd; \ ( ( (setsid \ /bin/sh -c "( ( (\$shell -c \\\"\\\$cmd\\\"); \ \$suicide) \ 2>&1 < /dev/null &); \ \$precmd"; \ echo " ") | \ expand | \ mlist -specfont 7x13 -pb2label "" \ -xrm "*XmList*highlightThickness: 0" \ -xrm "*listSpacing: 4" \ -title "Command Output: \$cmd" -list 10) \ 2>&1 & ); \ done' WINDOW_TYPE NO_STDIO ICON runner } ACTION HistRunCommand { DESCRIPTION Uses mprompt to ask for a command string, \ outputting stdout and stderr to mlist. EXEC_STRING sh -c \ 'shell=\$SHELL; \ precmd="if myesno -text \\"kill \\\$cmd\\" \ -title \\"kill \\\$cmd\\"; \ then kill -TERM \\\$setsid_GROUP; fi"; \ suicide="sleep 1; kill -TERM \\\$setsid_GROUP"; \ if [ -f $HOME/.dt/.RunActionShell ]; \ then \ shell="`cat $HOME/.dt/.RunActionShell`"; \ shellp=""; \ else shell="/bin/bash"; shellp=""; \ fi; \ shellname=`basename \$shell`; \ shell="\$shell \$shellp"; \ colours=""; user=""; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then shell="sh_as_user \ -u root \ -f $HOME/.dt/.RunActionUser \ - \$shell"; \ colours="-bg red -fg yellow"; \ user="(root) "; \ fi; \ fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ cd \$exd; \ if [ -z "`echo \$ff`" ]; then cd; fi; \ cat /dev/null | \ mselect \$colours \ -addselect -select 3 \ -specfont 7x13 \ -selectlabel "Run \$shellname in `pwd`" \ -title "\${user}Run Command" \ -autoicon -icontitle "Run" \ -defaultstring " \$ff" -noexit | \ while read cmd; do \ export cmd; \ ( ( (setsid \ /bin/sh -c "( ( (\$shell -c \\\"\\\$cmd\\\"); \ \$suicide) \ 2>&1 < /dev/null &); \ \$precmd"; \ echo " ") | \ expand | \ mlist -specfont 7x13 -pb2label "" \ -xrm "*XmList*highlightThickness: 0" \ -xrm "*listSpacing: 4" \ -title "Command Output: \$cmd" -list 10) \ 2>&1 & ); \ done' WINDOW_TYPE NO_STDIO ICON runner } ACTION RunList { TYPE MAP MAP_ACTION RunCommandList ICON runner } # for Text widget output ACTION RunCommandDisplay { DESCRIPTION Uses mprompt to ask for a command string, \ outputting stdout and stderr to mdisplay. EXEC_STRING sh -c \ 'shell=\$SHELL; \ precmd="if myesno -text \\"kill \\\$cmd\\" \ -title \\"kill \\\$cmd\\"; \ then kill -TERM \\\$setsid_GROUP; fi"; \ suicide="sleep 1; kill -TERM \\\$setsid_GROUP"; \ if [ -f $HOME/.dt/.RunActionShell ]; \ then \ shell="`cat $HOME/.dt/.RunActionShell`"; \ shellp=""; \ else shell="/bin/bash"; shellp=""; \ fi; \ shellname=`basename \$shell`; \ shell="\$shell \$shellp"; \ colours=""; user=""; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then shell="sh_as_user \ -u root \ -f $HOME/.dt/.RunActionUser \ - \$shell"; \ colours="-bg red -fg yellow"; \ user="(root) "; \ fi; \ fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ cd \$exd; \ if [ -z "`echo \$ff`" ]; then cd; fi; \ mprompt \$colours \ -specfont 7x13 \ -text "Run \$shellname in `pwd`" \ -title "\${user}Run (text) Command" \ -autoicon -icontitle "Run Txt" \ -defaultstring " \$ff" -noexit | \ while read cmd; do \ export cmd; \ ( ( (setsid \ /bin/sh -c "( ( (\$shell -c \\\"\\\$cmd\\\"); \ \$suicide) \ 2>&1 < /dev/null &); \ \$precmd") | \ mdisplay -specfont 7x13 -pb2label "" \ -xrm "*XmText*highlightThickness: 0" \ -title "Command Output: \$cmd" \ -columns 80 -rows 20 -frompipe) \ 2>&1 > /dev/null & ); \ done' WINDOW_TYPE NO_STDIO ICON runner } # for Text widget output ACTION RunCommandDisplaySmall { DESCRIPTION Uses mprompt to ask for a command string, \ outputting stdout and stderr to mdisplay. EXEC_STRING sh -c ' \ exd=`pwd`; shell=\$SHELL; \ : precmd="if myesno -text \\"kill \\\$cmd\\" \ : -title \\"kill \\\$cmd\\"; \ : then kill -TERM \\\$setsid_GROUP; fi"; \ precmd="case \\`mmenu -text \\"kill \\\$cmd\\" \ -title \\"kill \\\$cmd\\" \ -rows 1 \ \\"(No kill)\\" \ \\"kill -TERM (15)\\" \ \\"kill -KILL (9)\\" \\` in \ 2) echo \\"\\"; \ echo === kill -TERM: \ \\"\\\$cmd\\" ===; \ kill -TERM \\\$setsid_GROUP ;; \ 3) echo \\"\\"; \ echo === kill -KILL: \ \\"\\\$cmd\\" ===; \ kill -KILL \\\$setsid_GROUP ;; \ *) : echo \\"\\"; \ : echo === no kill: \ \\"\\\$cmd\\" === ;; \ esac"; \ : - options for the mmenu RowColumn above: \ : -xrm \\"*packing: pack_column\\" \ : -xrm \\"*numColumns: 3\\" ; \ : -xrm \\"*orientation: vertical\\" \ : ; \ suicide="sleep 1; echo \\"\\"; \ echo === DONE: \\"\\\$cmd\\" ===; \ kill -TERM \\\$setsid_GROUP"; \ if [ -f $HOME/.dt/.RunActionShell ]; \ then \ shell="`cat $HOME/.dt/.RunActionShell`"; \ shellp=""; \ else shell="/bin/bash"; shellp=""; \ fi; \ shellname=`basename \$shell`; \ shell="\$shell \$shellp"; \ colours=""; user=""; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then shell="sh_as_user \ -u root \ -f $HOME/.dt/.RunActionUser \ - \$shell"; \ colours="-bg red -fg yellow"; \ user="(root) "; \ fi; \ fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ cd \$exd; \ if [ -z "`echo \$ff`" ]; then cd; fi; \ mprompt \$colours \ -specfont 7x13 \ -text "Run \$shellname in `pwd`" \ -title "\${user}Run (text) Command" \ -autoicon -icontitle "Run Txt" \ -defaultstring " \$ff" -noexit | \ while read cmd; do \ export cmd; \ ( ( (setsid \ /bin/sh -c "( ( (\$shell -c \\\"\\\$cmd\\\"); \ \$suicide) \ 2>&1 < /dev/null &); \ \$precmd") | \ mdisplay -specfont 6x10 -pb1label "" -pb2label "" \ -xrm "*XmText*highlightThickness: 0" \ -title "Command Output: \$cmd" \ -columns 80 -rows 24 -frompipe) \ 2>&1 > /dev/null & ) \ done' # alternative line:- # -columns 80 -rows 72 -autosize) & ); \ WINDOW_TYPE NO_STDIO ICON runner } ACTION HistRunTxt { DESCRIPTION Uses mprompt to ask for a command string, \ outputting stdout and stderr to mdisplay. EXEC_STRING sh -c ' \ exd=`pwd`; shell=\$SHELL; \ precmd="if myesno -text \\"kill \\\$cmd\\" \ -title \\"kill \\\$cmd\\"; \ then kill -TERM \\\$setsid_GROUP; fi"; \ suicide="sleep 1; kill -TERM \\\$setsid_GROUP"; \ if [ -f $HOME/.dt/.RunActionShell ]; \ then \ shell="`cat $HOME/.dt/.RunActionShell`"; \ shellp=""; \ else shell="/bin/bash"; shellp=""; \ fi; \ shellname=`basename \$shell`; \ shell="\$shell \$shellp"; \ colours=""; user=""; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then shell="sh_as_user \ -u root \ -f $HOME/.dt/.RunActionUser \ - \$shell"; \ colours="-bg red -fg yellow"; \ user="(root) "; \ fi; \ fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ cd \$exd; \ if [ -z "`echo \$ff`" ]; then cd; fi; \ cat /dev/null | \ mselect \$colours \ -addselect -select 3 \ -specfont 7x13 \ -selectlabel "Run \$shellname in `pwd`" \ -title "\${user}Run (text) Command" \ -autoicon -icontitle "Run Txt" \ -defaultstring " \$ff" -noexit | \ while read cmd; do \ export cmd; \ ( ( (setsid \ /bin/sh -c "( ( (\$shell -c \\\"\\\$cmd\\\"); \ \$suicide) \ 2>&1 < /dev/null &); \ \$precmd") | \ mdisplay -specfont 6x10 -pb1label "" -pb2label "" \ -xrm "*XmText*highlightThickness: 0" \ -title "Command Output: \$cmd" \ -columns 80 -rows 24 -frompipe) \ 2>&1 > /dev/null & ) \ done' WINDOW_TYPE NO_STDIO ICON runner } ACTION RunTxt { TYPE MAP MAP_ACTION RunCommandDisplaySmall ICON runner } # and for XTerm output ACTION RunCommandXterm { DESCRIPTION Uses mprompt to ask for a command string, \ then executes it in an xterm. EXEC_STRING sh -c \ 'shell=\$SHELL; \ xtparam=`if [ -r $HOME/.xwin ]; \ then cat $HOME/.xwin; \ fi`; \ if [ -f $HOME/.dt/.RunActionShell ]; \ then \ shell="`cat $HOME/.dt/.RunActionShell`"; \ shellp=""; \ else shell="/bin/bash"; shellp=""; \ fi; \ shellname=`basename \$shell`; \ shell="\$shell \$shellp"; \ colours=""; user=""; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then shell="sh_as_user \ -u root \ -f $HOME/.dt/.RunActionUser \ - \$shell"; \ colours="-bg red -fg yellow"; \ user="(root) "; \ fi; \ fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ cd \$exd; \ if [ -z "`echo \$ff`" ]; then cd; fi; \ mprompt \$colours \ -specfont 7x13 \ -text "Run \$shellname in `pwd`" \ -title "\${user}Run (XTerm) Command" \ -autoicon -icontitle "Run XT" \ -defaultstring " \$ff" -noexit | \ while read cmd; do \ (xterm -fn 7x13 -sl 2000 -sb \$colours \$xtparam \ -e \$shell -c "\$cmd; echo; \ echo ==Done==; sleep 120" &); \ done' WINDOW_TYPE NO_STDIO ICON runner } ACTION RunXT { TYPE MAP MAP_ACTION RunCommandXterm ICON runner } ACTION RunNoOutput { DESCRIPTION Uses mprompt to ask for a command string, \ outputting stdout and stderr to /dev/null. EXEC_STRING sh -c \ 'shell=\$SHELL; \ precmd="if myesno -text \\"kill \\\$cmd\\" \ -title \\"kill \\\$cmd\\"; \ then kill -TERM \\\$setsid_GROUP; fi"; \ suicide="sleep 1; kill -TERM \\\$setsid_GROUP"; \ if [ -f $HOME/.dt/.RunActionShell ]; \ then \ shell="`cat $HOME/.dt/.RunActionShell`"; \ shellp=""; \ else shell="/bin/bash"; shellp=""; \ fi; \ shellname=`basename \$shell`; \ shell="\$shell \$shellp"; \ colours=""; user=""; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then shell="sh_as_user \ -u root \ -f $HOME/.dt/.RunActionUser \ - \$shell"; \ colours="-bg red -fg yellow"; \ user="(root) "; \ fi; \ fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ cd \$exd; \ if [ -z "`echo \$ff`" ]; then cd; fi; \ mprompt \$colours \ -specfont 7x13 \ -text "Run \$shellname in `pwd`" \ -title "\${user}Run (No Output)" \ -autoicon -icontitle "RunNoOut" \ -defaultstring " \$ff" -noexit | \ while read cmd; do \ export cmd; \ ( ( setsid \ /bin/sh -c "( ( (\$shell -c \\\"\\\$cmd\\\"); \ \$suicide) \ 2>&1 < /dev/null &); \ \$precmd") \ 2>&1 < /dev/null > /dev/null &);\ done' WINDOW_TYPE NO_STDIO ICON runner } ACTION RunToggleShell { DESCRIPTION Allows the user to pick the shell used for the run \ command actions EXEC_STRING sh -c \ 'if [ ! -f $HOME/.dt/.RunActionShell ]; \ then echo "/bin/bash" > $HOME/.dt/.RunActionShell; \ fi; \ s=`cat $HOME/.dt/.RunActionShell`; \ set - " /bin/bash " \ " /bin/ksh " \ " /bin/sh " \ " /bin/csh " \ " /bin/tcsh "; \ c=`mmenu \ -title "Shell" \ -defaultbutton 0 \ -xrm "*highlightThickness: 0" \ -xrm "*shadowThickness: 1" \ -xrm "*fontList: helvb12" \ -xrm "*spacing: 2" \ -xrm "*marginHeight: 0" \ -xrm "*marginWidth: 0" \ -xrm "*entryBorder: 0" \ "$@"`; \ if [ -n "\$c" ]; then \ e="\\\$""\$c"; \ s=`sh -c "echo \$e" dummy "$@"`; \ fi; \ echo "\$s" > $HOME/.dt/.RunActionShell; \ mmessage -title "Shell" \ -text "Chosen shell is \$s" \ -pb2label "";' WINDOW_TYPE NO_STDIO ICON runner } ACTION RunToggleUser { DESCRIPTION Toggles the username used for the run command actions EXEC_STRING sh -c \ 'if [ -f $HOME/.dt/.RunActionUser ]; \ then rm $HOME/.dt/.RunActionUser; \ else \ umask 077; \ mprompt -password -specfont 7x13 \ -text "root password" \ -title "Run actions as root" \ -bg red -fg yellow \ > $HOME/.dt/.RunActionUser; \ if sh_as_user -u root -q \ -f $HOME/.dt/.RunActionUser - true; \ then true; \ else rm $HOME/.dt/.RunActionUser; \ mmessage -title "Run actions as root" \ -text "Invalid password" \ -pb2label ""; \ fi; \ fi' WINDOW_TYPE NO_STDIO ICON runner } ACTION RunNoOut { TYPE MAP MAP_ACTION RunNoOutput ICON runner } ACTION RunMenu { DESCRIPTION Runs a menu for run command actions EXEC_STRING setsid sh -c \ 'fl=`echo "%(File)Args%"`; \ for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ ti="? "\${ff}; \ true ti=Run\${fl:+" Files"}; \ colours=""; \ Tuser="Set-root"; \ if [ -f $HOME/.dt/.RunActionUser ]; \ then colours="-bg red -fg yellow"; \ ti="(root) \$ti"; \ Tuser="Set-\$USER"; \ fi; \ mmenu \ -title "\$ti" \ -defaultbutton 0 \ \$colours \ -noexit \ -xrm "*highlightThickness: 1" \ -xrm "*shadowThickness: 1" \ -xrm "*fontList: helvb12" \ -xrm "*spacing: 0" \ -xrm "*marginHeight: 0" \ -xrm "*marginWidth: 0" \ -xrm "*entryBorder: 1" \ -rows 6 \ Run-Text Run-List \ Hist-Text Hist-List \ Run-XTerm Run-null \ Set-Shell \$Tuser \ File-Names Names-Rel \ Edit-Text Exit | \ (while read result; do \ case r\$result in \ r1) setsid dtaction RunTxt \$fl & ;; \ r2) setsid dtaction RunList \$fl & ;; \ r3) setsid dtaction HistRunTxt \$fl & ;; \ r4) setsid dtaction HistRunCommand \$fl & ;; \ r5) setsid dtaction RunXT \$fl & ;; \ r6) setsid dtaction RunNoOutput \$fl & ;; \ r7) dtaction RunToggleShell \$fl ;; \ r8) dtaction RunToggleUser \$fl ;; \ r9) for f in \$fl; do ff="\$f \$ff"; done; \ ( (for f in `echo "\$ff"`; do \ echo "\$f"; \ done) | \ setsid \ mdisplay -specfont 6x10 \ -pb1label "" -pb2label "" \ -xrm "*XmText*highlightThickness: 0" \ -xrm "*primaryColorSetId: 2" \ -title "File Names" \ -columns 80 -rows 72 \ -autosize &) ;; \ r10) for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ ( (echo "\$exd"; echo ""; \ for f in `echo "\$ff"`; do \ echo "\$f"; \ done) | \ setsid \ mdisplay -specfont 6x10 \ -pb1label "" -pb2label "" \ -xrm "*XmText*highlightThickness: 0" \ -xrm "*primaryColorSetId: 2" \ -title "File Names" \ -columns 80 -rows 72 \ -autosize &) ;; \ r11) for f in \$fl; do exd=`dirname \$f`; done; \ cd \$exd; pexd=`pwd`; \ for f in \$fl; do \ cd `dirname \$f`; \ if [ `pwd` = \$pexd ]; \ then ff="`basename \$f` \$ff"; \ else ff="\$f \$ff"; \ fi; \ done; \ ( (echo "\$exd"; echo ""; \ for f in `echo "\$ff"`; do \ echo "\$f"; \ done) | \ setsid \ medit -specfont 6x10 -rows 20 -columns 80 \ -pb1label "" -pb2label "" \ -title " " > /dev/null &) ;; \ r12) kill -TERM \$setsid_GROUP ;; \ *) : ;; \ esac; \ done) > /dev/null 2>&1' WINDOW_TYPE NO_STDIO ICON runner }