[go: up one dir, main page]

Skip to content

Commit

Permalink
remove the commented-out code
Browse files Browse the repository at this point in the history
  • Loading branch information
lo-tp committed Mar 10, 2017
1 parent 5c88101 commit f6a937d
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions scripts/safekill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,40 @@
set -e

function safe_end_procs {
old_ifs="$IFS"
IFS=$'\n'
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"
if [[ "$pane_proc" == "vim" ]] || [[ "$pane_proc" == "nvim" ]]; then
cmd='":qa" Enter'
elif [[ "$pane_proc" == "man" ]] || [[ "$pane_proc" == "less" ]]; then
cmd='"q"'
elif [[ "$pane_proc" == "bash" ]] || [[ "$pane_proc" == "zsh" ]] || [[ "$pane_proc" == "fish" ]]; then
cmd='C-c C-u space "exit" Enter'
elif [[ "$pane_proc" == "ssh" ]] || [[ "$pane_proc" == "vagrant" ]]; then
cmd='Enter "~."'
elif [[ "$pane_proc" == "psql" ]]; then
cmd='Enter "\q"'
fi
echo $cmd | xargs tmux send-keys -t "$pane_id"
# echo $pane_set
done
IFS="$old_ifs"
old_ifs="$IFS"
IFS=$'\n'
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"
if [[ "$pane_proc" == "vim" ]] || [[ "$pane_proc" == "nvim" ]]; then
cmd='":qa" Enter'
elif [[ "$pane_proc" == "man" ]] || [[ "$pane_proc" == "less" ]]; then
cmd='"q"'
elif [[ "$pane_proc" == "bash" ]] || [[ "$pane_proc" == "zsh" ]] || [[ "$pane_proc" == "fish" ]]; then
cmd='C-c C-u space "exit" Enter'
elif [[ "$pane_proc" == "ssh" ]] || [[ "$pane_proc" == "vagrant" ]]; then
cmd='Enter "~."'
elif [[ "$pane_proc" == "psql" ]]; then
cmd='Enter "\q"'
fi
echo $cmd | xargs tmux send-keys -t "$pane_id"
done
IFS="$old_ifs"
}

function safe_kill_panes_of_current_session {
session_name=$(tmux display-message -p '#S')
current_panes=$(tmux list-panes -a -F "#{pane_id} #{pane_current_command} #{session_name}\n" | grep "$session_name")
current_panes=$(tmux list-panes -a -F "#{pane_id} #{pane_current_command} #{session_name}\n" | grep "$session_name")

IFS=$'\n'
array=($current_panes)
# Restore IFS
IFS=$SAVEIFS
for (( i=0; i<${#array[@]}; i++ ))
do
# echo "${array[$i]}"
safe_end_procs "${array[$i]}"
sleep 0.8
safe_end_procs "${array[$i]}"
sleep 0.8
done
}

Expand Down

0 comments on commit f6a937d

Please sign in to comment.