sced: made it better?
This commit is contained in:
parent
1913382d64
commit
8e847ad111
1 changed files with 11 additions and 7 deletions
|
@ -1,21 +1,25 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
# sced (script edit) edit a script or function that's somewhere inside the shell configuration
|
||||
# Usage: bined <script name>
|
||||
# Depends: fd
|
||||
|
||||
set -eu
|
||||
|
||||
above_dir="$(dirname "$(realpath "$0")")"/..
|
||||
|
||||
# start in the directory above the script
|
||||
cd "$(dirname "$(realpath "$0")")"/.. || exit 1
|
||||
cd "$above_dir"
|
||||
|
||||
# get the path to the file if there was an argument
|
||||
if [ -n "$1" ]; then
|
||||
FILE="$(fd --exact-depth 2 --max-results=1 -at f "$1")"
|
||||
if [ "$FILE" = '' ]; then
|
||||
FILE="$(dirname "$(realpath "$0")")/../$1"
|
||||
file="$(fd --exact-depth 2 --max-results=1 -at f "$1")"
|
||||
if [ -z "$file" ]; then
|
||||
file="$(dirname "$(realpath "$0")")/../$1"
|
||||
fi
|
||||
else
|
||||
# edit >this< script by default
|
||||
FILE="$(realpath "$0")"
|
||||
file="$(realpath "$0")"
|
||||
fi
|
||||
|
||||
# edit the file
|
||||
"${EDITOR:-$(which nvim)}" "${FILE:-$(realpath "$0")}"
|
||||
eval "${EDITOR:-$(which nvim)} ${file:-$(realpath "$0")}"
|
||||
|
|
Loading…
Add table
Reference in a new issue