Re: [i3] binding the same key to revert the command?
Hi, one possible solution: save the following as /some/path/stopcont.sh and bind bindsym $mod+p exec --no-startup-id /some/path/stopcont.sh Script: === #!/usr/bin/env bash PROCESS=${1} FILE="/tmp/${PROCESS}.signal" if [[ -f "${FILE}" ]]; then rm ${FILE} pkill -SIGCONT ${PROCESS} else touch ${FILE} pkill -SIGSTOP ${PROCESS} fi === This will, of course, assume that the process isn't paused by anything else as that would make it go out of sync. A better and more robust way would be to write the script such that it instead uses the information of /proc//stat to check whether the process is currently paused. If you use a higher-level language such as Python, you can do this nicely instead of manually parsing the output. See [1] for some more information. [1] http://stackoverflow.com/questions/6021771/is-there-a-way-to-determine-if-a-linux-pid-is-paused-or-not Ingo On 11/08/2015 04:16 AM, Zenny wrote: > Hi, > > I am trying to use a keybinding to pause a process temporily, > > bindsym $mod+p exec pkill -SIGSTOP > > But I could not figure out how to make pressing to same keybinding to > restart the process? > > Currenlty I am using, > > bindsym $mod+c exec pkill -SIGCONT > > Instead, I want something like re-pressing $mod+p executes pkill > -SIGCONT . > > Thanks! > > /z
Re: [i3] binding the same key to revert the command?
Hi, sorry, my last email didn't go to the mailing list which I diidn't even notice until this email. Below is my previous email as a quote which also has a script using /proc/../stat. Never hurts to have multiple solutions :) > Hi, > > here's a script using /proc/.../stat. The usage is as before. The only > assumption now is that the process is running exactly once. > > > #!/usr/bin/env bash > PROCESS=${1} > STATE=$(cat /proc/$(pgrep ${PROCESS})/stat | awk -F' ' '{print $3}') > > [[ "${STATE}" = "T" ]] && pkill -SIGCONT ${PROCESS} || pkill -SIGSTOP > ${PROCESS} > = On 11/08/2015 05:22 PM, Joep van Delft wrote: > Elaborating on Ingo's hints: Something like this could be used to not > to have > to maintain the state somewhere on disk: > > === > #!/usr/bin/env bash > process_name=$1 > for pid in $(pgrep --exact $process_name); do > # Assumes there is no space in the command name > if awk '$3=="T"{exit 1}' /proc/$pid/stat 2>/dev/null > then kill -SIGCONT $pid > else kill -SIGKILL $pid > fi > done > === > > > Kind regards, > > Joep > > > Ingo Bürk schreef op 2015-11-08 10:30: >> Hi, >> >> one possible solution: save the following as /some/path/stopcont.sh >> and bind >> >> bindsym $mod+p exec --no-startup-id /some/path/stopcont.sh >> >> >> Script: >> === >> #!/usr/bin/env bash >> PROCESS=${1} >> FILE="/tmp/${PROCESS}.signal" >> >> if [[ -f "${FILE}" ]]; then >> rm ${FILE} >> pkill -SIGCONT ${PROCESS} >> else >> touch ${FILE} >> pkill -SIGSTOP ${PROCESS} >> fi >> === >> >> This will, of course, assume that the process isn't paused by anything >> else as that would make it go out of sync. A better and more robust way >> would be to write the script such that it instead uses the information >> of /proc//stat to check whether the process is currently paused. If >> you use a higher-level language such as Python, you can do this nicely >> instead of manually parsing the output. See [1] for some more >> information. >> >> [1] >> http://stackoverflow.com/questions/6021771/is-there-a-way-to-determine-if-a-linux-pid-is-paused-or-not >> >> >> >> Ingo >> >> On 11/08/2015 04:16 AM, Zenny wrote: >>> Hi, >>> >>> I am trying to use a keybinding to pause a process temporily, >>> >>> bindsym $mod+p exec pkill -SIGSTOP >>> >>> But I could not figure out how to make pressing to same keybinding to >>> restart the process? >>> >>> Currenlty I am using, >>> >>> bindsym $mod+c exec pkill -SIGCONT >>> >>> Instead, I want something like re-pressing $mod+p executes pkill >>> -SIGCONT . >>> >>> Thanks! >>> >>> /z
Re: [i3] binding the same key to revert the command?
Hi Sege, On 11/8/15, Serge van Ginderachterwrote: > I have a script that does that, to pause dunst (whilst locking) and/or > disabling the autolock screensaver (for a presentation mode). > > The trick is to be able to check for a state, which I do by using gtrayicon > to visually show the current state, so the script can check whether to > enable or disable the mode. > > See https://github.com/srvg/dotfiles/blob/master/bin/presentation-mode Thanks for the input. Can you explain the usage in my case in particular. Cheers, /z > > On 8 November 2015 at 10:16, Zenny wrote: > >> Hi, >> >> I am trying to use a keybinding to pause a process temporily, >> >> bindsym $mod+p exec pkill -SIGSTOP >> >> But I could not figure out how to make pressing to same keybinding to >> restart the process? >> >> Currenlty I am using, >> >> bindsym $mod+c exec pkill -SIGCONT >> >> Instead, I want something like re-pressing $mod+p executes pkill >> -SIGCONT . >> >> Thanks! >> >> /z >> >
Re: [i3] binding the same key to revert the command?
Elaborating on Ingo's hints: Something like this could be used to not to have to maintain the state somewhere on disk: === #!/usr/bin/env bash process_name=$1 for pid in $(pgrep --exact $process_name); do # Assumes there is no space in the command name if awk '$3=="T"{exit 1}' /proc/$pid/stat 2>/dev/null then kill -SIGCONT $pid else kill -SIGKILL $pid fi done === Kind regards, Joep Ingo Bürk schreef op 2015-11-08 10:30: Hi, one possible solution: save the following as /some/path/stopcont.sh and bind bindsym $mod+p exec --no-startup-id /some/path/stopcont.sh Script: === #!/usr/bin/env bash PROCESS=${1} FILE="/tmp/${PROCESS}.signal" if [[ -f "${FILE}" ]]; then rm ${FILE} pkill -SIGCONT ${PROCESS} else touch ${FILE} pkill -SIGSTOP ${PROCESS} fi === This will, of course, assume that the process isn't paused by anything else as that would make it go out of sync. A better and more robust way would be to write the script such that it instead uses the information of /proc//stat to check whether the process is currently paused. If you use a higher-level language such as Python, you can do this nicely instead of manually parsing the output. See [1] for some more information. [1] http://stackoverflow.com/questions/6021771/is-there-a-way-to-determine-if-a-linux-pid-is-paused-or-not Ingo On 11/08/2015 04:16 AM, Zenny wrote: Hi, I am trying to use a keybinding to pause a process temporily, bindsym $mod+p exec pkill -SIGSTOP But I could not figure out how to make pressing to same keybinding to restart the process? Currenlty I am using, bindsym $mod+c exec pkill -SIGCONT Instead, I want something like re-pressing $mod+p executes pkill -SIGCONT . Thanks! /z