<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=1951&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / Questions on environment checks in Bash script]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=1951</link>
		<description><![CDATA[The most recent posts in Questions on environment checks in Bash script.]]></description>
		<lastBuildDate>Tue, 27 Mar 2018 21:47:22 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: Questions on environment checks in Bash script]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=8117#p8117</link>
			<description><![CDATA[<p>The script has already seen a good deal of changes since my initial post, mainly because I found out I was making some structural mistakes. I&#039;ll try to get it into a presentable shape as soon as possible, put it on GitHub and post a link on this forum. </p><div class="quotebox"><cite>xunilog wrote:</cite><blockquote><div><p>Nested checks or not, I expect it would need &quot;special case&quot; exceptions handling. For instance, conky &quot;use_own_window=true&quot; would need to be recognized, and handled (whitelisted)...</p></div></blockquote></div><p>Because you don&#039;t want to be warned about that conky window, right? A list of programs to ignore can be provided through command line parameters.</p><div class="quotebox"><cite>xunilog wrote:</cite><blockquote><div><p>and, can I really hang my hat on, and trust, who a given window is &quot;owned by&quot;? What about text editor instance(s) launched as sudo to edit config files?</p></div></blockquote></div><p>They will be handled like any other remaining window.</p><div class="quotebox"><cite>xunilog wrote:</cite><blockquote><div><p>What about any long-running windowless processes I may have running (as me, or as sudo) that I&#039;ve forgotten about?</p></div></blockquote></div><p>Can you give an example? I know that <em>xmobar</em>, which I use for system monitoring, is not recognized as a window by <span class="bbc">wmctrl</span>. But that&#039;s the way I&#039;d want it anyway.</p><div class="quotebox"><cite>xunilog wrote:</cite><blockquote><div><p>I hear ya about &quot;oops, dangit!&quot;, but I would skip the prone-to-failure guessing/checking and just wire an unconditionally triggered yad or xdialog prompt inline with the desktop session exit script.</p></div></blockquote></div><p>Openbox actually has that. It asks for confirmation before it exits (unless you run <span class="bbc">openbox --exit</span> directly). My issue with that is: If there are no remaining open windows (of possible interest), I don&#039;t want to be asked for confirmation. However, if there are, I want to be warned about that. In my experience, that really makes a difference.</p>]]></description>
			<author><![CDATA[dummy@example.com (msi)]]></author>
			<pubDate>Tue, 27 Mar 2018 21:47:22 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=8117#p8117</guid>
		</item>
		<item>
			<title><![CDATA[Re: Questions on environment checks in Bash script]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=8109#p8109</link>
			<description><![CDATA[<p>Nested checks or not, I expect it would need &quot;special case&quot; exceptions handling. For instance, conky &quot;use_own_window=true&quot; would need to be recognized, and handled (whitelisted)... and, can I really hang my hat on, and trust, who a given window is &quot;owned by&quot;? What about text editor instance(s) launched as sudo to edit config files? What about any long-running windowless processes I may have running (as me, or as sudo) that I&#039;ve forgotten about? I hear ya about &quot;oops, dangit!&quot;, but I would skip the prone-to-failure guessing/checking and just wire an unconditionally triggered yad or xdialog prompt inline with the desktop session exit script.</p>]]></description>
			<author><![CDATA[dummy@example.com (xunilog)]]></author>
			<pubDate>Tue, 27 Mar 2018 19:44:12 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=8109#p8109</guid>
		</item>
		<item>
			<title><![CDATA[Questions on environment checks in Bash script]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=8088#p8088</link>
			<description><![CDATA[<p>I&#039;m working on a Bash script that will display a warning dialog in case the user tries to exit the window manager when there are remaining open windows. The reason I&#039;m doing this is that I use Openbox stand-alone without any task bar and it has happened to me time and again that I, e.g., lost notes from text editor windows that I had minimized or moved to another workspace at some point and then forgotten about.</p><p>Because I want this to be a sane script, I&#039;ve created a function that performs some environment checks after the command line parameters have been processed and before any of the main script is being executed.</p><p>Currently, that function looks like this:</p><div class="codebox"><pre class="vscroll"><code># Perfom environment checks

function f_check_env {  

# Check if wmctrl can be found (and executed)

  if [ ! -x &quot;$(type -p wmctrl)&quot; ]
  then
    return 1  # Leave function with error code 1: wmctrl not found
  fi

# Check if given window manager is supported

  local wm_supported=0

  for item in &quot;${wm_list[@]}&quot;
  do
    if [ &quot;$item&quot; = &quot;$wm&quot; ]
    then
      wm_supported=1
      break
    fi
  done

  if [ &quot;$wm_supported&quot; != 1 ]
  then
    return 2  # Leave function with error code 2: $wm is not supported
  fi

# Check if given window manager can be found on the system (and executed)

  if [ ! -x &quot;$(type -p &quot;$wm&quot;)&quot; ]
  then
    return 3  # Leave function with error code 3: $wm not found
  fi

# Check if given window manager is currently being run by the current user

  if [ ! &quot;$(ps -u &quot;$(whoami)&quot; | grep &quot;$wm&quot;)&quot; ]
  then
    return 4  # Leave function with error code 4: $wm is not currently
              # being run by the user executing this script
  fi
}</code></pre></div><p>A bit of explanation: <span class="bbc">wmctrl</span> is a tool that can be used to query and control EWMH/NetWM compatible window managers. I use it to get a list of existing windows at a later point in the script. <span class="bbc">wm_list</span> is an array containing a list of all the window managers that the script can work with.</p><p>Now, I have two questions about this function:</p><p>1. Wouldn&#039;t it be better to nest all the checks performed there instead of having them as independent blocks? One advantage of nesting I can think of is that it would enable me to put <del><span class="bbc">else return 0; fi</span> at the end of the function</del> <span class="bbc">return 0</span> into the innermost <span class="bbc">else</span> statement, which would then be executed if no error condition is met.</p><p>2. Is there anything wrong with how I&#039;m using error codes? The function&#039;s return value will be dealt with in a <span class="bbc">case</span> statement later, containing the messages corresponding to the error codes.</p>]]></description>
			<author><![CDATA[dummy@example.com (msi)]]></author>
			<pubDate>Sun, 25 Mar 2018 03:16:10 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=8088#p8088</guid>
		</item>
	</channel>
</rss>
