Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: autoload variables
hello zsh users,
> We can autoload functions but is there a way to autoload variables?
i was hoping for a better answer than mine (reading this list provides
me so many "wow" moments). the way i dealt years ago to deal with my
"too heavy .zshenv" is to write what i call "modules"
<<\. cat > /usr/local/bin/mynetstuff.zsh
# yes i use setopt pathdirs :)
export IFUP=$( ip -4 r |sed ...)
mynetstuff/thing () { ... }
mynetstuff/stuff () { ... }
.
now i can run
. mynetstuff.zsh
when i need my net stuff. to unload functions, you can write
unset 'functions['$^functions[(I)mynetstuff/*]']'
oth.
besides: if the sed command is for real, i'm curious about
how it works:
sed -n -e '/^default/ s/^default.*dev //; s/ > .*// p;q'
my guess is it is equivalent to
sed -r '/^default dev (\S+) .*/!d; s//\1/; q'
or
ip -4 r | sed -r '/^default dev /!d; s///; s/ .*//; q'
but as you quit anyway, i assume you *know* that what you need is on the
first line so this should do the job:
ip -4 r | head -n1 | cut -d' ' -f3
regards,
marc
Messages sorted by:
Reverse Date,
Date,
Thread,
Author