dotfiles/.config/shell/bin/sced

26 lines
615 B
Text
Raw Permalink Normal View History

2022-10-27 01:41:24 -07:00
#!/bin/sh
2022-01-13 17:59:21 -08:00
# sced (script edit) edit a script or function that's somewhere inside the shell configuration
# Usage: bined <script name>
# Depends: fd
2022-10-27 01:41:24 -07:00
set -eu
above_dir="$(dirname "$(realpath "$0")")"/..
2022-01-13 17:59:21 -08:00
# start in the directory above the script
2022-10-27 01:41:24 -07:00
cd "$above_dir"
2022-01-13 17:59:21 -08:00
# get the path to the file if there was an argument
if [ -n "$1" ]; then
2022-10-27 01:41:24 -07:00
file="$(fd --exact-depth 2 --max-results=1 -at f "$1")"
if [ -z "$file" ]; then
file="$(dirname "$(realpath "$0")")/../$1"
2022-01-13 17:59:21 -08:00
fi
else
# edit >this< script by default
2022-10-27 01:41:24 -07:00
file="$(realpath "$0")"
2022-01-13 17:59:21 -08:00
fi
# edit the file
2022-10-27 01:41:24 -07:00
eval "${EDITOR:-$(which nvim)} ${file:-$(realpath "$0")}"