URI:
       Add ability to manage block and audio input - qmenu - manage qubes os via dmenu (drkhsh fork)
  HTML git clone git://git.drkhsh.at/qmenu.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 59d5b9ba3c1531bf4bc7cf78d7174915270c248c
   DIR parent f689afeea91afdbd0ac985fb485506eb9e2c8c79
  HTML Author: sine3o14nnae <3o14@pm.me>
       Date:   Mon, 19 Aug 2019 03:49:31 +0200
       
       Add ability to manage block and audio input
       
       Diffstat:
         A qmenu-dv                            |     183 +++++++++++++++++++++++++++++++
       
       1 file changed, 183 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/qmenu-dv b/qmenu-dv
       @@ -0,0 +1,183 @@
       +#!/bin/bash
       +
       +rearrange_qube_list() {
       + 
       + local QUBE_LIST_REARRANGED+=`echo "$(echo "$qube_list" |\
       +   awk '$2 == "purple"')"`
       +
       + local QUBE_LIST_REARRANGED+=`echo "\n$(echo "$qube_list" |\
       +   awk '$2 == "blue"')"`
       + 
       + local QUBE_LIST_REARRANGED+=`echo "\n$(echo "$qube_list" |\
       +   awk '$2 == "gray"')"`
       +   
       + local QUBE_LIST_REARRANGED+=`echo "\n$(echo "$qube_list" |\
       +   awk '$2 == "green"')"`
       +
       + local QUBE_LIST_REARRANGED+=`echo "\n$(echo "$qube_list" |\
       +   awk '$2 == "yellow"')"`
       +
       + local QUBE_LIST_REARRANGED+=`echo "\n$(echo "$qube_list" |\
       +   awk '$2 == "orange"')"`
       +
       + local QUBE_LIST_REARRANGED+=`echo "\n$(echo "$qube_list" |\
       +   awk '$2 == "red"')"`
       +
       + local QUBE_LIST_REARRANGED+=`echo "\n$(echo "$qube_list" |\
       +   awk '$2 == "black"')"`
       +
       + # Remove blank lines 
       + qube_list=`echo -e "$QUBE_LIST_REARRANGED" | sed "{/^$/d;}"`
       +}
       +
       +
       +get_qube_label() {
       +
       + qube_label=`echo "$qube_list" | grep -w $target_qube | awk '{ print $2 }'`
       + 
       + # Change black, yellow and green to a more readable color if needed 
       + if [ "$qube_label" = "black" ]; then
       +
       +   qube_label='#373737'
       +
       + # Change only if dark theme is selected
       + elif [ "$theme_1" = "#ffffff" ]; then
       +
       +   if [ "$qube_label" = "yellow" ]; then 
       +        
       +     qube_label='#cdcd00'
       +    
       +   elif [ "$qube_label" = "green" ]; then
       +
       +     qube_label='#00b300'
       +   fi
       + fi
       +}
       +
       +
       +if [ "$2"  = "--light-theme" ]; then
       +
       +  theme_0='#ffffff'
       +  theme_1='#000000'
       +else
       +        
       +  theme_0='#000000'
       +  theme_1='#ffffff'
       +fi
       +
       +# Note that the '-m 0' option in 'dmenu' is important
       +# for security as it restricts it to monitor 0
       +dmenu_fmc="-f -m 0 -nb $theme_0 -nf $theme_1 -sb $theme_1 -sf $theme_0"
       +
       +case $1 in
       +
       +  --all)
       +
       +    device_type=`echo -e "Audio input\nBlock\nUSB" |\
       +      dmenu -i -l 3 -p "Select device type:"\
       +      $dmenu_fmc | awk '{ print $1 }'`;;
       +
       +  --audio-input)
       +
       +    device_type="Audio";;
       +
       +  --block)
       +
       +    device_type="Block";;
       +
       +  --usb)
       +
       +    device_type="USB";;
       +
       +  *)
       +
       +    echo -e "Please append one of the following:\
       + '--all', '--audio-input', '--block' or '--usb'"
       +esac
       +
       +# Depending on the device type, we have to 
       +# 'awk' different fields later on
       +if [ "$device_type" = "Audio" ]; then
       +
       +  device_type="device mic"
       +  
       +  awk_devicename0=2
       +  awk_devicename1=10
       +  awk_targetqube=3
       +
       +elif [ "$device_type" = "Block" ]; then
       +
       +  device_type="${device_type,}"
       +
       +  awk_devicename0=2
       +  awk_devicename1=3
       +  awk_targetqube=4
       +
       +elif [ "$device_type" = "USB" ]; then
       +
       +  device_type="${device_type,,}"
       +
       +  awk_devicename0=2
       +  awk_devicename1=10
       +  awk_targetqube=3
       +else
       +
       +  exit 2
       +fi
       +
       +qube_list=`qvm-ls --no-spinner --running -O NAME,LABEL`
       +
       +rearrange_qube_list
       +
       +devices_list=`qvm-$device_type`
       +
       +device=`echo "$devices_list" | dmenu -l 16 $dmenu_fmc`
       +
       +device_id=`echo $device | awk '{ print $1 }'`
       +
       +device_name=`echo $device |\
       +  awk '{ print $'$awk_devicename0'$'$awk_devicename1' }'`
       +
       +if [ -n "$device" ]; then
       +
       +  target_qube=`echo "$devices_list" | grep $device_id |\
       +     awk '{ print $'$awk_targetqube' }'`
       +
       +  if [ -z "$target_qube" ]; then
       +    
       +    target_qube=`echo "$qube_list" | grep -v -w dom0 |\
       +      sed '1d' | dmenu -p "attach to:" -l 32 $dmenu_fmc | awk '{ print $1 }'`
       +    
       +    if [ -n "$target_qube" ]; then
       +
       +      get_qube_label 
       +
       +      prompt=`echo -e "No\nYes" |\
       +        dmenu -i -p "Attach $device_name to $target_qube?"\
       +        -f -m 0 -nb $theme_0 -nf $theme_1 -sb $qube_label -sf $theme_1`
       +    
       +      if [ "$prompt" = "Yes" ]; then
       +
       +        if ! qvm-$device_type attach $target_qube $device_id; then exit 2; fi        
       +        
       +        exit 0
       +      fi
       +    fi 
       +  else
       +    
       +    get_qube_label
       +
       +    prompt=`echo -e "No\nYes" |\
       +      dmenu -i -p "Detach $device_name from $target_qube?"\
       +      -f -m 0 -nb $theme_0 -nf $theme_1 -sb $qube_label -sf $theme_1`
       +    
       +    if [ "$prompt" = "Yes" ]; then
       +
       +      if ! qvm-$device_type detach $target_qube $device_id; then exit 2; fi
       +        
       +      exit 0
       +    fi
       +  fi
       +fi
       +
       +exit 1