dotfiles

custom linux config files managed with gnu stow

dotfiles

wmutils/bin/group


#!/bin/sh
#
# wmg by:
#
# ▓█████▄  ▄████▄   ▄▄▄     ▄▄▄█████▓
# ▒██▀ ██▌▒██▀ ▀█  ▒████▄   ▓  ██▒ ▓▒
# ░██   █▌▒▓█    ▄ ▒██  ▀█▄ ▒ ▓██░ ▒░
# ░▓█▄   ▌▒▓▓▄ ▄██▒░██▄▄▄▄██░ ▓██▓ ░ 
# ░▒████▓ ▒ ▓███▀ ░ ▓█   ▓██▒ ▒██▒ ░ 
#  ▒▒▓  ▒ ░ ░▒ ▒  ░ ▒▒   ▓▒█░ ▒ ░░   
#  ░ ▒  ▒   ░  ▒     ▒   ▒▒ ░   ░    
#  ░ ░  ░ ░          ░   ▒    ░      
#    ░    ░ ░            ░  ░        
#  ░      ░                          

GRP_DIR="/tmp/wmutils/groups"
USE_FIFO=yes

setup() {
  [ -d "$GRP_DIR" ] || mkdir -p $GRP_DIR
  if [ -n "$USE_FIFO" ]
  then
    [ -p "$GRP_DIR/.fifo" ] || mkfifo $GRP_DIR/.fifo
  fi
}

sed_apply() {
  TMP=`mktemp /tmp/grp.XXXXXX`
  sed  <  > $TMP && mv $TMP  || rm $TMP
  [ -n "$DEBUG" ] && echo "sed  <  > $TMP && mv $TMP  || rm $TMP"
}

pop() {
  sed_apply "//d" 
}

push() {
  echo  >> $GRP_DIR/
}

view() {
  while read WID
  do mapw -m $WID
  done < $GRP_DIR/
}

hide() {
  while read WID
  do mapw -u $WID
  done < $GRP_DIR/
}

pop_from_all() {
  for GRP in $GRP_DIR/*
  do
    pop  $GRP
  done
}

case  in
view)
  setup
  if [ -f "$GRP_DIR/" ]
  then
    for GRP in $GRP_DIR/*
    do hide `basename $GRP`
    done
    view 
  else
    echo "group does not exist"
    exit 1
  fi

  # customize your fifo printing here
  if [ -n "$USE_FIFO" ]
  then
    for GRP in $GRP_DIR/*
    do
      GRP_BASE="`basename $GRP`"
      GRP_NUM=`wc -l < $GRP | tr -cd '[:digit:]'`
      [ $GRP_NUM -ne 0 ] && printf '^fg(#888)' || printf '^fg(#555)'
      [ $GRP_BASE -eq  ] && printf '^fg(orange)<'
      printf "$GRP_BASE^fg()"
      [ $GRP_BASE -eq  ] && printf '>^fg()'
    done > $GRP_DIR/.fifo
    echo >> $GRP_DIR/.fifo
  fi

  ;;
hide)
  setup
  hide 
  ;;
add)
  setup
  pop_from_all 
  push  
  hide 
  view 
  ;;
remove)
  setup
  pop_from_all 
  ;;
esac

Download

raw zip tar