Implement fhackeditor, which opens or connects to an existing neovim instance

This commit is contained in:
Marko Korhonen 2025-07-25 10:40:09 -05:00
parent 80bf43eaba
commit f4b71c3054
Signed by: FunctionalHacker
GPG key ID: A7F78BCB859CD890
9 changed files with 76 additions and 42 deletions

View file

@ -0,0 +1,2 @@
os:
editCommand: 'fhackeditor'

View file

@ -0,0 +1 @@
neovim-bin = "{{@@ env['HOME'] @@}}/.scripts/fhackeditor"

View file

@ -43,8 +43,8 @@ export PATH="$HOME/.local/share/nvim/mason/bin:$PATH"
# go path
export GOPATH=~/.go
# Add dotfile scripts dir to path
export PATH="$PATH:$DOTREPO/scripts"
# Add scripts dir to path
export PATH="$PATH:$HOME/.scripts"
# fzf settings
export FD_COMMAND='fd -HLt'
@ -73,7 +73,7 @@ _fzf_complete_pass() {
}
# nvim ftw!
export EDITOR=nvim
export EDITOR='nvim'
export PAGER="$EDITOR -R +\"lua require 'pager'\""
export GIT_PAGER="$EDITOR -c 'set ft=git' -R +\"lua require 'pager'\""
export PARU_PAGER="$PAGER -c 'set ft=PKGBUILD'"

View file

@ -18,6 +18,10 @@ alias o='xdg-open'
# and handling merges
alias dv='nvim +DiffviewOpen'
alias nvim="fhackeditor"
alias vim='nvim'
alias vi='nvim'
# Rename grc alias from forgit since it
# collides with the grc colorizer
forgit_revert_commit=fgrc

27
home/.scripts/fhackeditor Executable file
View file

@ -0,0 +1,27 @@
#!/bin/sh
# Script to launch a new NeoVim instance or reuse an existing one
# Exit on error
set -e
# Settings
SOCKET="/tmp/nvim.{{@@ env['USER'] @@}}/server.pipe"
# Convert each argument to absolute path
abs_args=""
for arg in "$@"; do
case "$arg" in
/*) abs="$arg" ;; # already absolute
*) abs="$(pwd)/$arg" ;;
esac
abs_args="$abs_args \"$abs\""
done
if [ -S "$SOCKET" ]; then
# Pipe exists and is a socket — reuse it
echo "Sending file to existing NeoVim instance"
eval exec nvim --server "$SOCKET" --remote $abs_args
else
# Socket doesn't exist — start new instance
exec nvim --listen "$SOCKET" "$@"
fi

View file

@ -0,0 +1,9 @@
#!/bin/sh
acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi
}

54
home/.scripts/reboot-moria Executable file
View file

@ -0,0 +1,54 @@
#!/bin/sh
set -e
# The IP address or hostname where the remote computer can be reached
REMOTE_HOST="moria"
# Remote computer's SSH port
REMOTE_SSH_PORT="221"
# SSH command to connect the remote computer via SSH
REMOTE_SSH="ssh -p $REMOTE_SSH_PORT moria"
# SSH command to connect the remote computer via SSH for unlocking
REMOTE_SSH_UNLOCK="ssh -p $REMOTE_SSH_PORT moria-unlock"
wait_for_down() {
while ping -c 1 -W 1 "$REMOTE_HOST" >/dev/null 2>&1; do
sleep 1
done
}
wait_for_up() {
while ! nc -w 1 -z "$REMOTE_HOST" "$REMOTE_SSH_PORT" >/dev/null 2>&1; do
sleep 1
done
}
run_ssh() {
if ! eval "$1"; then
if [ "$2" != "allow-fail" ]; then
echo "SSH failed: $1"
exit 1
fi
fi
}
echo "Rebooting remote now"
run_ssh "$REMOTE_SSH 'reboot'"
echo "Waiting for remote to go down..."
wait_for_down
echo "Waiting for remote to come back up..."
wait_for_up
echo "Remote is ready for unlock"
run_ssh "$REMOTE_SSH_UNLOCK" allow-fail
echo "Waiting for remote to come back up..."
sleep 3
wait_for_up
echo "Remote is back online, starting SSH session"
run_ssh "$REMOTE_SSH"