summaryrefslogtreecommitdiff
path: root/scripts/open-emacs-project
blob: 23df773692524f8a78097425cac3641faf56101f (plain)
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
#!/bin/bash

find_dirs() {
	echo $(emacsclient -e "(proj--get-paths)" | sed -ze 's/(\(.*\))/\1/') | xargs -n1
}

emacs_attached() {
    [ "$(emacsclient -e '(- (length (frame-list)) 1)')" = 0 ] && return 1 || return 0
}

switch_to() {
    if emacs_attached; then
        emacsclient -e "(proj-set-dir \"$1\")"
    else
        emacsclient -ce "(proj-set-dir \"$1\")"
    fi
}

# get selected
selected=$(find_dirs | swenu -coil 15)
[ -z "$selected" ] && exit 1;
selected="${selected/\~/$HOME}"

# set emacs project
switch_to "$selected"

# focus emacs
swaymsg [con_id="$(swaymsg -t get_tree | jq -r '.nodes[1].nodes[].nodes[] | .. | (.id|tostring) + " " + .name?' | grep -e "[0-9]* ." | grep Emacs | awk '{print $1}')"] focus