Skip to content

Instantly share code, notes, and snippets.

@cuckookernel
Created July 9, 2026 22:38
Show Gist options
  • Select an option

  • Save cuckookernel/7084c63c13a8bf6448b5d5743c89e7fe to your computer and use it in GitHub Desktop.

Select an option

Save cuckookernel/7084c63c13a8bf6448b5d5743c89e7fe to your computer and use it in GitHub Desktop.
dotenv / load_dotenv / Load a .env function in fish shell
function load_env
if test -f $argv[1]
set -l count 0
while read -l line
# Skip empty lines and comments
if not string match -qr '^#|^$' "$line"
# Split the line into name and value, removing quotes
set -l kv (string split -m 1 "=" $line)
set -l key $kv[1]
set -l value (string trim -c '"' $kv[2])
# echo key=`$key`
# echo value=`$value`
# Set the variable globally
set -gx $key $value
set count (math $count + 1)
end
end < $argv[1]
echo "Successfully set $count environment variables"
else
echo "File $argv[1] not found."
return 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment