From a0355dbf88ef914799b05904e9d664d296e88015 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Wed, 11 Mar 2020 17:40:45 +0000 Subject: [PATCH] Adds ctrl+z binding --- shells/zsh/includes/keybindings.zsh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/shells/zsh/includes/keybindings.zsh b/shells/zsh/includes/keybindings.zsh index 18073521..8b87ba89 100644 --- a/shells/zsh/includes/keybindings.zsh +++ b/shells/zsh/includes/keybindings.zsh @@ -57,3 +57,25 @@ zle -N edit-command-line bindkey '\C-x\C-e' edit-command-line bindkey -M viins jj vi-cmd-mode + +# Make CTRL-Z background things and unbackground them. +# Based off https://github.com/wincent/wincent/commit/30b502d811fbf4ca058db3a6f006aaecab68f6b7 +function fg-bg() { + if [[ $#BUFFER -eq 0 ]]; then + local backgroundProgram="$(jobs | tail -n 1 | awk '{print $4}')" + if [[ "$backgroundProgram" == "nc" ]] || [[ "$backgroundProgram" == "ncat" ]]; then + # Make sure that /dev/tty is given to the stty command + local columns=$(stty -a < /dev/tty | grep -oE 'columns [0-9]+' | cut -d' ' -f2) + local rows=$(stty -a < /dev/tty | grep -oE 'rows [0-9]+' | cut -d' ' -f2) + notify-send "Terminal dimensions" "Rows: $rows\nColumns: $columns\nstty command on clipboard" + echo "stty rows $rows cols $columns" | clip + stty raw -echo < /dev/tty; fg + else + fg + fi + else + zle push-input + fi +} +zle -N fg-bg +bindkey '^Z' fg-bg