title: JQ get key based on variable value
body: <p>I'm trying to create a ohmyzsh function for Salesforce's DX CLI based on Wade Wegner's guide <a href="http://www.wadewegner.com/2017/04/show-the-salesforce-dx-org-config-in-your-bash-profile/#comment-3671894553" rel="nofollow noreferrer">here</a>. In order to get the value I want I need to expand how he is using <a href="https://stedolan.github.io/jq/" rel="nofollow noreferrer">JQ</a> which I've never heard of before. I get the premise for this use case but I'm struggling with one abstraction point (within the <code>aliasConfig</code> json). Here's my script so far</p>
  
  <pre><code>get_sfdx_defaultusername() {
      config="$(cat .sfdx/sfdx-config.json 2&gt; /dev/null)";
      globalConfig="$(cat ~/.sfdx/sfdx-config.json)";
      aliasConfig="$(cat ~/.sfdx/alias.json)";
  
      defaultusername="$(echo ${config} | jq -r .defaultusername)"
      defaultusernamealias="NEED HELP HERE"
      globaldefaultusername="$(echo ${globalConfig} | jq -r .defaultusername)"
  
      if [ ! $defaultusernamealias = "null" ]
      then
        echoString=$echoString$defaultusernamealias"$txtylw (alias)"
      elif [ ! $defaultusername = "null" ]
      then
        echoString=$echoString$defaultusername"$txtylw (local)"
      else
        echoString=$echoString$globaldefaultusername"$txtylw (global)"
      fi
      echo $echoString"\n"
  }
  </code></pre>
  
  <p>The <strong>alias.json</strong> looks like this:</p>
  
  <pre><code>{
      "orgs": {
          "HubOrg": "myemail@domain.com",        
          "my-scrath-org": "test-jdj1iflkor4k@mydomain.net"
      }
  }
  </code></pre>
  
  <p>Using the <code>${defaultusername}</code> I know the value in this case to be "test-jdj1iflkor4k@mydomain.net", therefore I need it to set the value of <code>defaultusernamealias</code> to "my-scrath-org"</p>
  
  <p>NOTE: The closest answer I found was <a href="https://stackoverflow.com/questions/43678724/jq-extracting-the-array-key-based-on-value">this</a>, but unfortunately I still couldn't get what I needed with it.</p>