作業環境の準備を自動化するスクリプトを書いています。4 つのターミナル ウィンドウを開いて配置し、それぞれでコマンドを実行する必要があります。
それは機能しますが、時々私は厄介な失敗をします -xdotool type
いくつかの文字をランダムに繰り返します:
rvm use ruby-1.99999999999999999999999999999999.3-p194@ro && rails c
~/my_src/ruby_apps/ro > rvm use ruby-1.99999999999999999999999999999999.3-p194@ro && rails c
ruby-1.99999999999999999999999999999999.3-p194 is not installed.
To install do: 'rvm install ruby-1.99999999999999999999999999999999.3-p194'
~/my_src/ruby_apps/ro >
または他のウィンドウで:
tail -fn 100 looooooog/thin.0.log
~/my_src/ruby_apps/ro > tail -fn 100 looooooog/thin.0.log
tail: could not open «looooooog/thin.0.log» for reading: No such file or directory
tail: no more files
~/my_src/ruby_apps/ro >
CPU 負荷に依存していると思います。ATOM で処理される .bashrc が非常に大きく、スクリプト処理中に負荷が高くなるためです。
単純な単純なコマンドを最初に実行するために、スクリプト内でwait
andsleep
と特別な関数呼び出しの順序を使用します。open_lxterminal_execute_hold()
これによりエラーは最小限に抑えられますが、まったく防止されません。
CPU負荷に関係なく安定した結果を得るために何を提案しますか? sleep
s も取り除くのは素晴らしいことです。
#!/bin/bash
#
# prepares work environment for rails project
# Opens lxterminal with title if windows with such title
# doesn't exist, executes command and stays open.
# Otherwise does nothing.
#
function open_lxterminal_execute_hold(){
local winid=`xwininfo -name $title 2>/dev/null |grep 'Window id:' |cut -d" " -f4`
if [ -n "$winid" ]; then
echo "Window for title '$title' exists with '$winid'"
else
lxterminal -t $title
sleep 1
wmctrl -i -a "$winid" # bring the window to front, activate
wait
xdotool type "$command"
wait
xdotool key Return # run the command
wait
fi
}
pkill devilspie
cd ~/my_src/ruby_apps/ro # TODO param
title='rails-commandline'; command='ls'; open_lxterminal_execute_hold
title='rails-development.log'; command='tail -fn 100 log/development.log'; open_lxterminal_execute_hold
title='rails-user_case'; command='tail -fn 100 log/thin.0.log'; open_lxterminal_execute_hold
sleep 5
title='rails-console'; command='rvm use ruby-1.9.3-p194@ro && rails c'; open_lxterminal_execute_hold
/usr/bin/devilspie -a 2>/dev/null & # arrange windows
更新 xdotool の繰り返し文字を防ぐにはどうすればよいですか?