feat: split loadenv from readenv to load any file

This commit is contained in:
Klesh Wong 2021-09-23 17:14:29 +08:00
parent 7a15fceb1b
commit 50cae027bc

View File

@ -70,19 +70,23 @@ if status is-interactive
# === auto cd into last activated directory
test "$PWD" = "$HOME" && cd $last_pwd
function loadenv
while read -l line
set -l line (string trim $line)
if [ -z "$line" ]
continue
end
if string match -q '#*' $line
continue
end
set -l kv (string split -m 1 = -- $line)
set -gx $kv
end < $argv[1]
end
function readenv --on-variable PWD
if test -r .env
while read -l line
set -l line (string trim $line)
if [ -z "$line" ]
continue
end
if string match -q '#*' $line
continue
end
set -l kv (string split -m 1 = -- $line)
set -gx $kv
end < .env
loadenv .env
end
end
end