diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/focus-sway | 10 | ||||
| -rwxr-xr-x | scripts/open-emacs | 14 | ||||
| -rwxr-xr-x | scripts/open-emacs-project | 30 |
3 files changed, 54 insertions, 0 deletions
diff --git a/scripts/focus-sway b/scripts/focus-sway new file mode 100755 index 0000000..e3c63fb --- /dev/null +++ b/scripts/focus-sway @@ -0,0 +1,10 @@ +#!/bin/bash + +# Get available windows +windows=$(swaymsg -t get_tree | jq -r '.nodes[1].nodes[].nodes[] | .. | (.id|tostring) + " " + .name?' | grep -e "[0-9]* ." ) + +# Select window with rofi +selected=$(echo "$windows" | swenu -coil 10 | awk '{print $1}') + +# Tell sway to focus said window +swaymsg [con_id="$selected"] focus diff --git a/scripts/open-emacs b/scripts/open-emacs new file mode 100755 index 0000000..15b0794 --- /dev/null +++ b/scripts/open-emacs @@ -0,0 +1,14 @@ +#!/bin/bash + +emacsclient -e '(message "")' 2>&1 >/dev/null || emacs --daemon & + +emacs_attached() { + [ "$(emacsclient -e '(- (length (frame-list)) 1)')" = 0 ] && return 1 || return 0 +} + +if emacs_attached; then + # 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 +else + emacsclient -c +fi diff --git a/scripts/open-emacs-project b/scripts/open-emacs-project new file mode 100755 index 0000000..a5e4338 --- /dev/null +++ b/scripts/open-emacs-project @@ -0,0 +1,30 @@ +#!/bin/bash + +emacsclient -e '(message "")' 2>&1 >/dev/null || emacs --daemon & + +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 |
