Here follows some of my zsh configuration, as promised in my previous post. Please see that previous post for understanding where to place these and how they are used.
First out is zshenv.illumos
which gets conditionally included on illumos
(solaris) hosts. It does nothing more than adding a few directories to the
start of the list of directories searched for executables, given that those
paths exist.
# vim: filetype=zsh sw=2 et
# /opt/onbld/bin/i386 /opt/ooce/docbook-xsl/tools /usr/xpg4/bin /usr/share/lib
for _path in \
'/usr/gnu/bin' \
'/usr/ccs/bin' \
'/opt/ooce/bin'
do
if [ "${PATH//${_path}/}" = "${PATH}" ] && [ -e "${_path}" ]; then
PATH="${_path}:${PATH}"
fi
done
unset _path
export PATH
The second file here zshenv.cloud
creates a few convenience functions for
easily finding cloud computing instances. The stack exchange links in the
comments are pretty much where I have copy'n'pasted the oneliners from, and
they are mostly used by my secure shell configuration.
# vim: filetype=zsh sw=2 et
# https://stackoverflow.com/q/25922609/#50535409
# does-google-publish-a-dns-record-for-google-compute-engine-instances
get_gce_ip() {
local instance="${1%%.*}"
gcloud compute instances list --filter="$instance" \
--format='value(networkInterfaces[0].accessConfigs[0].natIP)'
}
# https://serverfault.com/q/734237/
# is-there-a-command-to-list-aws-instances-that-results-in-short-output
get_aws_fqdn() {
local instance="${1%%.*}"
aws ec2 describe-instances --filters "Name=tag:Name,Values=${instance}" \
--output text --query 'Reservations[*].Instances[*].[PublicDnsName]'
}
get_linode_ip() {
local instance="${1%%.*}"
linode-cli --json linodes list --label "${instance}" |
jq --raw-output '.[0].ipv4[0]'
}
In order to make your linodes, ec2:s and gce:s conveniently available under
some fake top level domains, just add the corresponding cloud.conf
somewhere
and include it from .ssh/config
:
# vim: ft=sshconfig sw=4
Host *.aws
ProxyCommand nc $( get_aws_fqdn "%h" ) %p
# https://stackoverflow.com/q/25922609/#50535409-dns-record-for-gce-instance
Host *.googl
ProxyCommand nc $( get_gce_ip "%h" ) %p
Host *.linode
ProxyCommand nc $( get_linode_ip "%h" ) %p
The third and last zsh config file in this post is zshrc.prompt
which is only
used for interactive shells. The manual does a better job than I could do
at describing how the percent preceeded characters are expanded. One might
maybe start out reading it with the understanding that a ternary operator style
expression is used to make the prompt red when the previous command failed.
# vim: filetype=zsh sw=2 et
PROMPT="%(?..%S%F{red})%D{%Y%m%d}|%T|%!|%m%#"
RPROMPT="%(?..%S%F{red})"
PROMPT+="%f%s "
export PROMPT RPROMPT
Clearly these are not my full set of zsh configuration files, but a bite sized chunk. Maybe there will be more in the future, maybe not. To some degree that depends on whether these first two zsh posts are well recieved by those who initially requested the topic.