Last active
April 13, 2017 18:17
-
-
Save douglaswth/fb55be8aa144d97f908f0ad43bd9d0ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Bash Logout | |
# | |
# Douglas Thrift | |
# | |
# .bash_logout | |
if [[ `< /proc/sys/kernel/osrelease` =~ Microsoft ]]; then | |
backgrounds=(`pgrep 'tmux|screen'`) | |
if [[ ${#backgrounds[@]} -ne 0 ]]; then | |
bashes=(`pgrep 'bash$'`) | |
for index in ${!bashes[@]}; do | |
parent=$(ps -o comm= -ww `ps -o ppid= -ww ${bashes[$index]}`) | |
if [[ ${bashes[$index]} -eq $BASHPID || ! $parent =~ ^(init|wslbridge-backe) ]]; then | |
unset bashes[$index] | |
fi | |
done | |
if [[ ${#bashes[@]} -eq 0 ]]; then | |
declare red=$'\e[1;31m' reset=$'\e[0m' | |
echo "${red}There are background processes still running! WSL will kill them if you exit.$reset" | |
ps -o pid,tname,command -q "${backgrounds[*]}" | |
read -p 'Really exit? (yes/no) [no] ' really | |
[[ $really != yes ]] && exec bash -l | |
fi | |
fi | |
fi | |
clear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment