dustin
/
zdotdir
Archived
1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Dustin e120838f8a functions: Add test vm functions
* `@testvm::cleanup`: Deletes (after optionally powering off) test VMs
  matching a pattern
* `@testvm::connect`: Connects to test VM using SSH
* `@testvm::delete`: Powers off and deletes a specific test VM
* `@testvm::sftp`: Connects to a test VM using SFTP
2020-04-03 16:10:29 -05:00
Dustin d9d559c327 functions: dotenv: export variables from .env
Tools (such as VSCode) can read and use environment variables from a
file in the current working directory named `.env`.  Unfortunately,
these tools are not exactly compatible with shell syntax, as they do not
correctly process lines starting with `export`.

The `dotenv` function will read a `.env` file from the current working
directory and then export all of the variables it defines.  This allows
the `.env` file to define the variables without "exporting" them, making
them compatible with VSCode et al, but still allowing the same
environment variables to be set in the shell and its child processes.
2020-02-08 14:23:18 -06:00
6 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,27 @@
# vim: set ft=zsh sw=4 ts=4 sts=4 et :
@testvm::cleanup() {
local destroy=false
local pattern='^fmos-[a-f0-9]{8}$'
while [ $# -gt 0 ]; do
case "$1" in
--destroy)
destroy=true
;;
*)
pattern="${1}"
;;
esac
shift
done
if ${destroy}; then
virsh list --name \
| awk "/${pattern}/{print}" \
| xargs -r -n1 virsh destroy
fi
virsh list --inactive --name \
| awk "/${pattern}/{print}" \
| xargs -r -n1 virsh undefine --remove-all-storage --nvram
}
@testvm::cleanup "$@"

View File

@ -0,0 +1,22 @@
# vim: set ft=zsh sw=4 ts=4 sts=4 et :
@testvm::connect() {
local _term
local testvm_domain=${TESTVM_DOMAIN:-dustin.test}
local testvm="${1}"
shift
if [ -z "${SSHPASS}" ]; then
export SSHPASS='F!r3m0n1'
fi
case ${TERM} in
[Aa]lacritty)
_term=xterm-256color
;;
esac
if [[ ! "${testvm}" = *.* ]]; then
testvm="${testvm}.${testvm_domain}"
fi
TERM=${_term:-${TERM}} sshpass -e ssh ${testvm} "$@"
}
@testvm::connect "$@"

View File

@ -0,0 +1,8 @@
# vim: set ft=zsh sw=4 ts=4 sts=4 et :
@testvm::delete() {
virsh destroy "${1}" || :
virsh undefine "${1}" --remove-all-storage --nvram
}
@testvm::delete "$@"

17
functions/@testvm::sftp Normal file
View File

@ -0,0 +1,17 @@
# vim: set ft=zsh sw=4 ts=4 sts=4 et :
@testvm::sftp() {
local _term
local testvm_domain=${TESTVM_DOMAIN:-dustin.test}
if [ -z "${SSHPASS}" ]; then
export SSHPASS='F!r3m0n1'
fi
case ${TERM} in
Alacritty)
_term=xterm-256color
;;
esac
TERM=${_term:-${TERM}} sshpass -e sftp ${1}.${testvm_domain}${2:+:${2}}
}
@testvm::sftp "$@"

1
functions/@vmname Normal file
View File

@ -0,0 +1 @@
printf 'fmos-%08x\n' $(od -An -tu -N4 /dev/urandom)

10
functions/dotenv Normal file
View File

@ -0,0 +1,10 @@
# vim: set ft=zsh sw=4 ts=4 sts=4 et :
function dotenv() {
if [ -f .env ]; then
. ./.env || return $?
eval $(awk -F= '{print "export",$1}' .env)
fi
}
dotenv