about summary refs log tree commit diff
path: root/configs/linux/misc/.config/i3/i3-navigate-emacs
blob: f973c6667f74f6d68656e1617f3eb9808efe9517 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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)"
  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