-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·70 lines (63 loc) · 1.96 KB
/
start
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
64
65
66
67
68
69
70
#!/bin/sh
set -e
set -u
xdg_dirs() {
local dirs home
eval "dirs=\${XDG_$1_DIRS:-}; home=\${XDG_$1_HOME:-}"
if [ -n "${dirs:-}" ]; then
echo "$dirs"
elif [ -n "${home:-}" ]; then
echo "$home"
else
echo "$HOME/$2"
fi
}
HERE="$(dirname "$(readlink -e "$0")")"
SOCKET_DIR="${XDG_RUNTIME_DIR:-/tmp}/Bretts"
EMACS_SOCKET_NAME="$SOCKET_DIR/Emacs"
export PATH="$PATH:$HERE/.local/bin"
export SCREENDIR="$SOCKET_DIR/screen"
export TMUX_TMPDIR="$SOCKET_DIR"
export XDG_CONFIG_DIRS="$HERE/.config:$(xdg_dirs CONFIG .config)"
export XDG_CONFIG_HOME="$HERE/.config"
export XDG_DATA_DIRS="$HERE/data:$(xdg_dirs DATA .local/share)"
export XDG_DATA_HOME="$HERE/data"
export XDG_STATE_DIRS="$HERE/state:$(xdg_dirs STATE .local/state)"
export XDG_STATE_HOME="$HERE/state"
export ZDOTDIR="$XDG_CONFIG_HOME/bcsh"
unset DISPLAY WAYLAND_DISPLAY
if ! SHELL="$(which zsh 2>/dev/null)"; then
SHELL="$HERE/bcsbash"
fi
export SHELL
mkdir -p --mode=0700 "$SCREENDIR" "$XDG_DATA_HOME" "$XDG_STATE_HOME"
umask 027
if command -v emacsclient >/dev/null; then
emacs_eval() {
if [ $# = 0 ]; then
set -- t
fi
emacsclient --socket-name="$EMACS_SOCKET_NAME" --alternate-editor=false \
--eval "$@" >/dev/null 2>&1
}
emacs_load=true
if emacs_eval; then
emacs_load=false
elif [ -e "/var/lib/systemd/linger/$USER" ]; then
systemd-run --user \
--unit="brett-emacs-$(date +%Y-%m-%dT%H:%M)" \
emacs --fg-daemon="$EMACS_SOCKET_NAME" --no-init-file
else
emacs --daemon="$EMACS_SOCKET_NAME" --no-init-file
fi
if $emacs_load; then
while ! emacs_eval; do
sleep .1
done
nohup emacsclient --socket-name="$EMACS_SOCKET_NAME" \
--eval "(load-file \"$XDG_CONFIG_HOME/emacs/init.el\")" \
>>"$SOCKET_DIR/Emacs.log" 2>&1 &
fi
export EMACS_SOCKET_NAME
fi
exec "$HERE/.local/bin/reattach" -C "$HERE"