Advertisement
Bladtman

Untitled

Aug 13th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2. NAME_FILE="/home/bladt/Downloads/walls/in_use/names.txt"
  3. DIR=$(dirname $NAME_FILE)
  4. WAIT_TIME="5m"
  5. STAT=0
  6.  
  7. # takes a string as "[path] [option]"
  8. #+ and outputs "[flag] [path]" to be passed to awsetbg
  9. function modeSwitch {
  10.     case $2 in
  11.     "full")
  12.         local mode="-F"
  13.     ;;
  14.     "centered")
  15.         local mode="-C"
  16.     ;;
  17.     "tiled")
  18.         local mode="-T"
  19.     ;;
  20.     "maximized")
  21.         local mode="-A"
  22.     ;;
  23.     *)
  24.         local mode="-F" #defaults to fullscreen
  25.     ;;
  26.     esac   
  27.     echo "$mode $1"
  28. }  
  29.  
  30. if [ "$#" -ne "0" ]; then
  31.     IFS=$(echo -ne "\\n")
  32.     name=$(grep -E "$1" $NAME_FILE)
  33.     nonempty=$?
  34.     if [ $(echo $name | wc -l) -gt "1" ]; then
  35.         echo $name
  36.     elif [ $nonempty -eq "0" ]; then
  37.         unset IFS #unset here, to force $name to be split into modeSwitch's $1 and $2
  38.         awsetbg $(modeSwitch $DIR/$name)
  39.     else
  40.         echo "wallrotor found no entries matching \"$1\"" >&2
  41.         stat=1
  42.     fi
  43.     unset IFS
  44.     exit $stat
  45. elif  ps -e | grep -i wallrotor | grep -v $$ >/dev/null 2>&1 ; then
  46.     echo "allready running"
  47.     exit
  48. fi
  49.  
  50. while true; do
  51.     names="$(sort -R $NAME_FILE)"
  52.     while read -r line ; do
  53.         awsetbg $(modeSwitch $DIR/$line)
  54.         sleep $WAIT_TIME
  55.     done <<< "$names"
  56. done
  57. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement