Last active
August 17, 2020 18:15
-
-
Save windwp/273387a73f902ae49c7c90d612fd2238 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 | |
# 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_s.sh | |
#augroup end | |
idfile="/tmp/runner_pid.txt" | |
if [ ! -f "${idfile}" ] | |
then | |
touch "$idfile" | |
fi | |
tid=$(xdo id) | |
echo "kill id" | cat $idfile | |
echo $pwd | |
kill $(cat "$idfile") | |
echo $@ | |
command="$@" | |
# my script have swallow function on i3 if you don't want to use it remove swallow -p ${tid} | |
command="alacritty --hold --working-directory $pwd -e swallow -p ${tid} $command" | |
# command="alacritty --hold --working-directory $pwd -e $command " | |
handler(){ | |
echo "handler was called." | |
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 | |
$command & | |
pid=$! | |
sleep 1 | |
# do what ever you want to update layout | |
# focus back on vim | |
i3-msg '[title="nvim"] focus' | |
} | |
trap handler usr1 | |
$command & | |
pid=$! | |
echo "press 'q' to exit" | |
count=0 | |
while : ; do | |
read -n 1 k <&1 | |
if [[ $k = q ]] ; then | |
printf "\nquitting from the program\n" | |
break | |
else | |
((count=$count+1)) | |
printf "\niterate for $count times\n" | |
echo "press 'q' to exit" | |
fi | |
done | |
# reset all traps | |
trap - usr1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment