diff options
author | eug-vs <eug-vs@keemail.me> | 2020-12-10 18:32:12 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-01-06 21:28:40 +0300 |
commit | c4ae2519dc8238390624af05602c364b39b5b77d (patch) | |
tree | 9fccc440474b5ad3b2c099c4ab8d3d95607b0874 | |
parent | c3b78d929f3c0bf58890904ea3c07b470057b35f (diff) | |
download | dotfiles-c4ae2519dc8238390624af05602c364b39b5b77d.tar.gz |
feat: bind all movements to Super+hjkl
-rw-r--r-- | .config/i3/config | 8 | ||||
-rw-r--r-- | .config/nvim/vim-plug/plugins.vim | 3 | ||||
-rwxr-xr-x | .local/bin/i3_tmux_vim_focus | bin | 0 -> 17272 bytes | |||
-rwxr-xr-x | .local/bin/i3_tmux_vim_focus.c | 78 | ||||
-rwxr-xr-x | .local/bin/tmux_sys_win_aware_navigation.sh | 115 | ||||
-rw-r--r-- | .tmux.conf | 7 |
6 files changed, 205 insertions, 6 deletions
diff --git a/.config/i3/config b/.config/i3/config index 66604ff..861f27b 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -43,10 +43,10 @@ bindsym $mod+Shift+q kill bindsym $mod+d exec rofi -show combi -theme gruvbox-dark-soft # change focus -bindsym $mod+h focus left -bindsym $mod+j focus down -bindsym $mod+k focus up -bindsym $mod+l focus right +bindsym $mod+h exec "xdotool keyup Super h && i3_tmux_vim_focus left && xdotool keydown Super" +bindsym $mod+j exec "xdotool keyup Super j && i3_tmux_vim_focus down && xdotool keydown Super" +bindsym $mod+k exec "xdotool keyup Super k && i3_tmux_vim_focus up && xdotool keydown Super" +bindsym $mod+l exec "xdotool keyup Super l && i3_tmux_vim_focus right && xdotool keydown Super" # alternatively, you can use the cursor keys: bindsym $mod+Left focus left diff --git a/.config/nvim/vim-plug/plugins.vim b/.config/nvim/vim-plug/plugins.vim index cc0f2a9..51de831 100644 --- a/.config/nvim/vim-plug/plugins.vim +++ b/.config/nvim/vim-plug/plugins.vim @@ -6,7 +6,8 @@ call plug#begin('~/.config/nvim/autoload/plugged') Plug 'kristijanhusak/defx-icons' Plug 't9md/vim-choosewin' " Tmux navigator - Plug 'christoomey/vim-tmux-navigator' + " Plug 'christoomey/vim-tmux-navigator' + Plug 'fogine/vim-i3wm-tmux-navigator' " Color scheme Plug 'morhetz/gruvbox' " Editorconfig diff --git a/.local/bin/i3_tmux_vim_focus b/.local/bin/i3_tmux_vim_focus Binary files differnew file mode 100755 index 0000000..bf156f9 --- /dev/null +++ b/.local/bin/i3_tmux_vim_focus diff --git a/.local/bin/i3_tmux_vim_focus.c b/.local/bin/i3_tmux_vim_focus.c new file mode 100755 index 0000000..1429e3a --- /dev/null +++ b/.local/bin/i3_tmux_vim_focus.c @@ -0,0 +1,78 @@ +/* File: i3_vim_focus.c + * + * Compile with: + * gcc i3_tmux_vim_focus.c -lX11 -lxdo -o i3_tmux_vim_focus $(pkg-config --libs --cflags i3ipc-glib-1.0) + * + */ + +#include <stdio.h> + +#include <strings.h> +#include <string.h> + +#include <xdo.h> + +#include <glib/gprintf.h> +#include <i3ipc-glib/i3ipc-glib.h> + +int main(int argc, char *argv[]) { + + char cmd[20]; + + unsigned char *name; + int name_len; + int name_type; + Window window_ret; + + i3ipcConnection *conn; + gchar *reply; + + if(argc < 2){ + printf("Missing argument\n"); + return 1; + } + + xdo_t *xdo = xdo_new(NULL); + xdo_get_active_window(xdo, &window_ret); + xdo_get_window_name(xdo, window_ret, &name, &name_len, &name_type); + + puts(name); + if(strstr(name, "VIM") || strstr(name, "vim") && !strstr(name, "i3_tmux_vim_focus")) + { + strcpy(cmd, "Ctrl+c+Ctrl+"); + + + strcat(cmd, (argv[1][0] == 'l')? "h" : + (argv[1][0] == 'd')? "j" : + (argv[1][0] == 'u')? "k" : + "l" ); + puts(cmd); + + xdo_send_keysequence_window(xdo, window_ret, cmd, 0); + } + else if(strstr(name, "tmux")) + { + strcpy(cmd, "ctrl+a"); + + + xdo_send_keysequence_window(xdo, window_ret, cmd, 0); + strcpy(cmd, (argv[1][0] == 'l')? "Left" : + (argv[1][0] == 'd')? "Down" : + (argv[1][0] == 'u')? "Up" : + "Right" ); + + xdo_send_keysequence_window(xdo, window_ret, cmd, 0); + } + else + { + conn = i3ipc_connection_new(NULL, NULL); + strcpy(cmd, "focus "); + strcat(cmd, argv[1]); + reply = i3ipc_connection_message(conn, I3IPC_MESSAGE_TYPE_COMMAND, cmd, NULL); + g_free(reply); + g_object_unref(conn); + } + + XFree(name); + return 0; +} diff --git a/.local/bin/tmux_sys_win_aware_navigation.sh b/.local/bin/tmux_sys_win_aware_navigation.sh new file mode 100755 index 0000000..4fed4ae --- /dev/null +++ b/.local/bin/tmux_sys_win_aware_navigation.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +#export PS4="\$LINENO: " # Prints out the line number being executed by debug +#set -xv # Turn on debugging + +exists_another_pane_in_direction() { + local direction=$1 + local result=1 #false + + local paneList=$( + tmux list-panes -F '#{pane_top} #{pane_left} #{?pane_active,active,} ' + ) + + local paneActive=$( + echo "$paneList" | \ + grep 'active' | \ + tr -s ' ' + ) + + local paneNoActive=$( + echo "$paneList" | \ + grep -v 'active' + ) + + local paneActiveTop="$(echo "$paneActive" | cut -d' ' -f1)" + local paneActiveLeft="$(echo "$paneActive" | cut -d' ' -f2)" + + while read -r line; do + local left="$(echo "$line" | cut -d' ' -f2 | tr -d "[:blank:]" | tr -d "\n")" + local top="$(echo "$line" | cut -d' ' -f1)" + + if [ "$top" = '' ] && [ "$left" = '' ]; then + break # There is not other window + fi + + if [ "$direction" = 'up' ] + then + + if [ "$top" -lt "$paneActiveTop" ] && [ "$left" -eq "$paneActiveLeft" ] + then + local result=0 #true + break + fi + fi + + if [ "$direction" = 'right' ] + then + + if [ "$left" -gt "$paneActiveLeft" ] + then + local result=0 #true + break + fi + fi + + if [ "$direction" = 'down' ] + then + if [ "$top" -gt "$paneActiveTop" ] && [ "$left" -eq "$paneActiveLeft" ] + then + local result=0 #true + break + fi + fi + + if [ "$direction" = 'left' ] + then + if [ "$left" -lt "$paneActiveLeft" ] + then + local result=0 #true + break + fi + fi + done <<< "$paneNoActive" + + echo "$result" +} + +dir=$1 #direction +mode=$2 #if value = "tmux-only", navigation shortcuts won't apply in system's window scope + # ....so this script won't be used and navigation will be handled by tmux only + +if [ "$dir" = "up" ] +then + tmuxArg="U" +elif [ "$dir" = "right" ] +then + tmuxArg="R" +elif [ "$dir" = "down" ] +then + tmuxArg="D" +elif [ "$dir" = "left" ] +then + tmuxArg="L" +else + echo -e "Invalid dirrection parameter supplied\nUsage: tmux_sys_win_aware_navigation up|right|down|left" + exit 1 +fi + +if [ "$mode" = "tmux-only" ] +then + tmux select-pane -$tmuxArg + exit 0 +fi + +exists=$(exists_another_pane_in_direction $dir) + + +if [ $exists = '0' ] +then + tmux select-pane -$tmuxArg +else + i3-msg -q focus $dir +fi +exit 0 +#set +xv #end of debug @@ -22,8 +22,13 @@ bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection c # Vi mode set-window-option -g mode-keys vi +is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?|vifm)(diff)?$"' +bind -r left if-shell "$is_vim" "send-keys C-h" "run-shell 'tmux_sys_win_aware_navigation.sh left && tmux rename-window #{pane_current_command}'" +bind -r down if-shell "$is_vim" "send-keys C-j" "run-shell 'tmux_sys_win_aware_navigation.sh down && tmux rename-window #{pane_current_command}'" +bind -r up if-shell "$is_vim" "send-keys C-k" "run-shell 'tmux_sys_win_aware_navigation.sh up && tmux rename-window #{pane_current_command}'" +bind -r right if-shell "$is_vim" "send-keys C-l" "run-shell 'tmux_sys_win_aware_navigation.sh right && tmux rename-window #{pane_current_command}'" + # Plugins -set -g @plugin 'christoomey/vim-tmux-navigator' set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' |