feat: split loadenv from readenv to load any file
This commit is contained in:
parent
7a15fceb1b
commit
50cae027bc
|
@ -70,19 +70,23 @@ if status is-interactive
|
||||||
# === auto cd into last activated directory
|
# === auto cd into last activated directory
|
||||||
test "$PWD" = "$HOME" && cd $last_pwd
|
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
|
function readenv --on-variable PWD
|
||||||
if test -r .env
|
if test -r .env
|
||||||
while read -l line
|
loadenv .env
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user