Skip to content

Instantly share code, notes, and snippets.

@douglaswth
Last active April 13, 2017 18:17
Show Gist options
  • Save douglaswth/fb55be8aa144d97f908f0ad43bd9d0ac to your computer and use it in GitHub Desktop.
Save douglaswth/fb55be8aa144d97f908f0ad43bd9d0ac to your computer and use it in GitHub Desktop.
# 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