dotfiles/bin/tmux-hx-helper

44 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
set -eo 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%,90% -y 0"}
_root=$(git rev-parse --show-toplevel 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 --ignore-file "${_root}/.gitignore" . "$_root") | cat -n | sort -k2 -k1n | uniq -f1 | sort -nk1,1 | cut -f2- | sed -e "s#^${_root}/##" | $FZF --no-sort --preview "bat {}" --preview-window=bottom,70%,border-top --color=bg+:16,fg+:49,pointer:49 --layout=reverse "--bind=alt-e:become(tmux-edit-history)")
_file="${_root}/${_file}"
fre --store_name "$_store" --add "$_file"
fi
fre --store_name "edit-history" --add "$_file"
tmux-shortcut 1 env \
"AR=$AR" \
"AS=$AS" \
"BUILD_COMMAND=$BUILD_COMMAND" \
"CC=$CC" \
"CXX=$CXX" \
"GOFLAGS=$GOFLAGS" \
"GOPACKAGESDRIVER=$GOPACKAGESDRIVER" \
"LC_ALL=$LC_ALL" \
"LD=$LD" \
"NM=$NM" \
"NM=$NM" \
"OBJCOPY=$OBJCOPY" \
"OBJDUMP=$OBJDUMP" \
"PATH=$PATH" \
"RANLIB=$RANLIB" \
"READELF=$READELF" \
"RUST_SRC_PATH=$RUST_SRC_PATH" \
"SIZE=$SIZE" \
"STRIP=$STRIP" \
helix "${_file}"
sleep 0.1
tmux send-keys Escape &&
tmux send-keys ":open ${_file}" Enter ":reload" Enter