3 ms·
These are necessarily bash functions, not executables, but here are two tools I'm proud of, which seem similar in spirit to vidir & vipe: # Launch $EDITOR
by pjungwir 5y ago
These are necessarily bash functions, not executables, but here are two tools I'm proud of, which seem similar in spirit to vidir & vipe:
# Launch $EDITOR to let you edit your env vars.
function viset() {
if [ -z "$1" ]; then
echo "USAGE: viset THE_ENV_VAR"
exit 1
else
declare -n ref=$1
f=$(mktemp)
echo ${!1} > $f
$EDITOR $f
ref=`cat $f`
export $1
fi
}
# Like viset, but breaks up the var on : first,
# then puts it back together after you're done editing.
# Defaults to editing PATH.
#
# TODO: Accept a -d/--delimiter option to use something besides :.
function vipath() {
varname="${1:-PATH}"
declare -n ref=$varname
f=$(mktemp)
echo ${!varname} | tr : "\n" > $f
$EDITOR $f
ref=`tr "\n" : < $f`
export $varname
}
Mostly I use vipath because I'm too lazy to figure out why tmux makes rvm so angry. . . .
I guess a cool addition to viset would be to accept more than one envvar, and show them on multiple lines. Maybe even let you edit your entire env if you give it zero args. Having autocomplete-on-tab for viset would be cool too. Maybe even let it interpret globs so you can say `viset AWS*`.
Btw I notice I'm not checking for an empty $EDITOR. That seems like it could be a problem somewhere.