-
-
Save max-lv/0c58e239b5bdadca71cbde1ca6315937 to your computer and use it in GitHub Desktop.
m_runner.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Credit to windwp for original script: | |
# https://gist.github.com/windwp/273387a73f902ae49c7c90d612fd2238 | |
# (this is slightly modified version) | |
# use it for continue running application | |
# similar entr | |
# if you want to use swallow function you need to install | |
# https://github.com/windwp/i3-master-stack | |
# https://github.com/windwp/i3-master-stack/blob/master/swallow | |
#┌──────────┐ | |
#│vim script│ | |
#└──────────┘ | |
# put in on vim.rc or init.vim | |
# change *.go to your file type | |
#======================================== | |
#augroup editorsignal | |
# autocmd! | |
# autocmd bufwritepost *.go :silent !pkill -usr1 m_runner.sh | |
#augroup end | |
# OR | |
# use watchexec/entr in another terminal | |
# watchexec -- pkill -usr m_runner.sh | |
is_running=1 | |
command="$@" | |
run_command(){ | |
echo "-----------------------------" | |
$command & | |
pid=$! | |
} | |
handler(){ | |
wid=$(xdotool search -pid $pid) | |
# focus on runner process it make i3 understand the next window spawn | |
if [[ ${#wid} -gt 2 ]]; then | |
xdotool windowactivate $wid | |
fi | |
sleep 0.5 | |
kill $pid | |
run_command | |
sleep 1 | |
# do what ever you want to update layout | |
# focus back on vim | |
i3-msg '[title="nvim"] focus' > /dev/null | |
} | |
handle_ctrl_c() { | |
# `\r` to overwrite `^C` entered by user | |
printf "\r-----------------------------\n" | |
echo "Received Ctrl-C" | |
kill $pid | |
is_running=0 | |
} | |
trap handler usr1 | |
trap handle_ctrl_c SIGINT | |
run_command | |
while [ $is_running -eq 1 ] ; do | |
sleep 0.5 | |
done | |
# reset all traps | |
trap - usr1 | |
trap - SIGINT | |
echo "Quiting..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment