[go: up one dir, main page]

Skip to content

Commit

Permalink
add option to close only the current window
Browse files Browse the repository at this point in the history
  • Loading branch information
mMontu committed Jun 17, 2016
1 parent 5d59242 commit 1e26679
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ In tmux, use the command:

The plugin will attempt to recursively end processes it knows about (right now: vim, man, less, bash, zsh, and ssh). It defaults to `Ctrl-C` for processes it doesn't know about. Ultimately, the session should have exited on its own after all child processes are gone.

It is also possible to close only the panes in the current window:

```
<prefix> Q
```

Warning: this is kind of a big hammer. If you have any sensitive processes, make sure they are dealt with before running this :-)

### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
Expand Down
1 change: 1 addition & 0 deletions safekill.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
tmux bind-key C run-shell "$CURRENT_DIR/scripts/safekill.sh"
tmux bind-key Q run-shell "$CURRENT_DIR/scripts/safekill.sh w"
14 changes: 11 additions & 3 deletions scripts/safekill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ set -e
function safe_end_procs {
old_ifs="$IFS"
IFS=$'\n'
panes=$(tmux list-panes -s -F "#{pane_id} #{pane_current_command}")
for pane_set in $panes; do
for pane_set in $1; do
pane_id=$(echo "$pane_set" | awk -F " " '{print $1}')
pane_proc=$(echo "$pane_set" | awk -F " " '{print tolower($2)}')
cmd="C-c"
Expand All @@ -26,9 +25,18 @@ function safe_end_procs {
}

safe_end_tries=0
window_count=$(tmux list-windows | wc -l)
while [ $safe_end_tries -lt 5 ]; do
safe_end_procs
if [ $1 == "w" ]; then
panes=$(tmux list-panes -F "#{pane_id} #{pane_current_command}")
else
panes=$(tmux list-panes -s -F "#{pane_id} #{pane_current_command}")
fi
safe_end_procs "$panes"
safe_end_tries=$[$safe_end_tries+1]
sleep 0.8
if [ $1 == "w" ] && [ $window_count -ne $(tmux list-windows | wc -l) ]; then
exit 0
fi
done
tmux send-message "Could not end all processes, you're on your own now!"

0 comments on commit 1e26679

Please sign in to comment.