about summary refs log tree commit diff
path: root/configs/linux/misc/.config/i3/i3-and-emacs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2019-01-13T19·26-0500
committerWilliam Carroll <wpcarro@gmail.com>2019-01-13T19·26-0500
commit6842ecd3be417e9212e4d832c069285d0c5ab760 (patch)
treeaf259972e2d5401fcc1a643f6968d50e14d01c77 /configs/linux/misc/.config/i3/i3-and-emacs
parent8b09557f383b78c8ecd9e46c9f459deb117a42d4 (diff)
Update linux configs
- Updates IRSSI config, XInitRC, i3 config
Diffstat (limited to 'configs/linux/misc/.config/i3/i3-and-emacs')
-rwxr-xr-xconfigs/linux/misc/.config/i3/i3-and-emacs45
1 files changed, 45 insertions, 0 deletions
diff --git a/configs/linux/misc/.config/i3/i3-and-emacs b/configs/linux/misc/.config/i3/i3-and-emacs
new file mode 100755
index 000000000000..ed912b7da830
--- /dev/null
+++ b/configs/linux/misc/.config/i3/i3-and-emacs
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+
+# Heavily inspired by this blog post:
+# https://bl.ocks.org/mijoharas/b9d09daed9654ca8d0d081015209ecd0
+
+get_focused_window() {
+  i3-msg -t get_tree | jq -r ".. | select(.focused? == true).window_properties.class"
+}
+
+perform_close() {
+  if [ "$(get_focused_window)" = "Emacs" ]; then
+    emacsclient -e "(delete-window)"
+    result=$?
+    if [ $result -ne 0 ]; then
+      i3-msg kill
+    fi
+  else
+    i3-msg kill
+  fi
+}
+
+perform_move() {
+  if [ "$(get_focused_window)" = "Emacs" ]; then
+    emacsclient -e "(evil-window-$1 1)"
+    result=$?
+    if [ $result -ne 0 ]; then
+      i3-msg focus "$1"
+    fi
+  else
+    i3-msg focus "$1"
+  fi
+}
+
+case "$1" in
+  left)  ;&
+  right) ;&
+  up)    ;&
+  down)
+    perform_move "$1"
+    ;;
+  quit)
+    perform_close
+    ;;
+  *) echo "command not found" ;;
+esac