2022-07-27 16:19:21 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-02-02 09:37:07 +01:00
|
|
|
set -fe -o pipefail
|
2022-07-27 16:19:21 +02:00
|
|
|
|
2023-02-12 11:36:35 +01:00
|
|
|
eval "$(direnv export bash)"
|
|
|
|
|
2022-07-27 16:19:21 +02:00
|
|
|
if [ -n "$1" ]; then
|
2022-11-22 09:56:09 +01:00
|
|
|
_file=$(readlink -f "$@")
|
2022-07-27 16:19:21 +02:00
|
|
|
else
|
2022-11-22 09:56:09 +01:00
|
|
|
FZF=${FZF:-"fzf-tmux -p 90%,50% -y 0"}
|
2023-01-19 20:53:26 +01:00
|
|
|
_root=$(git rev-parse --show-toplevel 2>/dev/null || sl root 2>/dev/null || pwd)
|
|
|
|
_store=$(echo "$_root" | sha1sum | cut -d ' ' -f 1)
|
|
|
|
_file=$( ( (fre --store_name "$_store" --sorted | xargs -n 100 ls -d 2>/dev/null || true) && fd --type f --hidden --follow --exclude .git --exclude .sl --ignore-file "${_root}/.gitignore" . "$_root") | cat -n | sort -k2 -k1n | uniq -f1 | sort -nk1,1 | cut -f2- | sed -e "s#^${_root}/##" | $FZF --no-sort)
|
|
|
|
_file="${_root}/${_file}"
|
2022-11-22 09:56:09 +01:00
|
|
|
fre --store_name "$_store" --add "$_file"
|
2022-07-27 16:19:21 +02:00
|
|
|
fi
|
|
|
|
|
2023-03-08 23:27:35 +01:00
|
|
|
_nvim_socket="$XDG_RUNTIME_DIR/nvim-persistent.sock"
|
|
|
|
|
2023-03-07 22:56:45 +01:00
|
|
|
function _nvim_setenv() {
|
2023-03-08 23:27:35 +01:00
|
|
|
nvim --server "$_nvim_socket" --remote-expr "execute(\"let \$${1} = \\\"${2}\\\"\")"
|
2023-03-07 22:56:45 +01:00
|
|
|
}
|
|
|
|
|
2023-03-08 23:27:35 +01:00
|
|
|
nvim --server "$_nvim_socket" --remote-expr "42" 2>/dev/null ||
|
|
|
|
(rm -f "$_nvim_socket" && wezterm cli spawn --cwd "${PWD}" nvim --listen "$_nvim_socket" && sleep 0.5)
|
2023-03-07 22:56:45 +01:00
|
|
|
|
|
|
|
_nvim_setenv BUILD_COMMAND "$BUILD_COMMAND"
|
|
|
|
_nvim_setenv GOPACKAGESDRIVER "$GOPACKAGESDRIVER"
|
|
|
|
_nvim_setenv GOFLAGS "$GOFLAGS"
|
2022-12-03 14:06:37 +01:00
|
|
|
|
2023-03-08 23:27:35 +01:00
|
|
|
nvim --server "$_nvim_socket" --remote "$_file"
|
2023-03-07 22:56:45 +01:00
|
|
|
|
|
|
|
printf "\033]1337;SetUserVar=%s=%s\007" nvim_activate $(date +%s | base64)
|