all repos — dot @ master

Shell, editor and terminal configuration, and the tools that go with them

bin/alacritty-mosh (view raw)

 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
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
#!/bin/bash

set -euo pipefail

target="$1"
dedicated_dir='/tmp/alacritty'
# Unique per launch: cleanup deletes the files when the session inside ends,
# so a second window (or a relaunch racing a previous exit) must not share them.
dedicated_cfg="${dedicated_dir}/${target}.$$.conf"
dedicated_sh="${dedicated_dir}/${target}.$$.sh"
mkdir -p "${dedicated_dir}"

main_cfg="${HOME}/.config/alacritty/alacritty.toml"

# Alacritty loads config files in a way that doesn't allow terminal.shell to be
# overriden, so this doesn't work.
# cat > "${dedicated_cfg}" <<EOF
# # [general]
# # import = [
# #     "${main_cfg}",
# # ]
# [terminal.shell]
# args = ["--login", "-ic", "${dedicated_sh}"]
# program = "/bin/zsh"
# [window]
# title = "${target}"
# dynamic_title = false
# EOF

awk -v r='terminal.shell,window' '
/^\[/ {
    s = $0
    gsub(/^\[|\]$/, "", s)
    p = (index(","r",", ","s",") == 0)
}
p
' "${main_cfg}" > "${dedicated_cfg}"
cat >> "${dedicated_cfg}" <<EOF
[terminal.shell]
args = ["--login", "-ic", "${dedicated_sh}"]
program = "/bin/zsh"

[window]
title = "${target}"
dynamic_title = false
opacity = 0.96
# blur = true
decorations = "buttonless"
dynamic_padding = true
option_as_alt = "None"
EOF

cat > "$dedicated_sh" <<EOF
#!/bin/bash
cleanup() {
    rm -f "${dedicated_cfg}"
    rm -f "${dedicated_sh}"
}
trap cleanup EXIT INT TERM
mosh ${target} -- tmux new-session -As 0
EOF
chmod +x "$dedicated_sh"
open -n -a Alacritty --args --config-file "${dedicated_cfg}"