zsh: add sced (script edit)
This commit is contained in:
parent
86ce2abd6e
commit
eccae5b262
1 changed files with 21 additions and 0 deletions
21
.config/shell/bin/sced
Executable file
21
.config/shell/bin/sced
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
# sced (script edit) edit a script or function that's somewhere inside the shell configuration
|
||||
# Usage: bined <script name>
|
||||
# Depends: fd
|
||||
|
||||
# start in the directory above the script
|
||||
cd "$(dirname "$(realpath "$0")")"/.. || exit 1
|
||||
|
||||
# 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"
|
||||
fi
|
||||
else
|
||||
# edit >this< script by default
|
||||
FILE="$(realpath "$0")"
|
||||
fi
|
||||
|
||||
# edit the file
|
||||
"${EDITOR:-$(which nvim)}" "${FILE:-$(realpath "$0")}"
|
Loading…
Add table
Reference in a new issue