###############################################################################
#    Byobu f-key keybindings
#      This configuration profile is intended to provide a useful
#      keybindings using the keyboard's f-keys
#
#    Copyright (C) 2008  Nick Barcet <nick.barcet@canonical.com>
#                        Dustin Kirkland <kirkland@canonical.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
###############################################################################

# F-keys seem to work well in both gnome-terminal and tty consoles
bindkey -k k1 screen -t config 0 byobu-config		# F1  | Configuration (along with F9)
							#     | since F1 = Help in gnome-terminal
bindkey -k k2 screen					# F2  | Create new window
bindkey -k k3 eval 'prev' 'fit'				# F3  | Previous Window
bindkey -k k4 eval 'next' 'fit'				# F4  | Next Window
register r "^a:source $HOME/.byobu/profile^M"		#     | Goes with F5 definition
bindkey -k k5 eval 'process r'				# F5  | Reload profile
bindkey -k k6 detach					# F6  | Detach from this session
bindkey -k k7 copy					# F7  | Enter copy/scrollback mode
register t "^aA^aa^k^h"					#     | Goes with the F8 definition
bindkey -k k8 process t 				# F8  | Re-title a window
bindkey -k k9 screen -t config 0 byobu-config		# F9  | Configuration
							# F10 | 'toolbar' in gnome-terminal
							# F11 | 'fullscreen' in gnome-terminal
bindkey -k F2 lockscreen				# F12 | Lock this terminal
bind $ screen -t status 0 byobu-status-detail 		# ctrl-a $ | show detailed status
bind @ screen -t config 0 byobu-config			# ctrl-a @ | Configuration
bind R process r					# ctrl-a R | Reload profile
register s "^a[g G$>^h"					# Goes with ^a~ definition
bind ~ eval 'process s' 'exec sed -i -e "/./,/^$/!d" /var/run/screen/S-$USER/byobu-exchange' 'echo "See: /var/run/screen/S-$USER/byobu-exchange"' # ctrl-a ~ | write the buffer to file

# Hotkeys for splits (gnome-terminal)
bindkey "^[O1;2Q" eval 'split' 'focus down' 'next' 'focus up'		# shift-F2 | horizontal split
bindkey "^[O1;5Q" eval 'split -v' 'focus down' 'next' 'focus up'	# ctrl-F2  | vertical split
bindkey "^[O1;2R" focus up						# shift-F3 | focus up
bindkey "^[O1;2S" focus down						# shift-F4 | focus down
bindkey "^[[15;2~" only							# shift-F5 | kill all splits
bindkey "^[[17;2~" remove						# shift-F6 | kill this split

# Hotkeys for splits (tty)
bindkey "^[[26~" eval 'split' 'focus down' 'next' 'focus up'		# shift-F2 | horizontal split
									# ctrl-F2  | sadly, does not work in tty :-(
bindkey "^[[28~" focus up						# shift-F3 | focus up
bindkey "^[[29~" focus down						# shift-F4 | focus down
bindkey "^[[31~" only							# shift-F5 | kill all splits
bindkey "^[[32~" remove							# shift-F6 | kill this split

# Make it more logical how to enter scrollback
bindkey "^[[5;3~" copy					# alt-pageup | scrollback
bindkey "^[[6;3~" copy					# alt-pageup | scrollback

# Make socket reconnection a little easier
bindkey "^[[15;5~" eval 'process r' 'stuff ". $BYOBU_PREFIX/bin/byobu-reconnect-sockets^M"' # ctrl-F5 | reconnect gpg/ssh sockets

# Detach from an auto-launched byobu, but don't log out of the shell
bindkey "^[[17;2~" eval 'exec touch /var/run/screen/S-$USER/byobu.no-logout' 'detach'   # ctrl-F6 | detach, but don't logout

# toggle f-key keybindings off
register d "^a:source $BYOBU_PREFIX/share/byobu/keybindings/screen-escape-keys^M"
bind ! eval 'process d' 'backtick 111 9999999 9999999 byobu-status menu --disable-f-keys'	# ctrl-a-! | toggle on/off f-keys
