#!/usr/bin/env bash set -fe -o pipefail eval "$(direnv export bash 2>/dev/null)" PATH="$HOME/bin:$PATH" if [ -n "$1" ]; then _file=$(readlink -f "$@") else FZF=${FZF:-"fzf-tmux -p 90%,50% -y 0"} _root=$(git rev-parse --show-toplevel 2>/dev/null || jj workspace 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 .jj --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}" fre --store_name "$_store" --add "$_file" fi fre --store_name "edit-history" --add "$_file" _nvim_socket="$XDG_RUNTIME_DIR/nvim-persistent.sock" (tmux select-window -t nvim 2>/dev/null && tmux select-pane -t 0) && exec nvim --server "$_nvim_socket" --remote "$_file" # nvim is not running/listening on remote socket, so start it. tmux new-window -S -t 42 -n nvim \ -e "AR=$AR" \ -e "AS=$AS" \ -e "BUILD_COMMAND=$BUILD_COMMAND" \ -e "CC=$CC" \ -e "CXX=$CXX" \ -e "GOFLAGS=$GOFLAGS" \ -e "GOPACKAGESDRIVER=$GOPACKAGESDRIVER" \ -e "LC_ALL=$LC_ALL" \ -e "LD=$LD" \ -e "NM=$NM" \ -e "NM=$NM" \ -e "OBJCOPY=$OBJCOPY" \ -e "OBJDUMP=$OBJDUMP" \ -e "PATH=$PATH" \ -e "RANLIB=$RANLIB" \ -e "READELF=$READELF" \ -e "RUST_SRC_PATH=$RUST_SRC_PATH" \ -e "SIZE=$SIZE" \ -e "STRIP=$STRIP" \ nvim --listen "$_nvim_socket" "$_file"