玩awesome# 预览配置文件效果

wiki里提供了一种预览配置文件效果的方法:xephy,

Xephyr  -  X  server outputting to a window on a pre-existing X display

说了一堆,千言万语最后化作一个可以直接拿来用的现成脚本。使用很简单,见第一个方法或者直接执行脚本。这个脚本默认使用rc.lua.new,如果没有就会从模板中复制一份

下面是对这个脚本中我感兴趣的问题的总结:

1. Xephy

不仅于awesome,Xephy可以在一个窗口显示任何的桌面环境。

Xephyr -ac -br -noreset -screen 800x600 :1&
sleep 1
DISPLAY=:1.0 startxfce4 &

上面的示例就是显示一个xfce。这段命令会让人困惑的地方是 :1 这个表示一个从属的X。

 

2. kill -s HUP

kill -s 是向指定的pid发送信号。关于信号的帮助可以man 7 signal查看。

脚本里,这条命令的作用是重启awesome。它的帮助是这样说的

awesome can be restarted by sending it a SIGHUP.

 但hup是hang up的意思吧,总感觉古怪。不过好像也有点约定俗成的感觉,xbindkeys里也是这个信号用来刷新配置

 

3. pidof

功能类似procps-ng软件包下pgrep根据名字返回pid,有三个主要选项。

-x 脚本进程也在返回之列

-o 指定需要忽略的pid

-s 限制返回一个pid

 

 

function usage() 
{
  cat <<USAGE
awesome_test start|stop|restart|run

  start    Start nested Awesome in Xephyr
  stop     Stop Xephyr
  restart  Reload nested Awesome configuration
  run      Run command in nested Awesome

USAGE
  exit 0
}

# WARNING: the following two functions expect that you only run one instance
# of Xephyr and the last launched Awesome runs in it

function awesome_pid() 
{
  /bin/pidof awesome | cut -d\  -f1
}
 
function xephyr_pid()

{
  /bin/pidof Xephyr | cut -d\  -f1
}

[ $# -lt 1 ] && usage

# If rc.lua.new is missing, make a default one.
RC_LUA=~/.config/awesome/rc.lua.new
test -f $RC_LUA || /bin/cp /etc/xdg/awesome/rc.lua $RC_LUA

# Just in case we're not running from /usr/bin
AWESOME=`which awesome`
XEPHYR=`which Xephyr`

test -x $AWESOME || { echo "Awesome executable not found. Please install Awesome"; exit 1; }
test -x $XEPHYR || { echo "Xephyr executable not found. Please install Xephyr"; exit 1; }

case "$1" in
  start)
    $XEPHYR -ac -br -noreset -screen 800x600 :1 &
    sleep 1
    DISPLAY=:1.0 $AWESOME -c $RC_LUA &
    sleep 1
    echo Awesome ready for tests. PID is $(awesome_pid)
    ;;
  stop)
    echo -n "Stopping Nested Awesome... "
    if [ -z $(xephyr_pid) ]; then
      echo "Not running: not stopped :)"
      exit 0
    else
      kill $(xephyr_pid)
      echo "Done."
    fi
    ;;
  restart)
    echo -n "Restarting Awesome... "
    kill -s SIGHUP $(awesome_pid)
    ;;
  run)
    shift
    DISPLAY=:1.0 "$@" &
    ;;
  *)
    usage
    ;;
esac

 

 

 

posted @ 2012-11-16 22:10  倚楼无语F5  阅读(602)  评论(0编辑  收藏  举报