-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvim-isolated
52 lines (43 loc) · 1.77 KB
/
nvim-isolated
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
#!/usr/bin/env bash
runIsolated() {
declare -a bindPaths
declare nvimExecutable nvimAppDir cacheDir dataDir stateDir sandboxedNvimAppDir nvimAppName
configDir="$1"
nvimExecutable="$2"
if ! [[ -e $nvimExecutable ]]; then
echo Cannot find executable "$nvimExecutable". >&2
return 1
fi
shift 2
if [[ $NVIM ]] && systemd-detect-virt --private-users; then
exec "$nvimExecutable" "$@"
return $?
fi
nvimAppName="${NVIM_APPNAME:-nvim}"
nvimAppDir="${configDir}/${nvimAppName}"
sandboxedNvimAppDir=${HOME}/.config/${nvimAppName}
cacheDir="${configDir}/.xdg/cache"
dataDir="${configDir}/.xdg/data"
stateDir="${configDir}/.xdg/state"
mkdir -p "$nvimAppDir" "$cacheDir" "$dataDir" "$stateDir"
mapfile -t bindPaths <<-EOF
${nvimAppDir}:${sandboxedNvimAppDir}
${cacheDir}:${HOME}/.cache/${nvimAppName}
${dataDir}:${HOME}/.local/share/${nvimAppName}
${stateDir}:${HOME}/.local/state/${nvimAppName}
EOF
# Try to increase /proc/sys/fs/inotify/max_user_instances against "too many open files"
# BindPaths implies PrivateUsers: the owner inside /etc/ssh/ssh_config.d becomes`nobody`
exec systemd-run --quiet --user --pty --pipe --same-dir \
--property=InaccessiblePaths=/etc/ssh/ssh_config.d \
--property=BindPaths="${bindPaths[*]}" \
--setenv=NVIM_UNSANDBOXED_CONFIGDIR="${nvimAppDir}" \
--setenv=NVIM_FROM_SRC_DIR="${NVIM_FROM_SRC_DIR}" \
--setenv=PWD="${PWD}" \
${GIT_DIR:+--setenv=GIT_DIR="$GIT_DIR"} \
${GIT_WORK_TREE:+--setenv=GIT_WORK_TREE="$GIT_WORK_TREE"} \
${SSH_TTY:+--setenv=SSH_TTY="$SSH_TTY"} \
${TMUX:+--setenv=TMUX="$TMUX"} \
${COLORTERM:+--setenv=COLORTERM="$COLORTERM"} \
-- "$nvimExecutable" "$@"
}